input: keyboard: snvs: make sure irq is handled correctly
Subsystems (2)
PATCH 1/1 input: keyboard: snvs: make sure irq is handled correctly
SNVS IRQ is requested before necessary driver data initialized, if there is a pending IRQ during driver probe phase, kernel NULL pointer panic will occur in IRQ handler. To avoid such scenario, need to move the IRQ request to after driver data initialization done. This patch is inspired by NXP's internal kernel tree.
--- drivers/input/keyboard/snvs_pwrkey.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/input/keyboard/snvs_pwrkey.c +8 -9
@@ -148,15 +148,6 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev)return error; } - error =devm_request_irq (&pdev->dev, pdata->irq, - imx_snvs_pwrkey_interrupt, -0 , pdev->name, pdev); - -if (error) { -dev_err (&pdev->dev,"interrupt not available.\n" ); -return error; - } - error =input_register_device (input);if (error <0 ) {dev_err (&pdev->dev,"failed to register input device\n" );
@@ -166,6 +157,14 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev) pdata->input = input;platform_set_drvdata (pdev, pdata); + error =devm_request_irq (&pdev->dev, pdata->irq, + imx_snvs_pwrkey_interrupt, +0 , pdev->name, pdev); +if (error) { +dev_err (&pdev->dev,"interrupt not available.\n" ); +return error; + } +device_init_wakeup (&pdev->dev, pdata->wakeup);return 0 ;
Signature · 1 line
2.7.4
[email protected]
maintainerHi Anson,
Quoted 34 lines · Anson Huang
SNVS IRQ is requested before necessary driver data initialized, if there is a pending IRQ during driver probe phase, kernel NULL pointer panic will occur in IRQ handler. To avoid such scenario, need to move the IRQ request to after driver data initialization done. This patch is inspired by NXP's internal kernel tree.
Fixes d3dc6e232215 ("input: keyboard: imx: add snvs power key driver")Signed-off-by Anson Huang <[email protected]>--- drivers/input/keyboard/snvs_pwrkey.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)drivers/input/keyboard/snvs_pwrkey.c +0
-9@@ -148,15 +148,6 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev)return error; } - error =devm_request_irq (&pdev->dev, pdata->irq, - imx_snvs_pwrkey_interrupt, -0 , pdev->name, pdev); - -if (error) { -dev_err (&pdev->dev,"interrupt not available.\n" ); -return error; - } - error =input_register_device (input);if (error <0 ) {dev_err (&pdev->dev,"failed to register input device\n" );
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 166
Quoted 10 lines
drivers/input/keyboard/snvs_pwrkey.c +7
-0@@ -166,6 +157,14 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev) pdata->input = input;platform_set_drvdata (pdev, pdata); + error =devm_request_irq (&pdev->dev, pdata->irq, + imx_snvs_pwrkey_interrupt, +0 , pdev->name, pdev); +if (error) { +dev_err (&pdev->dev,"interrupt not available.\n" ); +return error; + }
Instead of moving devm_request_irq() around could you simply move pdata->input = input assignment higher? It is perfectly fine to try calling input_event() on input device that is allocated but not yet registered.
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 168
Quoted 2 lines
drivers/input/keyboard/snvs_pwrkey.c +1
-0+device_init_wakeup (&pdev->dev, pdata->wakeup);
Unrelated suggestion:
Can you try calling dev_pm_set_wake_irq(&pdev->dev, pdata->irq) here and I think you will be able to get rid of suspend/resume methods in the driver.
Thanks.
Signature · 1 line
Dmitry
Hi, Dmitry
Best Regards!
Anson Huang
Quoted 53 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: 2019年3月27日 12:29
To: Anson Huang <[email protected]>
Cc: Fabio Estevam <[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] input: keyboard: snvs: make sure irq is handled correctlyHi Anson,
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct
Quoted 19 lines · Anson Huang
SNVS IRQ is requested before necessary driver data initialized, if there is a pending IRQ during driver probe phase, kernel NULL pointer panic will occur in IRQ handler. To avoid such scenario, need to move the IRQ request to after driver data initialization done. This patch is inspired by NXP's internal kernel tree.
Fixes d3dc6e232215 ("input: keyboard: imx: add snvs power keydriver")
Signed-off-by Anson Huang <[email protected]>--- drivers/input/keyboard/snvs_pwrkey.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)drivers/input/keyboard/snvs_pwrkey.c +0
-0@@ -148,15 +148,6 @@ static int imx_snvs_pwrkey_probe(struct
platform_device*pdev)Quoted 5 lines
drivers/input/keyboard/snvs_pwrkey.c +0
-2return error; } - error = devm_request_irq(&pdev->dev, pdata->irq, - imx_snvs_pwrkey_interrupt,drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 153
Quoted 10 lines
drivers/input/keyboard/snvs_pwrkey.c +0
-7- 0, pdev->name, pdev); - -if (error) { -dev_err (&pdev->dev,"interrupt not available.\n" ); -return error; - } - error =input_register_device (input);if (error <0 ) {dev_err (&pdev->dev,"failed to register input device\n" );@@ -166,6
Quoted 1 line
+157,14 @@ static int imx_snvs_pwrkey_probe(struct
platform_device*pdev)
Quoted 3 lines
drivers/input/keyboard/snvs_pwrkey.c +0
-0pdata->input = input;platform_set_drvdata (pdev, pdata);
Quoted 11 lines
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 166
Quoted 7 lines
drivers/input/keyboard/snvs_pwrkey.c +7
-0+ error =devm_request_irq (&pdev->dev, pdata->irq, + imx_snvs_pwrkey_interrupt, +0 , pdev->name, pdev); +if (error) { +dev_err (&pdev->dev,"interrupt not available.\n" ); +return error; + }Instead of moving
devm_request_irq()around could you simply movepdata->input= input assignment higher? It is perfectly fine to try callinginput_event()on input device that is allocated but not yet registered.
OK, make sense.
Quoted 8 lines
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 168
Quoted 3 lines
drivers/input/keyboard/snvs_pwrkey.c +1
-0+device_init_wakeup (&pdev->dev, pdata->wakeup);Unrelated suggestion:
Can you try calling
dev_pm_set_wake_irq(&pdev->dev, pdata->irq)here and I think you will be able to get rid of suspend/resume methods in the driver.
OK, I will look into it, and send another patch to improve this.
Thanks.
Anson
Quoted 5 lines
Thanks.
--
Dmitry