提交 709d27c0 编写于 作者: M Mariusz Kozlowski 提交者: Jiri Kosina

HID: hidraw_connect() memleak fix

It looks like hidraw_connect() is leaking memory in case of failure.
Also it should return -ENOMEM when kzalloc fails.
Signed-off-by: NMariusz Kozlowski <m.kozlowski@tuxland.pl>
Signed-off-by: NJiri Kosina <jkosina@suse.cz>
上级 86166b7b
...@@ -282,7 +282,7 @@ EXPORT_SYMBOL_GPL(hidraw_report_event); ...@@ -282,7 +282,7 @@ EXPORT_SYMBOL_GPL(hidraw_report_event);
int hidraw_connect(struct hid_device *hid) int hidraw_connect(struct hid_device *hid)
{ {
int minor, result = -EINVAL; int minor, result;
struct hidraw *dev; struct hidraw *dev;
/* TODO currently we accept any HID device. This should later /* TODO currently we accept any HID device. This should later
...@@ -290,8 +290,11 @@ int hidraw_connect(struct hid_device *hid) ...@@ -290,8 +290,11 @@ int hidraw_connect(struct hid_device *hid)
* non-input applications * non-input applications
*/ */
if (!(dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL))) dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL);
return -1; if (!dev)
return -ENOMEM;
result = -EINVAL;
spin_lock(&minors_lock); spin_lock(&minors_lock);
...@@ -305,8 +308,10 @@ int hidraw_connect(struct hid_device *hid) ...@@ -305,8 +308,10 @@ int hidraw_connect(struct hid_device *hid)
spin_unlock(&minors_lock); spin_unlock(&minors_lock);
if (result) if (result) {
kfree(dev);
goto out; goto out;
}
dev->dev = device_create(hidraw_class, NULL, MKDEV(hidraw_major, minor), dev->dev = device_create(hidraw_class, NULL, MKDEV(hidraw_major, minor),
"%s%d", "hidraw", minor); "%s%d", "hidraw", minor);
...@@ -316,6 +321,7 @@ int hidraw_connect(struct hid_device *hid) ...@@ -316,6 +321,7 @@ int hidraw_connect(struct hid_device *hid)
hidraw_table[minor] = NULL; hidraw_table[minor] = NULL;
spin_unlock(&minors_lock); spin_unlock(&minors_lock);
result = PTR_ERR(dev->dev); result = PTR_ERR(dev->dev);
kfree(dev);
goto out; goto out;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册