Skip to content

Commit b6eda11

Browse files
KunWuChanJiri Kosina
authored andcommitted
HID: nvidia-shield: Add missing null pointer checks to LED initialization
devm_kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Ensure the allocation was successful by checking the pointer validity. [[email protected]: tweak changelog a bit] Signed-off-by: Kunwu Chan <[email protected]> Reviewed-by: Rahul Rameshbabu <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent afa6ac2 commit b6eda11

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/hid/hid-nvidia-shield.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,8 @@ static inline int thunderstrike_led_create(struct thunderstrike *ts)
800800

801801
led->name = devm_kasprintf(&ts->base.hdev->dev, GFP_KERNEL,
802802
"thunderstrike%d:blue:led", ts->id);
803+
if (!led->name)
804+
return -ENOMEM;
803805
led->max_brightness = 1;
804806
led->flags = LED_CORE_SUSPENDRESUME | LED_RETAIN_AT_SHUTDOWN;
805807
led->brightness_get = &thunderstrike_led_get_brightness;
@@ -831,6 +833,8 @@ static inline int thunderstrike_psy_create(struct shield_device *shield_dev)
831833
shield_dev->battery_dev.desc.name =
832834
devm_kasprintf(&ts->base.hdev->dev, GFP_KERNEL,
833835
"thunderstrike_%d", ts->id);
836+
if (!shield_dev->battery_dev.desc.name)
837+
return -ENOMEM;
834838

835839
shield_dev->battery_dev.psy = power_supply_register(
836840
&hdev->dev, &shield_dev->battery_dev.desc, &psy_cfg);

0 commit comments

Comments
 (0)