Input: snvs_pwrkey: Improve probe error handling
Subsystems (2)
PATCH v2 1/2 Input: snvs_pwrkey: Improve probe error handling
From: bui duc phuc <[email protected]>
Use dev_err_probe() for devm_clk_get() to prevent log spam when probe returns -EPROBE_DEFER.
Return the original error from platform_get_irq() instead of replacing it with -EINVAL.
Drop the redundant error message after devm_request_irq(), as the helper already reports request failures internally.
---
Changes in v2:
- Clarify the commit message to better describe the purpose of using dev_err_probe()
drivers/input/keyboard/snvs_pwrkey.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/input/keyboard/snvs_pwrkey.c +5 -8
@@ -142,16 +142,15 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev) } clk =devm_clk_get_optional_enabled (&pdev->dev,NULL ); -if (IS_ERR (clk)) { -dev_err (&pdev->dev,"Failed to get snvs clock (%pe)\n" , clk); -return PTR_ERR (clk); - } +if (IS_ERR (clk)) +return dev_err_probe (&pdev->dev,PTR_ERR (clk), +"Failed to get snvs clock\n" ); pdata->wakeup =of_property_read_bool (np,"wakeup-source" ); pdata->irq =platform_get_irq (pdev,0 );if (pdata->irq <0 ) -return -EINVAL ; +return pdata->irq; error =of_property_read_u32 (np,"power-off-time-sec" , &val);if (!error) {
@@ -209,10 +208,8 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev) 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" ); +if (error)return error; - } error =input_register_device (input);if (error <0 ) {
Signature · 1 line
2.43.0
PATCH v2 2/2 Input: st-keyscan: Improve probe error handling
From: bui duc phuc <[email protected]>
Use dev_err_probe() for devm_clk_get() to prevent log spam when probe returns -EPROBE_DEFER.
Drop the redundant error message after devm_request_irq(), since the helper already reports request failures internally.
Return the original error from platform_get_irq() instead of replacing it with -EINVAL.
---
Changes in v2:
- Clarify the commit message to better describe the purpose of using dev_err_probe()
drivers/input/keyboard/st-keyscan.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/input/keyboard/st-keyscan.c +5 -8
@@ -173,10 +173,9 @@ static int keyscan_probe(struct platform_device *pdev)return PTR_ERR (keypad_data->base); keypad_data->clk =devm_clk_get (&pdev->dev,NULL ); -if (IS_ERR (keypad_data->clk)) { -dev_err (&pdev->dev,"cannot get clock\n" ); -return PTR_ERR (keypad_data->clk); - } +if (IS_ERR (keypad_data->clk)) +return dev_err_probe (&pdev->dev,PTR_ERR (keypad_data->clk), +"cannot get clock\n" ); error =clk_enable (keypad_data->clk);if (error) {
@@ -188,14 +187,12 @@ static int keyscan_probe(struct platform_device *pdev) keypad_data->irq =platform_get_irq (pdev,0 );if (keypad_data->irq <0 ) -return -EINVAL ; +return keypad_data->irq; error =devm_request_irq (&pdev->dev, keypad_data->irq, keyscan_isr,0 , pdev->name, keypad_data); -if (error) { -dev_err (&pdev->dev,"failed to request IRQ\n" ); +if (error)return error; - } error =input_register_device (input_dev);if (error) {
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2 2/2] Input: st-keyscan: Improve probe error handling
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Hardware access with disabled clock in ISR causes bus faults (spurious or pending interrupts) --
--- Patch [2]: [PATCH v2 2/2] Input: st-keyscan: Improve probe error handling --- commit 006b58b79139d033aaee4496bf01651147f36cad
Author: bui duc phuc <[email protected]>
Input: st-keyscan: Improve probe error handling
This commit updates probe error handling by using dev_err_probe() for devm_clk_get(), dropping a redundant error message after devm_request_irq(), and returning the original error code from platform_get_irq().
Quoted 3 lines
drivers/input/keyboard/st-keyscan.c +0
-0
[ ... ]
drivers/input/keyboard/st-keyscan.c static int keyscan_probe(struct platform_device *pdev) · line 195
Quoted 13 lines
drivers/input/keyboard/st-keyscan.c +2
-3@@ -188,14 +187,12 @@ static int keyscan_probe(struct platform_device *pdev) keypad_data->irq =platform_get_irq (pdev,0 );if (keypad_data->irq <0 ) -return -EINVAL ; +return keypad_data->irq; error =devm_request_irq (&pdev->dev, keypad_data->irq, keyscan_isr,0 , pdev->name, keypad_data); -if (error) { -dev_err (&pdev->dev,"failed to request IRQ\n" ); +if (error)return error;
[Severity: High]
This isn't a bug introduced by this patch, but I noticed a pre-existing issue with how the interrupt is registered here.
Since keyscan_stop() is called just before this in keyscan_probe(), the IP block's clock is already gated. By requesting the interrupt without IRQF_NO_AUTOEN, the interrupt is immediately unmasked at the interrupt controller.
If a pending or spurious interrupt fires before the device is opened, could the ISR attempt to access hardware registers while the clock is disabled?
drivers/input/keyboard/st-keyscan.c:keyscan_isr() {
...
state = readl(keypad->base + KEYSCAN_MATRIX_STATE_OFF) & 0xffff;
...
}Does this sequence risk a synchronous external abort (bus fault) causing a kernel panic on this platform?
Would it be safer to request the IRQ with IRQF_NO_AUTOEN so it remains masked until keyscan_open() explicitly enables the clock? I noticed this same window might exist in keyscan_close(), which disables the clock via keyscan_stop() but leaves the IRQ unmasked.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Low] Direct use of input_event() instead of specific reporting helpers. --
--- Patch [1]: [PATCH v2 1/2] Input: snvs_pwrkey: Improve probe error handling --- commit 1bfa57ab7fcf3071071b3cf879e2dfcda7662e49
Author: bui duc phuc <[email protected]>
Input: snvs_pwrkey: Improve probe error handling
Use dev_err_probe() for devm_clk_get() to prevent log spam when probe returns -EPROBE_DEFER. Return the original error from platform_get_irq() instead of replacing it with -EINVAL. Drop the redundant error message after devm_request_irq().
Quoted 7 lines
drivers/input/keyboard/snvs_pwrkey.c +0
-0@@ -142,16 +142,15 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev) }
drivers/input/keyboard/snvs_pwrkey.c static int imx_snvs_pwrkey_probe(struct platform_device *pdev) · line 149
Quoted 10 lines
drivers/input/keyboard/snvs_pwrkey.c +3
-4clk =devm_clk_get_optional_enabled (&pdev->dev,NULL ); -if (IS_ERR (clk)) { -dev_err (&pdev->dev,"Failed to get snvs clock (%pe)\n" , clk); -return PTR_ERR (clk); - } +if (IS_ERR (clk)) +return dev_err_probe (&pdev->dev,PTR_ERR (clk), +"Failed to get snvs clock\n" ); pdata->wakeup =of_property_read_bool (np,"wakeup-source" );
[ ... ]
[Severity: Low]
This isn't a bug introduced by this patch, but since you are improving this driver, should imx_imx_snvs_check_for_events() use input_report_key() rather than calling input_event() directly?
drivers/input/keyboard/snvs_pwrkey.c:imx_imx_snvs_check_for_events() {
...
if (state ^ pdata->keystate) {
pdata->keystate = state;
input_event(input, EV_KEY, pdata->keycode, state);
input_sync(input);
pm_relax(pdata->input->dev.parent);
}
...
}The subsystem guidelines suggest using the specific reporting helpers like input_report_key() instead of generic input_event() when the event type is known.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1