diff mbox series

Input: ar1021 - use IRQ_NOAUTOEN flags to replace disable_irq

Message ID 20210102042902.41664-1-song.bao.hua@hisilicon.com (mailing list archive)
State New, archived
Headers show
Series Input: ar1021 - use IRQ_NOAUTOEN flags to replace disable_irq | expand

Commit Message

Song Bao Hua (Barry Song) Jan. 2, 2021, 4:29 a.m. UTC
disable_irq() after request_irq is unsafe as it gives a time gap which
irq can come before disable_irq(). IRQ_NOAUTOEN is the common way to
avoid enabling IRQ due to requesting IRQ.

Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
---
 drivers/input/touchscreen/ar1021_i2c.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Dmitry Torokhov Jan. 2, 2021, 5:55 a.m. UTC | #1
Hi Barry,

On Sat, Jan 02, 2021 at 05:29:02PM +1300, Barry Song wrote:
> disable_irq() after request_irq is unsafe as it gives a time gap which
> irq can come before disable_irq(). IRQ_NOAUTOEN is the common way to
> avoid enabling IRQ due to requesting IRQ.

Actually it is OK for the ISR to fire before the input device is
registered, input core allows that.

What I would like to see is to allow passing something like
IRQF_DISABLED to request_irq() so that we would not need neither
irq_set_status_flags() nor disable_irq().

Thanks.
Song Bao Hua (Barry Song) Jan. 2, 2021, 7:58 a.m. UTC | #2
> -----Original Message-----
> From: Dmitry Torokhov [mailto:dmitry.torokhov@gmail.com]
> Sent: Saturday, January 2, 2021 6:55 PM
> To: Song Bao Hua (Barry Song) <song.bao.hua@hisilicon.com>
> Cc: linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] Input: ar1021 - use IRQ_NOAUTOEN flags to replace
> disable_irq
> 
> Hi Barry,

Hi Dmitry,
Thanks for your quick reply.

> 
> On Sat, Jan 02, 2021 at 05:29:02PM +1300, Barry Song wrote:
> > disable_irq() after request_irq is unsafe as it gives a time gap which
> > irq can come before disable_irq(). IRQ_NOAUTOEN is the common way to
> > avoid enabling IRQ due to requesting IRQ.
> 
> Actually it is OK for the ISR to fire before the input device is
> registered, input core allows that.
> 

Yep. probably the only issue left is that the code looks silly.
It enables the interrupt in request_irq() automatically and
disables it immediately. So a better way would be avoiding enabling
the IRQ during request_irq().

> What I would like to see is to allow passing something like
> IRQF_DISABLED to request_irq() so that we would not need neither
> irq_set_status_flags() nor disable_irq().
> 

IRQF_DISABLED has been deleted for many years since Linux kernel
doesn't support interrupts enter while an irq handler is running
any more. That flag used to work for forbidding all interrupts
while  kernel was running in one hardIRQ to avoid IRQ races for
kernel older than 2.6.32.

Maybe we can invent a new flag like IRQF_NOAUTOEN for request_irq()?
but right now all other drivers are using irq_set_status_flags
(IRQ_NOAUTOEN) since this request flag doesn't exist.

Do you think it is worth to add a new flag to replace many
irq_set_status_flags(irq, IRQ_NOAUTOEN);
request_irq();
in drivers/gpu, i2c, input, media, net, perf, tc, spi, tty,
usb, vfio?

and +Thomas to get his comments as well :-)

> Thanks.
> 
> --
> Dmitry

Thanks
Barry
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/ar1021_i2c.c b/drivers/input/touchscreen/ar1021_i2c.c
index c0d5c2413356..c9e98ed4520e 100644
--- a/drivers/input/touchscreen/ar1021_i2c.c
+++ b/drivers/input/touchscreen/ar1021_i2c.c
@@ -123,6 +123,11 @@  static int ar1021_i2c_probe(struct i2c_client *client,
 
 	input_set_drvdata(input, ar1021);
 
+	/*
+	 * Don't enable the IRQ automatically, we'll enable it in
+	 * ar1021_i2c_open()
+	 */
+	irq_set_status_flags(client->irq, IRQ_NOAUTOEN);
 	error = devm_request_threaded_irq(&client->dev, client->irq,
 					  NULL, ar1021_i2c_irq,
 					  IRQF_ONESHOT,
@@ -133,9 +138,6 @@  static int ar1021_i2c_probe(struct i2c_client *client,
 		return error;
 	}
 
-	/* Disable the IRQ, we'll enable it in ar1021_i2c_open() */
-	disable_irq(client->irq);
-
 	error = input_register_device(ar1021->input);
 	if (error) {
 		dev_err(&client->dev,