summaryrefslogtreecommitdiffstats
path: root/drivers/hid/uhid.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-07-29 17:14:18 +0200
committerJiri Kosina <jkosina@suse.cz>2014-08-25 03:28:06 -0500
commit25be7fe2be879a96920cc74809e1bff1b0ae0bac (patch)
tree5aceb475e238677842f5b22fde8ce957b9932c67 /drivers/hid/uhid.c
parent41c4a46423c08274ef83cdbd44bbd2066cba59bb (diff)
downloadop-kernel-dev-25be7fe2be879a96920cc74809e1bff1b0ae0bac.zip
op-kernel-dev-25be7fe2be879a96920cc74809e1bff1b0ae0bac.tar.gz
HID: uhid: avoid magic-numbers when setting strings
Avoid hard-coding the target buffer sizes and use sizeof() instead. This also makes us future-proof to buffer-extensions later on. Signed-off-by: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/uhid.c')
-rw-r--r--drivers/hid/uhid.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
index bf13746..5dee8bd 100644
--- a/drivers/hid/uhid.c
+++ b/drivers/hid/uhid.c
@@ -363,7 +363,7 @@ static int uhid_dev_create2(struct uhid_device *uhid,
const struct uhid_event *ev)
{
struct hid_device *hid;
- size_t rd_size;
+ size_t rd_size, len;
void *rd_data;
int ret;
@@ -387,12 +387,12 @@ static int uhid_dev_create2(struct uhid_device *uhid,
goto err_free;
}
- strncpy(hid->name, ev->u.create2.name, 127);
- hid->name[127] = 0;
- strncpy(hid->phys, ev->u.create2.phys, 63);
- hid->phys[63] = 0;
- strncpy(hid->uniq, ev->u.create2.uniq, 63);
- hid->uniq[63] = 0;
+ len = min(sizeof(hid->name), sizeof(ev->u.create2.name)) - 1;
+ strncpy(hid->name, ev->u.create2.name, len);
+ len = min(sizeof(hid->phys), sizeof(ev->u.create2.phys)) - 1;
+ strncpy(hid->phys, ev->u.create2.phys, len);
+ len = min(sizeof(hid->uniq), sizeof(ev->u.create2.uniq)) - 1;
+ strncpy(hid->uniq, ev->u.create2.uniq, len);
hid->ll_driver = &uhid_hid_driver;
hid->bus = ev->u.create2.bus;
OpenPOWER on IntegriCloud