mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] Input: amijoy - fix memory region leak on registration failure
@ 2026-11-08  0:49 Thorsten Blum
  0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-11-08  0:49 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Thorsten Blum, Dmitry Torokhov, linux-input, linux-kernel

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")
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
Changes in v2:
- Consolidate the error paths (Dmitry)
- Drop cc stable (Dmitry)
- v1: https://lore.kernel.org/r/20261107160159.367919-2-blum@kernel.org/

 drivers/input/joystick/amijoy.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index 3752dc2a2086..03e5f924c678 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-08  0:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08  0:49 [PATCH v2] Input: amijoy - fix memory region leak on registration failure Thorsten Blum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®