Commit 25be7fe2 authored by David Herrmann's avatar David Herrmann Committed by Jiri Kosina

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: default avatarDavid Herrmann <dh.herrmann@gmail.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 41c4a464
...@@ -363,7 +363,7 @@ static int uhid_dev_create2(struct uhid_device *uhid, ...@@ -363,7 +363,7 @@ static int uhid_dev_create2(struct uhid_device *uhid,
const struct uhid_event *ev) const struct uhid_event *ev)
{ {
struct hid_device *hid; struct hid_device *hid;
size_t rd_size; size_t rd_size, len;
void *rd_data; void *rd_data;
int ret; int ret;
...@@ -387,12 +387,12 @@ static int uhid_dev_create2(struct uhid_device *uhid, ...@@ -387,12 +387,12 @@ static int uhid_dev_create2(struct uhid_device *uhid,
goto err_free; goto err_free;
} }
strncpy(hid->name, ev->u.create2.name, 127); len = min(sizeof(hid->name), sizeof(ev->u.create2.name)) - 1;
hid->name[127] = 0; strncpy(hid->name, ev->u.create2.name, len);
strncpy(hid->phys, ev->u.create2.phys, 63); len = min(sizeof(hid->phys), sizeof(ev->u.create2.phys)) - 1;
hid->phys[63] = 0; strncpy(hid->phys, ev->u.create2.phys, len);
strncpy(hid->uniq, ev->u.create2.uniq, 63); len = min(sizeof(hid->uniq), sizeof(ev->u.create2.uniq)) - 1;
hid->uniq[63] = 0; strncpy(hid->uniq, ev->u.create2.uniq, len);
hid->ll_driver = &uhid_hid_driver; hid->ll_driver = &uhid_hid_driver;
hid->bus = ev->u.create2.bus; hid->bus = ev->u.create2.bus;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment