m68k/amiga: fix missing platform_device_unregister() on error in amiga_init_devices()
PATCH 1/1 m68k/amiga: fix missing platform_device_unregister() on error in amiga_init_devices()
Add the missing platform_device_unregister() before return from amiga_init_devices() in the error handling case.
--- arch/m68k/amiga/platform.c | 99 ++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 26 deletions(-)
arch/m68k/amiga/platform.c +73 -26
@@ -131,10 +131,14 @@ static const struct resource amiga_rtc_resource __initconst = { }; +#define AMIGA_PLATFORM_DEVICES 13 +static int __init amiga_init_devices (void ) {struct platform_device *pdev; +struct platform_device *pdevs[AMIGA_PLATFORM_DEVICES ];int error; +int i =0 ;if (!MACH_IS_AMIGA )return -ENODEV ;
@@ -145,6 +149,7 @@ static int __init amiga_init_devices(void) 0);if (IS_ERR (pdev))return PTR_ERR (pdev); + pdevs[i++] = pdev; }
@@ -152,8 +157,11 @@ static int __init amiga_init_devices(void)if (AMIGAHW_PRESENT (AMI_AUDIO )) { pdev =platform_device_register_simple ("amiga-audio" ,-1 ,NULL ,0 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +if (IS_ERR (pdev)) { + error =PTR_ERR (pdev); + goto err_unregister_pdevs; + } + pdevs[i++] = pdev; }
@@ -161,46 +169,61 @@ static int __init amiga_init_devices(void)if (AMIGAHW_PRESENT (AMI_FLOPPY )) { pdev =platform_device_register_simple ("amiga-floppy" ,-1 ,NULL ,0 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +if (IS_ERR (pdev)) { + error =PTR_ERR (pdev); + goto err_unregister_pdevs; + } + pdevs[i++] = pdev; }if (AMIGAHW_PRESENT (A3000_SCSI )) { pdev =platform_device_register_simple ("amiga-a3000-scsi" ,-1 , &a3000_scsi_resource,1 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +if (IS_ERR (pdev)) { + error =PTR_ERR (pdev); + goto err_unregister_pdevs; + } + pdevs[i++] = pdev; }if (AMIGAHW_PRESENT (A4000_SCSI )) { pdev =platform_device_register_simple ("amiga-a4000t-scsi" ,-1 , &a4000t_scsi_resource,1 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +if (IS_ERR (pdev)) { + error =PTR_ERR (pdev); + goto err_unregister_pdevs; + } + pdevs[i++] = pdev; }if (AMIGAHW_PRESENT (A1200_IDE ) ||z_dev_present (ZORRO_PROD_MTEC_VIPER_MK_V_E_MATRIX_530_SCSI_IDE )) { pdev =platform_device_register_simple ("amiga-gayle-ide" ,-1 , &a1200_ide_resource,1 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +if (IS_ERR (pdev)) { + error =PTR_ERR (pdev); + goto err_unregister_pdevs; + } error =platform_device_add_data (pdev, &a1200_ide_pdata,sizeof (a1200_ide_pdata));if (error) -return error; + goto err_unregister_pdevs; + pdevs[i++] = pdev; }if (AMIGAHW_PRESENT (A4000_IDE )) { pdev =platform_device_register_simple ("amiga-gayle-ide" ,-1 , &a4000_ide_resource,1 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +if (IS_ERR (pdev)) { + error =PTR_ERR (pdev); + goto err_unregister_pdevs; + } error =platform_device_add_data (pdev, &a4000_ide_pdata,sizeof (a4000_ide_pdata));if (error) -return error; + goto err_unregister_pdevs; + pdevs[i++] = pdev; }
@@ -208,29 +231,41 @@ static int __init amiga_init_devices(void)if (AMIGAHW_PRESENT (AMI_KEYBOARD )) { pdev =platform_device_register_simple ("amiga-keyboard" ,-1 ,NULL ,0 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +if (IS_ERR (pdev)) { + error =PTR_ERR (pdev); + goto err_unregister_pdevs; + } + pdevs[i++] = pdev; }if (AMIGAHW_PRESENT (AMI_MOUSE )) { pdev =platform_device_register_simple ("amiga-mouse" ,-1 ,NULL ,0 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +if (IS_ERR (pdev)) { + error =PTR_ERR (pdev); + goto err_unregister_pdevs; + } + pdevs[i++] = pdev; }if (AMIGAHW_PRESENT (AMI_SERIAL )) { pdev =platform_device_register_simple ("amiga-serial" ,-1 ,NULL ,0 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +if (IS_ERR (pdev)) { + error =PTR_ERR (pdev); + goto err_unregister_pdevs; + } + pdevs[i++] = pdev; }if (AMIGAHW_PRESENT (AMI_PARALLEL )) { pdev =platform_device_register_simple ("amiga-parallel" ,-1 ,NULL ,0 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +if (IS_ERR (pdev)) { + error =PTR_ERR (pdev); + goto err_unregister_pdevs; + } + pdevs[i++] = pdev; }
@@ -238,18 +273,30 @@ static int __init amiga_init_devices(void)if (AMIGAHW_PRESENT (A2000_CLK )) { pdev =platform_device_register_simple ("rtc-msm6242" ,-1 , &amiga_rtc_resource,1 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +if (IS_ERR (pdev)) { + error =PTR_ERR (pdev); + goto err_unregister_pdevs; + } + pdevs[i++] = pdev; }if (AMIGAHW_PRESENT (A3000_CLK )) { pdev =platform_device_register_simple ("rtc-rp5c01" ,-1 , &amiga_rtc_resource,1 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); +if (IS_ERR (pdev)) { + error =PTR_ERR (pdev); + goto err_unregister_pdevs; + } + pdevs[i++] = pdev; }return 0 ; + +err_unregister_pdevs: +while (i >0 ) +platform_device_unregister (pdevs[--i]); + +return error; }arch_initcall (amiga_init_devices);
Signature · 1 line
2.25.1
Geert Uytterhoeven
maintainerHi Yang,
Quoted 6 lines · Yang Yingliang
Add the missing
platform_device_unregister()before return fromamiga_init_devices()in the error handling case.Fixes eeed227966da ("m68k/amiga: Add error checks when registering platform devices")Reported-by Hulk Robot <[email protected]>Signed-off-by Yang Yingliang <[email protected]>
Thanks for your patch!
TBH, I don't think it's worth adding this code: this happens during early kernel startup. If any of these devices fail to register, that must happen because the system ran out of memory, and thus won't work anyway.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds