Skip to contentSkip to conversation

sony-laptop: leak in error handling sony_nc_lid_resume_setup()

PATCH In review Dan Carpenter 2 participants 2 messages Feb 1, 2013 – Feb 2, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sony-laptop: leak in error handling sony_nc_lid_resume_setup()

We need to decrement "i" first because the current "i" was not allocated succesfully. Also we should go free the way down to zero to avoid a leak.

drivers/platform/x86/sony-laptop.c +1 -1
index 438c7fa..9557414 100644
@@ -2351,7 +2351,7 @@ static int sony_nc_lid_resume_setup(struct platform_device *pd)
 	return 0;
 
 liderror:
-	for (; i > 0; i--)
+	for (i--; i >= 0; i--)
 		device_remove_file(&pd->dev, &lid_ctl->attrs[i]);
 
 	kfree(lid_ctl);
#1 lore raw

Am 01.02.2013 14:28, schrieb Dan Carpenter:

Quoted 11 lines

We need to decrement "i" first because the current "i" was not allocated succesfully. Also we should go free the way down to zero to avoid a leak.

drivers/platform/x86/sony-laptop.c +0 -0
index 438c7fa..9557414 100644

drivers/platform/x86/sony-laptop.c static int sony_nc_lid_resume_setup(struct platform_device *pd) · line 2357

Quoted 8 lines
drivers/platform/x86/sony-laptop.c +1 -1
@@ -2351,7 +2351,7 @@ static int sony_nc_lid_resume_setup(struct platform_device *pd)
 	return 0;
 
 liderror:
-	for (; i > 0; i--)
+	for (i--; i >= 0; i--)
 		device_remove_file(&pd->dev, &lid_ctl->attrs[i]);
 
 	kfree(lid_ctl);

i have learned that most people get confused when you do loop "the-other-way-around". (typical errors see above). Maybe it would be better foe further generations to turn the loop on its head like:

int c;
for(c=0; c < i ; c++)

    device_remove_file(&pd->dev, &lid_ctl->attrs[c]);

kfree(lid_ctl);

re,
wh

yes, there is one var more

Quoted 6 lines

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html