[PATCH 2/2] Input: xpad - sanitize xpad_led_disconnect()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Namhyung Kim
Date: Wednesday, December 1, 2010 - 8:04 am

IMHO kfree() here looks very confusing. xpad_led->name is an array
of char inside struct xpad_led and is not a dynamic memory itself.
But kfree() works well because it is a first member of the struct
so it points start address of the struct and frees the struct.

Change it to xpad_led for the correctness & readability and make
xpad->led NULL for the safety.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Cc: Jan Kratochvil <honza@jikos.cz>
---
 drivers/input/joystick/xpad.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index f885902..1ca49e8 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -728,7 +728,8 @@ static void xpad_led_disconnect(struct usb_xpad *xpad)
 
 	if (xpad_led) {
 		led_classdev_unregister(&xpad_led->led_cdev);
-		kfree(xpad_led->name);
+		kfree(xpad_led);
+		xpad->led = NULL;
 	}
 }
 #else
-- 
1.7.0.4

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 1/2] Input: xpad - fix memory leak, Namhyung Kim, (Wed Dec 1, 8:04 am)
[PATCH 2/2] Input: xpad - sanitize xpad_led_disconnect(), Namhyung Kim, (Wed Dec 1, 8:04 am)
Re: [PATCH 2/2] Input: xpad - sanitize xpad_led_disconnect(), Dmitry Torokhov, (Wed Dec 1, 10:11 am)
Re: [PATCH 1/2] Input: xpad - fix memory leak, Dmitry Torokhov, (Wed Dec 1, 10:14 am)