[PATCH] HID: logitech-hidpp: Replace devm_kasprintf() call by devm_kstrdup() in hidpp_connect_event()

Markus Elfring posted 1 patch 8 months ago
drivers/hid/hid-logitech-hidpp.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] HID: logitech-hidpp: Replace devm_kasprintf() call by devm_kstrdup() in hidpp_connect_event()
Posted by Markus Elfring 8 months ago
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 16 Apr 2025 15:25:05 +0200

Use a devm_kstrdup() call instead of a devm_kasprintf() call
in this function implementation because only a single string
should be copied.

The source code was transformed by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/hid/hid-logitech-hidpp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 10a3bc5f931b..c1a9ecde57c6 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -4216,8 +4216,7 @@ static void hidpp_connect_event(struct work_struct *work)
 	if (hidpp->name == hdev->name && hidpp->protocol_major >= 2) {
 		name = hidpp_get_device_name(hidpp);
 		if (name) {
-			devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
-						   "%s", name);
+			devm_name = devm_kstrdup(&hdev->dev, name, GFP_KERNEL);
 			kfree(name);
 			if (!devm_name)
 				return;
-- 
2.49.0