From 8f25229026c89912574558d0a4e36c8fe51b9bb4 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Fri, 19 Aug 2011 11:00:55 +0300 Subject: [PATCH] HID: hid-lg4ff: add a kfree() to an error path There is a small rare potential memory leak here. Also Walter Harms points out that we can do a small cleanup as well by using kstrdup(). Signed-off-by: Dan Carpenter Signed-off-by: Jiri Kosina --- drivers/hid/hid-lg4ff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index 2d8762d4f32a..103f30d93f76 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c @@ -435,12 +435,12 @@ int lg4ff_init(struct hid_device *hid) hid_err(hid, "Cannot add device, insufficient memory.\n"); return -ENOMEM; } - entry->device_id = (char *)kzalloc(strlen((&hid->dev)->kobj.name) + 1, GFP_KERNEL); + entry->device_id = kstrdup((&hid->dev)->kobj.name, GFP_KERNEL); if (!entry->device_id) { hid_err(hid, "Cannot set device_id, insufficient memory.\n"); + kfree(entry); return -ENOMEM; } - strcpy(entry->device_id, (&hid->dev)->kobj.name); entry->min_range = lg4ff_devices[i].min_range; entry->max_range = lg4ff_devices[i].max_range; entry->set_range = lg4ff_devices[i].set_range;