linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PM / devfreq: return PTR_ERR not NULL in try_then_request_governor()
@ 2019-04-03 15:26 Steven Price
  2019-04-24  8:23 ` Enric Balletbo Serra
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Price @ 2019-04-03 15:26 UTC (permalink / raw)
  To: Kyungmin Park, MyungJoo Ham
  Cc: Chanwoo Choi, linux-kernel, linux-pm, Steven Price

The callers of try_then_request_governor() only test for a PTR_ERR using
IS_ERR(). However in the case that request_module() fails then NULL is
currently returned which will cause a NULL-pointer dereference in the
caller.

Instead convert the error we already have to a valid PTR_ERR and return
it.

Fixes: 23c7b54ca1cd ("PM / devfreq: Fix devfreq_add_device() when drivers are built as modules.")
Signed-off-by: Steven Price <steven.price@arm.com>
---
 drivers/devfreq/devfreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 0ae3de76833b..d29f66f0e52a 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -254,7 +254,7 @@ static struct devfreq_governor *try_then_request_governor(const char *name)
 		/* Restore previous state before return */
 		mutex_lock(&devfreq_list_lock);
 		if (err)
-			return NULL;
+			return ERR_PTR(err);
 
 		governor = find_devfreq_governor(name);
 	}
-- 
2.20.1


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

* Re: [PATCH] PM / devfreq: return PTR_ERR not NULL in try_then_request_governor()
  2019-04-03 15:26 [PATCH] PM / devfreq: return PTR_ERR not NULL in try_then_request_governor() Steven Price
@ 2019-04-24  8:23 ` Enric Balletbo Serra
  0 siblings, 0 replies; 2+ messages in thread
From: Enric Balletbo Serra @ 2019-04-24  8:23 UTC (permalink / raw)
  To: Steven Price
  Cc: Kyungmin Park, MyungJoo Ham, Chanwoo Choi, linux-kernel, Linux PM list

Hi,

Missatge de Steven Price <steven.price@arm.com> del dia dc., 3 d’abr.
2019 a les 17:26:

>
> The callers of try_then_request_governor() only test for a PTR_ERR using
> IS_ERR(). However in the case that request_module() fails then NULL is
> currently returned which will cause a NULL-pointer dereference in the
> caller.
>
> Instead convert the error we already have to a valid PTR_ERR and return
> it.
>
> Fixes: 23c7b54ca1cd ("PM / devfreq: Fix devfreq_add_device() when drivers are built as modules.")
> Signed-off-by: Steven Price <steven.price@arm.com>

There is already a fix for that. The fix was initially sent in October [2] but
unfortunately, it got lost. I resend and now is queued [1]. Hopefully, the Fixes
tag will help to pick the fix to the proper kernel releases.

Thanks,
 Enric

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/mzx/devfreq.git/commit/?h=for-next&id=b53b0128052ffd687797d5f4deeb76327e7b5711
[2] https://lkml.org/lkml/2018/10/16/744


> ---
>  drivers/devfreq/devfreq.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index 0ae3de76833b..d29f66f0e52a 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -254,7 +254,7 @@ static struct devfreq_governor *try_then_request_governor(const char *name)
>                 /* Restore previous state before return */
>                 mutex_lock(&devfreq_list_lock);
>                 if (err)
> -                       return NULL;
> +                       return ERR_PTR(err);
>
>                 governor = find_devfreq_governor(name);
>         }
> --
> 2.20.1
>

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

end of thread, other threads:[~2019-04-24  8:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-03 15:26 [PATCH] PM / devfreq: return PTR_ERR not NULL in try_then_request_governor() Steven Price
2019-04-24  8:23 ` Enric Balletbo Serra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).