Skip to contentSkip to conversation

Input: amijoy - fix memory region leak on registration failure

PATCH Applied Thorsten Blum 2 participants 2 messages Nov 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Input: amijoy - fix memory region leak on registration failure

If input_register_device() fails in amijoy_init(), release the memory region for the current port before cleaning up the previously registered ports.

Consolidate the error paths while at it.

Fixes 127278ce2254 ("Input: joysticks - handle errors when registering input devices")

---
Changes in v2:
- Consolidate the error paths (Dmitry)
- Drop cc stable (Dmitry)
- v1: https://lore.kernel.org/r/[email protected]/

 drivers/input/joystick/amijoy.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/input/joystick/amijoy.c +10 -8
index 3752dc2a2086..03e5f924c678 100644
@@ -98,13 +98,12 @@ static int __init amijoy_init(void)
 		amijoy_dev[i] = input_allocate_device();
 		if (!amijoy_dev[i]) {
 			err = -ENOMEM;
-			goto fail;
+			goto err_unregister;
 		}
 
 		if (!request_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2, "amijoy [Denise]")) {
-			input_free_device(amijoy_dev[i]);
 			err = -EBUSY;
-			goto fail;
+			goto err_free_dev;
 		}
 
 		amijoy_dev[i]->name = "Amiga joystick";
@@ -127,14 +126,17 @@ static int __init amijoy_init(void)
 		}
 
 		err = input_register_device(amijoy_dev[i]);
-		if (err) {
-			input_free_device(amijoy_dev[i]);
-			goto fail;
-		}
+		if (err)
+			goto err_release_mem;
 	}
 	return 0;
 
- fail:	while (--i >= 0)
+err_release_mem:
+	release_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2);
+err_free_dev:
+	input_free_device(amijoy_dev[i]);
+err_unregister:
+	while (--i >= 0)
 		if (amijoy[i]) {
 			input_unregister_device(amijoy_dev[i]);
 			release_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2);
maintainer Applied
#1 lore raw
Quoted 8 lines · Thorsten Blum

If input_register_device() fails in amijoy_init(), release the memory region for the current port before cleaning up the previously registered ports.

Consolidate the error paths while at it.

Fixes 127278ce2254 ("Input: joysticks - handle errors when registering input devices")

Applied, thank you.

Signature · 1 line
Dmitry