From: David Herrmann <dh.herrmann@gmail.com>
To: linux-input@vger.kernel.org
Cc: Jiri Kosina <jkosina@suse.cz>,
Benjamin Tissoires <benjamin.tissoires@gmail.com>,
David Herrmann <dh.herrmann@gmail.com>
Subject: [PATCH 03/12] HID: uhid: avoid dangling pointers in uhid context
Date: Tue, 29 Jul 2014 17:14:17 +0200 [thread overview]
Message-ID: <1406646866-999-4-git-send-email-dh.herrmann@gmail.com> (raw)
In-Reply-To: <1406646866-999-1-git-send-email-dh.herrmann@gmail.com>
Avoid keeping uhid->rd_data and uhid->rd_size set in case
uhid_dev_create2() fails. This is non-critical as we never flip
uhid->running and thus never enter uhid_dev_destroy(). However, it's much
nicer for debugging if pointers are only set if they point to valid data.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
---
drivers/hid/uhid.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
index c05b544..bf13746 100644
--- a/drivers/hid/uhid.c
+++ b/drivers/hid/uhid.c
@@ -363,20 +363,24 @@ static int uhid_dev_create2(struct uhid_device *uhid,
const struct uhid_event *ev)
{
struct hid_device *hid;
+ size_t rd_size;
+ void *rd_data;
int ret;
if (uhid->running)
return -EALREADY;
- uhid->rd_size = ev->u.create2.rd_size;
- if (uhid->rd_size <= 0 || uhid->rd_size > HID_MAX_DESCRIPTOR_SIZE)
+ rd_size = ev->u.create2.rd_size;
+ if (rd_size <= 0 || rd_size > HID_MAX_DESCRIPTOR_SIZE)
return -EINVAL;
- uhid->rd_data = kmemdup(ev->u.create2.rd_data, uhid->rd_size,
- GFP_KERNEL);
- if (!uhid->rd_data)
+ rd_data = kmemdup(ev->u.create2.rd_data, rd_size, GFP_KERNEL);
+ if (!rd_data)
return -ENOMEM;
+ uhid->rd_size = rd_size;
+ uhid->rd_data = rd_data;
+
hid = hid_allocate_device();
if (IS_ERR(hid)) {
ret = PTR_ERR(hid);
@@ -416,6 +420,8 @@ err_hid:
uhid->running = false;
err_free:
kfree(uhid->rd_data);
+ uhid->rd_data = NULL;
+ uhid->rd_size = 0;
return ret;
}
--
2.0.3
next prev parent reply other threads:[~2014-07-29 15:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-29 15:14 [PATCH 00/12] HID: Convert UHID to new HID transport-layer David Herrmann
2014-07-29 15:14 ` [PATCH 01/12] HID: uhid: simplify report-cb shutdown David Herrmann
2014-07-29 15:14 ` [PATCH 02/12] HID: uhid: forward create_req to create2_req David Herrmann
2014-07-29 15:14 ` David Herrmann [this message]
2014-07-29 15:14 ` [PATCH 04/12] HID: uhid: avoid magic-numbers when setting strings David Herrmann
2014-07-29 15:14 ` [PATCH 05/12] HID: uhid: turn report_id into u32 David Herrmann
2014-07-29 15:14 ` [PATCH 06/12] HID: uhid: invert report_done and make non-atomic David Herrmann
2014-07-29 15:14 ` [PATCH 07/12] HID: uhid: add ABI compatible UHID_GET_REPORT replacing UHID_FEATURE David Herrmann
2014-07-29 15:14 ` [PATCH 08/12] HID: uhid: keep legacy definitions at the bottom of uhid.h David Herrmann
2014-07-29 15:14 ` [PATCH 09/12] HID: uhid: rename uhid_raw_request to uhid_hid_raw_request David Herrmann
2014-07-29 15:14 ` [PATCH 10/12] HID: uhid: implement SET_REPORT David Herrmann
2014-07-29 15:14 ` [PATCH 11/12] HID: uhid: report to user-space whether reports are numbered David Herrmann
2014-07-29 15:14 ` [PATCH 12/12] HID: uhid: update documentation David Herrmann
2014-07-29 19:00 ` [PATCH 00/12] HID: Convert UHID to new HID transport-layer Jiri Kosina
2014-07-29 19:03 ` David Herrmann
2014-08-25 8:34 ` 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=1406646866-999-4-git-send-email-dh.herrmann@gmail.com \
--to=dh.herrmann@gmail.com \
--cc=benjamin.tissoires@gmail.com \
--cc=jkosina@suse.cz \
--cc=linux-input@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).