All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power: reset: msm: Process register_restart_handler() error
@ 2023-11-08 17:27 Nikita Kiryushin
  2023-11-15 22:24 ` Sebastian Reichel
  2023-12-16  8:15 ` Mukesh Ojha
  0 siblings, 2 replies; 4+ messages in thread
From: Nikita Kiryushin @ 2023-11-08 17:27 UTC (permalink / raw)
  To: Andy Gross
  Cc: Bjorn Andersson, Konrad Dybcio, Sebastian Reichel, Stephen Boyd,
	Pramod Gurav, Guenter Roeck, linux-arm-msm, linux-pm,
	linux-kernel, lvc-project

If registering restart handler fails for msm-restart result is not checked.
It may be irrelevant now (as stated in comment to register_restart_handler,
the function currently always returns zero), but if the behavior changes
in the future, an error at registration of handler will be silently skipped.

Add return error code and print error message too debug log in case of
non-zero result of register_restart_handler.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 18a702e0de98 ("power: reset: use restart_notifier mechanism for 
msm-poweroff")

Signed-off-by: Nikita Kiryushin <kiryushin@ancud.ru>
---
  drivers/power/reset/msm-poweroff.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/power/reset/msm-poweroff.c 
b/drivers/power/reset/msm-poweroff.c
index b9a401bd280b..5877a1ba2778 100644
--- a/drivers/power/reset/msm-poweroff.c
+++ b/drivers/power/reset/msm-poweroff.c
@@ -35,11 +35,16 @@ static void do_msm_poweroff(void)
   static int msm_restart_probe(struct platform_device *pdev)
  {
+	int ret = -EINVAL;
  	msm_ps_hold = devm_platform_ioremap_resource(pdev, 0);
  	if (IS_ERR(msm_ps_hold))
  		return PTR_ERR(msm_ps_hold);
  -	register_restart_handler(&restart_nb);
+	ret = register_restart_handler(&restart_nb);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to register restart handler, %d\n", ret);
+		return ret;
+	}
   	pm_power_off = do_msm_poweroff;
  -- 2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] power: reset: msm: Process register_restart_handler() error
  2023-11-08 17:27 [PATCH] power: reset: msm: Process register_restart_handler() error Nikita Kiryushin
@ 2023-11-15 22:24 ` Sebastian Reichel
  2023-12-16  8:15 ` Mukesh Ojha
  1 sibling, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2023-11-15 22:24 UTC (permalink / raw)
  To: Nikita Kiryushin
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Stephen Boyd,
	Pramod Gurav, Guenter Roeck, linux-arm-msm, linux-pm,
	linux-kernel, lvc-project

[-- Attachment #1: Type: text/plain, Size: 1929 bytes --]

Hi,

On Wed, Nov 08, 2023 at 08:27:57PM +0300, Nikita Kiryushin wrote:
> If registering restart handler fails for msm-restart result is not checked.
> It may be irrelevant now (as stated in comment to register_restart_handler,
> the function currently always returns zero), but if the behavior changes
> in the future, an error at registration of handler will be silently skipped.
> 
> Add return error code and print error message too debug log in case of
> non-zero result of register_restart_handler.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 18a702e0de98 ("power: reset: use restart_notifier mechanism for
> msm-poweroff")
> 
> Signed-off-by: Nikita Kiryushin <kiryushin@ancud.ru>
> ---

If register_restart_handler fails, it might actually be a good idea
to continue and at least have a poweroff handler :)

>  drivers/power/reset/msm-poweroff.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/power/reset/msm-poweroff.c
> b/drivers/power/reset/msm-poweroff.c
> index b9a401bd280b..5877a1ba2778 100644
> --- a/drivers/power/reset/msm-poweroff.c
> +++ b/drivers/power/reset/msm-poweroff.c
> @@ -35,11 +35,16 @@ static void do_msm_poweroff(void)
>   static int msm_restart_probe(struct platform_device *pdev)
>  {
> +	int ret = -EINVAL;

no need to initialize, it's overwritten before being used.

>  	msm_ps_hold = devm_platform_ioremap_resource(pdev, 0);
>  	if (IS_ERR(msm_ps_hold))
>  		return PTR_ERR(msm_ps_hold);
>  -	register_restart_handler(&restart_nb);
> +	ret = register_restart_handler(&restart_nb);
> +	if (ret) {
> +		dev_err(&pdev->dev, "unable to register restart handler, %d\n", ret);
> +		return ret;

There is dev_err_probe() for this, but as mentioned above it's more
sensible not to fail here.

-- Sebastian

> +	}
>   	pm_power_off = do_msm_poweroff;
>  -- 2.34.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] power: reset: msm: Process register_restart_handler() error
  2023-11-08 17:27 [PATCH] power: reset: msm: Process register_restart_handler() error Nikita Kiryushin
  2023-11-15 22:24 ` Sebastian Reichel
@ 2023-12-16  8:15 ` Mukesh Ojha
  2023-12-16 15:50   ` Guenter Roeck
  1 sibling, 1 reply; 4+ messages in thread
From: Mukesh Ojha @ 2023-12-16  8:15 UTC (permalink / raw)
  To: Nikita Kiryushin, Andy Gross
  Cc: Bjorn Andersson, Konrad Dybcio, Sebastian Reichel, Stephen Boyd,
	Pramod Gurav, Guenter Roeck, linux-arm-msm, linux-pm,
	linux-kernel, lvc-project



On 11/8/2023 10:57 PM, Nikita Kiryushin wrote:
> If registering restart handler fails for msm-restart result is not checked.
> It may be irrelevant now (as stated in comment to register_restart_handler,
> the function currently always returns zero), but if the behavior changes
> in the future, an error at registration of handler will be silently 
> skipped.
> 
> Add return error code and print error message too debug log in case of
> non-zero result of register_restart_handler.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 18a702e0de98 ("power: reset: use restart_notifier mechanism for 
> msm-poweroff")
> 
> Signed-off-by: Nikita Kiryushin <kiryushin@ancud.ru>
> ---
>   drivers/power/reset/msm-poweroff.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/power/reset/msm-poweroff.c 
> b/drivers/power/reset/msm-poweroff.c
> index b9a401bd280b..5877a1ba2778 100644
> --- a/drivers/power/reset/msm-poweroff.c
> +++ b/drivers/power/reset/msm-poweroff.c
> @@ -35,11 +35,16 @@ static void do_msm_poweroff(void)
>    static int msm_restart_probe(struct platform_device *pdev)
>   {
> +    int ret = -EINVAL;

This does not add up anything., no need to initialize.

-Mukesh


>       msm_ps_hold = devm_platform_ioremap_resource(pdev, 0);
>       if (IS_ERR(msm_ps_hold))
>           return PTR_ERR(msm_ps_hold);
>   -    register_restart_handler(&restart_nb);
> +    ret = register_restart_handler(&restart_nb);
> +    if (ret) {
> +        dev_err(&pdev->dev, "unable to register restart handler, %d\n", 
> ret);
> +        return ret;
> +    }
>        pm_power_off = do_msm_poweroff;
>   -- 2.34.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] power: reset: msm: Process register_restart_handler() error
  2023-12-16  8:15 ` Mukesh Ojha
@ 2023-12-16 15:50   ` Guenter Roeck
  0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2023-12-16 15:50 UTC (permalink / raw)
  To: Mukesh Ojha, Nikita Kiryushin, Andy Gross
  Cc: Bjorn Andersson, Konrad Dybcio, Sebastian Reichel, Stephen Boyd,
	Pramod Gurav, linux-arm-msm, linux-pm, linux-kernel, lvc-project

On 12/16/23 00:15, Mukesh Ojha wrote:
> 
> 
> On 11/8/2023 10:57 PM, Nikita Kiryushin wrote:
>> If registering restart handler fails for msm-restart result is not checked.
>> It may be irrelevant now (as stated in comment to register_restart_handler,
>> the function currently always returns zero), but if the behavior changes
>> in the future, an error at registration of handler will be silently skipped.
>>
>> Add return error code and print error message too debug log in case of
>> non-zero result of register_restart_handler.
>>
>> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>>
>> Fixes: 18a702e0de98 ("power: reset: use restart_notifier mechanism for msm-poweroff")
>>
>> Signed-off-by: Nikita Kiryushin <kiryushin@ancud.ru>
>> ---
>>   drivers/power/reset/msm-poweroff.c | 7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/power/reset/msm-poweroff.c b/drivers/power/reset/msm-poweroff.c
>> index b9a401bd280b..5877a1ba2778 100644
>> --- a/drivers/power/reset/msm-poweroff.c
>> +++ b/drivers/power/reset/msm-poweroff.c
>> @@ -35,11 +35,16 @@ static void do_msm_poweroff(void)
>>    static int msm_restart_probe(struct platform_device *pdev)
>>   {
>> +    int ret = -EINVAL;
> 
> This does not add up anything., no need to initialize.
> 
> -Mukesh
> 
> 
>>       msm_ps_hold = devm_platform_ioremap_resource(pdev, 0);
>>       if (IS_ERR(msm_ps_hold))
>>           return PTR_ERR(msm_ps_hold);
>>   -    register_restart_handler(&restart_nb);
>> +    ret = register_restart_handler(&restart_nb);

FWIW, checking this return value really do anything good either. The only possible
return value is -EEXIST, which would be returned if the restart handler was already
registered, and that can not really happen. On top of that, _if_ that happened,
the notifier core would dump a warning traceback, making the error message below
unnecessary.

>> +    if (ret) {
>> +        dev_err(&pdev->dev, "unable to register restart handler, %d\n", ret);
>> +        return ret;

On top of all the above, not registering the poweroff andler in the already
impossible case that the restart handler can not be registered seems like an
excessively bad idea to me.

Guenter

>> +    }
>>        pm_power_off = do_msm_poweroff;
>>   -- 2.34.1
>>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-16 15:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-08 17:27 [PATCH] power: reset: msm: Process register_restart_handler() error Nikita Kiryushin
2023-11-15 22:24 ` Sebastian Reichel
2023-12-16  8:15 ` Mukesh Ojha
2023-12-16 15:50   ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.