]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
HID: nvidia-shield: Add missing null pointer checks to LED initialization
authorKunwu Chan <chentao@kylinos.cn>
Fri, 19 Jan 2024 06:07:14 +0000 (14:07 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 1 Mar 2024 12:34:51 +0000 (13:34 +0100)
[ Upstream commit b6eda11c44dc89a681e1c105f0f4660e69b1e183 ]

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>
drivers/hid/hid-nvidia-shield.c

index c463e54decbce1476bb9e56980af2330fed6a4b9..edd0b0f1193bd246aa336afefbc13642d8ab9fec 100644 (file)
@@ -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);