Skip to contentSkip to conversation

HID: axff: add cleanup allocated struct axff_device heap

PATCH In review Jeongjun Park 2 participants 3 messages Aug 18, 2025 – Aug 20, 2025 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: axff: add cleanup allocated struct axff_device heap

Currently, acrux hid driver allocates heap memory equal to sizeof(struct axff_device) to support force feedback, but there's no code to free this memory except when initialization fails. This causes the allocated memory to not be freed even if the driver is detached.

Therefore, to properly clean up and safely manage the allocated heap, must be modified to use devm_kzalloc().

Fixes c0dbcc33c652 ("HID: add ACRUX game controller force feedback support")
---
 drivers/hid/hid-axff.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/hid/hid-axff.c +2 -6
index fbe4e16ab029..b8202737f4c8 100644
@@ -96,7 +96,7 @@ static int axff_init(struct hid_device *hid)
 		return -ENODEV;
 	}
 
-	axff = kzalloc(sizeof(struct axff_device), GFP_KERNEL);
+	axff = devm_kzalloc(&hid->dev, sizeof(struct axff_device), GFP_KERNEL);
 	if (!axff)
 		return -ENOMEM;
 
@@ -104,7 +104,7 @@ static int axff_init(struct hid_device *hid)
 
 	error = input_ff_create_memless(dev, axff, axff_play);
 	if (error)
-		goto err_free_mem;
+		return error;
 
 	axff->report = report;
 	hid_hw_request(hid, axff->report, HID_REQ_SET_REPORT);
@@ -112,10 +112,6 @@ static int axff_init(struct hid_device *hid)
 	hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun <[email protected]>\n");
 
 	return 0;
-
-err_free_mem:
-	kfree(axff);
-	return error;
 }
 #else
 static inline int axff_init(struct hid_device *hid)

--

#1 lore raw

Hi Jeongjun,

Quoted 7 lines · Jeongjun Park

Currently, acrux hid driver allocates heap memory equal to sizeof(struct axff_device) to support force feedback, but there's no code to free this memory except when initialization fails. This causes the allocated memory to not be freed even if the driver is detached.

Therefore, to properly clean up and safely manage the allocated heap, must be modified to use devm_kzalloc().

You have not tested this, have you? The private data that is passed to input_ff_create_memless() is freed by ml_ff_destroy() which is invoked when input core calls input_ff_destroy() as part of input device teardown. Your change introduces double-free.

Quoted 32 lines
Fixes c0dbcc33c652 ("HID: add ACRUX game controller force feedback support")
---
 drivers/hid/hid-axff.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/hid/hid-axff.c +2 -2
index fbe4e16ab029..b8202737f4c8 100644
@@ -96,7 +96,7 @@ static int axff_init(struct hid_device *hid)
 		return -ENODEV;
 	}
 
-	axff = kzalloc(sizeof(struct axff_device), GFP_KERNEL);
+	axff = devm_kzalloc(&hid->dev, sizeof(struct axff_device), GFP_KERNEL);
 	if (!axff)
 		return -ENOMEM;
 
@@ -104,7 +104,7 @@ static int axff_init(struct hid_device *hid)
 
 	error = input_ff_create_memless(dev, axff, axff_play);
 	if (error)
-		goto err_free_mem;
+		return error;
 
 	axff->report = report;
 	hid_hw_request(hid, axff->report, HID_REQ_SET_REPORT);
@@ -112,10 +112,6 @@ static int axff_init(struct hid_device *hid)
 	hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun <[email protected]>\n");

drivers/hid/hid-axff.c static int axff_init(struct hid_device *hid)

Quoted 10 lines
drivers/hid/hid-axff.c +0 -5
 
 	return 0;
-
-err_free_mem:
-	kfree(axff);
-	return error;
 }
 #else
 static inline int axff_init(struct hid_device *hid)
--

Thanks.

Signature · 1 line
Dmitry
#2 lore raw

Hello Dmitry,

Quoted 8 lines · Dmitry Torokhov

Hi Jeongjun,

Quoted 5 lines · Jeongjun Park

Currently, acrux hid driver allocates heap memory equal to sizeof(struct axff_device) to support force feedback, but there's no code to free this memory except when initialization fails. This causes the allocated memory to not be freed even if the driver is detached.

Quoted 7 lines
Quoted 2 lines

Therefore, to properly clean up and safely manage the allocated heap, must be modified to use devm_kzalloc().

You have not tested this, have you? The private data that is passed to input_ff_create_memless() is freed by ml_ff_destroy() which is invoked when input core calls input_ff_destroy() as part of input device teardown. Your change introduces double-free.

Oops, I checked again and realized my patch was a complete mess.

Thanks for letting me know!

Regards,
Jeongjun Park