linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mariusz Kozlowski <m.kozlowski@tuxland.pl>
To: jkosina@suse.cz
Cc: linux-input@atrey.karlin.mff.cuni.cz, linux-kernel@vger.kernel.org
Subject: [PATCH] hid: hidraw_connect memleak fix
Date: Thu, 27 Sep 2007 09:33:12 +0200	[thread overview]
Message-ID: <200709270933.13497.m.kozlowski@tuxland.pl> (raw)

It looks like hidraw_connect() is leaking memory in case of failure.
Also it should return -ENOMEM when kzalloc fails.

Signed-off-by: Mariusz Kozlowski <m.kozlowski@tuxland.pl>

 drivers/hid/hidraw.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

--- linux-2.6.23-rc8-mm1-a/drivers/hid/hidraw.c	2007-09-26 12:07:37.000000000 +0200
+++ linux-2.6.23-rc8-mm1-b/drivers/hid/hidraw.c	2007-09-26 14:36:08.000000000 +0200
@@ -282,7 +282,7 @@ EXPORT_SYMBOL_GPL(hidraw_report_event);

 int hidraw_connect(struct hid_device *hid)
 {
-	int minor, result = -EINVAL;
+	int minor, result;
 	struct hidraw *dev;

 	/* TODO currently we accept any HID device. This should later
@@ -290,8 +290,11 @@ int hidraw_connect(struct hid_device *hi
 	 * non-input applications
 	 */

-	if (!(dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL)))
-		return -1;
+	dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+
+	result = -EINVAL;

 	spin_lock(&minors_lock);

@@ -305,8 +308,10 @@ int hidraw_connect(struct hid_device *hi

 	spin_unlock(&minors_lock);

-	if (result)
+	if (result) {
+		kfree(dev);
 		goto out;
+	}

 	dev->dev = device_create(hidraw_class, NULL, MKDEV(hidraw_major, minor),
 				"%s%d", "hidraw", minor);
@@ -316,6 +321,7 @@ int hidraw_connect(struct hid_device *hi
 		hidraw_table[minor] = NULL;
 		spin_unlock(&minors_lock);
 		result = PTR_ERR(dev->dev);
+		kfree(dev);
 		goto out;
 	}

             reply	other threads:[~2007-09-27  7:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-27  7:33 Mariusz Kozlowski [this message]
2007-09-27  9:40 ` [PATCH] hid: hidraw_connect memleak fix Jiri Kosina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200709270933.13497.m.kozlowski@tuxland.pl \
    --to=m.kozlowski@tuxland.pl \
    --cc=jkosina@suse.cz \
    --cc=linux-input@atrey.karlin.mff.cuni.cz \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).