Commit b6eda11c authored by Kunwu Chan's avatar Kunwu Chan Committed by Jiri Kosina
Browse files

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.

[jkosina@suse.com: tweak changelog a bit]
Signed-off-by: default avatarKunwu Chan <chentao@kylinos.cn>
Reviewed-by: default avatarRahul Rameshbabu <rrameshbabu@nvidia.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.com>
parent afa6ac26
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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);