Skip to content

Commit

Permalink
HID: uhid: avoid magic-numbers when setting strings
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
David Herrmann authored and Jiri Kosina committed Aug 25, 2014
1 parent 41c4a46 commit 25be7fe
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions drivers/hid/uhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit 25be7fe

Please sign in to comment.