Skip to contentSkip to conversation

Input: amijoy - fix memory region leak on registration failure

PATCH Superseded Thorsten Blum 2 participants 2 messages Nov 7 – Nov 8

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

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

Fixes 127278ce2254 ("Input: joysticks - handle errors when registering input devices")
---
 drivers/input/joystick/amijoy.c | 1 +
 1 file changed, 1 insertion(+)
drivers/input/joystick/amijoy.c +1 -0
index cdb2b8f15348..3c2357ba7dc3 100644
@@ -132,6 +132,7 @@ static int __init amijoy_init(void)
 		err = input_register_device(amijoy_dev[i]);
 		if (err) {
 			input_free_device(amijoy_dev[i]);
+			release_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2);
 			goto fail;
 		}
 	}
maintainer
#1 lore raw

Hi Thorsten,

Quoted 5 lines · Thorsten Blum

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

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

...

drivers/input/joystick/amijoy.c static int __init amijoy_init(void) · line 137

Quoted 6 lines
drivers/input/joystick/amijoy.c +1 -0
 		err = input_register_device(amijoy_dev[i]);
 		if (err) {
 			input_free_device(amijoy_dev[i]);
+			release_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2);
 			goto fail;
 		}

Do we really need this in stable? It has been like this for 20 years, and only affects an unlikely input_register_device() failure (basically -ENOMEM during init) on Amiga hardware, so please drop Cc: stable.

Without the constraint of keeping the diff minimal for stable, could we also clean up the error handling here instead of unwinding inline (and out of order relative to input_allocate_device() / request_mem_region())? Either add cascading err_release_mem / err_free_dev labels before the unregister loop so unwinding happens in reverse order without repeating input_free_device(), or factor per-port initialization out into a small amijoy_setup_port() helper.

Thanks.

Signature · 1 line
Dmitry