Skip to content

Commit

Permalink
HID: hid-lg4ff: add a kfree() to an error path
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jiri Kosina <[email protected]>
  • Loading branch information
error27 authored and Jiri Kosina committed Aug 23, 2011
1 parent 2bbaf77 commit 8f25229
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/hid/hid-lg4ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8f25229

Please sign in to comment.