public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: walter harms <wharms@bfs.de>
Cc: Jiri Kosina <jkosina@suse.cz>,
	open@bfs.de, list@bfs.de,
	HID CORE LAYER <linux-input@vger.kernel.org>,
	kernel-janitors@vger.kernel.org
Subject: [patch 2/2 -next v2] hid-lg4ff: add a kfree() to an error path
Date: Fri, 19 Aug 2011 08:00:55 +0000	[thread overview]
Message-ID: <20110819080055.GH21927@shale.localdomain> (raw)
In-Reply-To: <4E4D2E4A.3020205@bfs.de>

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 <error27@gmail.com>

diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
index dc38c2d..cbb0089 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;


  parent reply	other threads:[~2011-08-19  8:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-18 13:43 [patch 2/2 -next] hid-lg4ff: add a kfree() to an error path Dan Carpenter
     [not found] ` <CAMvewQJigdY81gPrpndqV=FxN+cEeif4NkzSbBZKCO4z3guQew@mail.gmail.com>
2011-08-18 16:24   ` Dan Carpenter
     [not found] ` <4E4D2E4A.3020205@bfs.de>
2011-08-19  8:00   ` Dan Carpenter [this message]
2011-08-23  8:46     ` [patch 2/2 -next v2] " 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=20110819080055.GH21927@shale.localdomain \
    --to=error27@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=list@bfs.de \
    --cc=open@bfs.de \
    --cc=wharms@bfs.de \
    /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