linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] cpuidle: fix improper return value on error
@ 2016-12-03 15:02 Pan Bian
  2016-12-08  0:13 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Pan Bian @ 2016-12-03 15:02 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, linux-pm; +Cc: linux-kernel, Pan Bian

From: Pan Bian <bianpan2016@163.com>

In function cpuidle_add_state_sysfs(), variable ret takes the return
value. Its value should be negative on errors. Because ret is reset in
the loop, its value will be 0 during the second and after repeat of the
loop. If kzalloc() returns a NULL pointer then, it will return 0. It may
be better to explicitly assign "-ENOMEM" when the call to kzalloc()
fails.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188901

Signed-off-by: Pan Bian <bianpan2016@163.com>
---
 drivers/cpuidle/sysfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index 832a2c3..c5adc8c 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -403,8 +403,10 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
 	/* state statistics */
 	for (i = 0; i < drv->state_count; i++) {
 		kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL);
-		if (!kobj)
+		if (!kobj) {
+			ret = -ENOMEM;
 			goto error_state;
+		}
 		kobj->state = &drv->states[i];
 		kobj->state_usage = &device->states_usage[i];
 		init_completion(&kobj->kobj_unregister);
-- 
1.9.1

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

* Re: [PATCH 1/1] cpuidle: fix improper return value on error
  2016-12-03 15:02 [PATCH 1/1] cpuidle: fix improper return value on error Pan Bian
@ 2016-12-08  0:13 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2016-12-08  0:13 UTC (permalink / raw)
  To: Pan Bian; +Cc: Daniel Lezcano, linux-pm, linux-kernel, Pan Bian

On Saturday, December 03, 2016 11:02:27 PM Pan Bian wrote:
> From: Pan Bian <bianpan2016@163.com>
> 
> In function cpuidle_add_state_sysfs(), variable ret takes the return
> value. Its value should be negative on errors. Because ret is reset in
> the loop, its value will be 0 during the second and after repeat of the
> loop. If kzalloc() returns a NULL pointer then, it will return 0. It may
> be better to explicitly assign "-ENOMEM" when the call to kzalloc()
> fails.
> 
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188901
> 
> Signed-off-by: Pan Bian <bianpan2016@163.com>
> ---
>  drivers/cpuidle/sysfs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
> index 832a2c3..c5adc8c 100644
> --- a/drivers/cpuidle/sysfs.c
> +++ b/drivers/cpuidle/sysfs.c
> @@ -403,8 +403,10 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
>  	/* state statistics */
>  	for (i = 0; i < drv->state_count; i++) {
>  		kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL);
> -		if (!kobj)
> +		if (!kobj) {
> +			ret = -ENOMEM;
>  			goto error_state;
> +		}
>  		kobj->state = &drv->states[i];
>  		kobj->state_usage = &device->states_usage[i];
>  		init_completion(&kobj->kobj_unregister);
> 

Applied.

Thanks,
Rafael

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

end of thread, other threads:[~2016-12-08  0:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-03 15:02 [PATCH 1/1] cpuidle: fix improper return value on error Pan Bian
2016-12-08  0:13 ` Rafael J. Wysocki

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).