Skip to content

Commit

Permalink
HID: nvidia-shield: Add missing null pointer checks to LED initializa…
Browse files Browse the repository at this point in the history
…tion

[ Upstream commit b6eda11 ]

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.

[jkosina@suse.com: tweak changelog a bit]
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Reviewed-by: Rahul Rameshbabu <rrameshbabu@nvidia.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
KunWuChan authored and gregkh committed Mar 1, 2024
1 parent 034a006 commit 83527a1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/hid/hid-nvidia-shield.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,8 @@ static inline int thunderstrike_led_create(struct thunderstrike *ts)

led->name = devm_kasprintf(&ts->base.hdev->dev, GFP_KERNEL,
"thunderstrike%d:blue:led", ts->id);
if (!led->name)
return -ENOMEM;
led->max_brightness = 1;
led->flags = LED_CORE_SUSPENDRESUME | LED_RETAIN_AT_SHUTDOWN;
led->brightness_get = &thunderstrike_led_get_brightness;
Expand Down Expand Up @@ -831,6 +833,8 @@ static inline int thunderstrike_psy_create(struct shield_device *shield_dev)
shield_dev->battery_dev.desc.name =
devm_kasprintf(&ts->base.hdev->dev, GFP_KERNEL,
"thunderstrike_%d", ts->id);
if (!shield_dev->battery_dev.desc.name)
return -ENOMEM;

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

0 comments on commit 83527a1

Please sign in to comment.