Skip to content

Commit 0922386

Browse files
dtorJiri Kosina
authored andcommitted
HID: input: optionally use device id in battery name
Manufacturers do not always populate serial number in their devices, so let's fall back to device ID when forming the battery device name. As a result, batteries in devices without serial number will be named like this: hid-0018:2D1F:510E.0001-battery (as opposed to hid--battery for the first one, and failing to create batteries for the subsequent ones). Signed-off-by: Dmitry Torokhov <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 581c448 commit 0922386

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/hid/hid-input.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,9 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
456456
if (!psy_desc)
457457
return -ENOMEM;
458458

459-
psy_desc->name = kasprintf(GFP_KERNEL, "hid-%s-battery", dev->uniq);
459+
psy_desc->name = kasprintf(GFP_KERNEL, "hid-%s-battery",
460+
strlen(dev->uniq) ?
461+
dev->uniq : dev_name(&dev->dev));
460462
if (!psy_desc->name) {
461463
error = -ENOMEM;
462464
goto err_free_mem;

0 commit comments

Comments
 (0)