Skip to contentSkip to conversation

m68k/amiga: missing platform_device_unregister() on error in amiga_init_devices()

PATCH In review Qinglang Miao 2 participants 3 messages Jul 28, 2020 – Sep 19, 2020 m68k architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 m68k/amiga: 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 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/m68k/amiga/platform.c +6 -2
index d34029d7b..afa2782c6 100644
@@ -188,8 +188,10 @@ static int __init amiga_init_devices(void)
 			return PTR_ERR(pdev);
 		error = platform_device_add_data(pdev, &a1200_ide_pdata,
 						 sizeof(a1200_ide_pdata));
-		if (error)
+		if (error) {
+			platform_device_unregister(pdev);
 			return error;
+		}
 	}
 
 	if (AMIGAHW_PRESENT(A4000_IDE)) {
@@ -199,8 +201,10 @@ static int __init amiga_init_devices(void)
 			return PTR_ERR(pdev);
 		error = platform_device_add_data(pdev, &a4000_ide_pdata,
 						 sizeof(a4000_ide_pdata));
-		if (error)
+		if (error) {
+			platform_device_unregister(pdev);
 			return error;
+		}
 	}
 
 
Signature · 1 line
2.25.1
#1 lore raw

Hi Qinglang,

Quoted 4 lines · Qinglang Miao

Add the missing platform_device_unregister() before return from amiga_init_devices() in the error handling case.

Thanks for your patch!

arch/m68k/amiga/platform.c static int __init amiga_init_devices(void) · line 190

Quoted 6 lines
arch/m68k/amiga/platform.c +0 -0
@@ -188,8 +188,10 @@ static int __init amiga_init_devices(void)
                        return PTR_ERR(pdev);
                error = platform_device_add_data(pdev, &a1200_ide_pdata,
                                                 sizeof(a1200_ide_pdata));

The only reason why platform_device_add_data() can fail is because the system ran out of memory. If that's the case this early, the whole system will fail to work anyway, and it doesn't matter that the IDE driver will crash later due to missing platform data.

So I don't think it helps to increase kernel size by adding more error handling.

Quoted 9 lines
arch/m68k/amiga/platform.c +3 -1
-               if (error)
+               if (error) {
+                       platform_device_unregister(pdev);
                        return error;
+               }
        }
 
        if (AMIGAHW_PRESENT(A4000_IDE)) {

arch/m68k/amiga/platform.c static int __init amiga_init_devices(void) · line 205

Quoted 6 lines
arch/m68k/amiga/platform.c +2 -1
@@ -199,8 +201,10 @@ static int __init amiga_init_devices(void)
                        return PTR_ERR(pdev);
                error = platform_device_add_data(pdev, &a4000_ide_pdata,
                                                 sizeof(a4000_ide_pdata));
-               if (error)
+               if (error) {
+                       platform_device_unregister(pdev);

Likewise.

arch/m68k/amiga/platform.c static int __init amiga_init_devices(void) · line 207

Quoted 2 lines
arch/m68k/amiga/platform.c +1 -0
                        return error;
+               }

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
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
#2 lore raw
Quoted 22 lines · Geert Uytterhoeven

Hi Qinglang,

Quoted 4 lines · Qinglang Miao

Add the missing platform_device_unregister() before return from amiga_init_devices() in the error handling case.

Thanks for your patch!

arch/m68k/amiga/platform.c static int __init amiga_init_devices(void) · line 190

Quoted 6 lines
arch/m68k/amiga/platform.c +0 -0
@@ -188,8 +188,10 @@ static int __init amiga_init_devices(void)
                         return PTR_ERR(pdev);
                 error = platform_device_add_data(pdev, &a1200_ide_pdata,
                                                  sizeof(a1200_ide_pdata));

The only reason why platform_device_add_data() can fail is because the system ran out of memory. If that's the case this early, the whole system will fail to work anyway, and it doesn't matter that the IDE driver will crash later due to missing platform data.

Quoted 3 lines

So I don't think it helps to increase kernel size by adding more error handling.

Hi Geert,

Glad to know your opnions, it sounds resonable to me.

Thanks.

Quoted 25 lines
Quoted 9 lines
arch/m68k/amiga/platform.c +3 -1
-               if (error)
+               if (error) {
+                       platform_device_unregister(pdev);
                         return error;
+               }
         }
 
         if (AMIGAHW_PRESENT(A4000_IDE)) {

arch/m68k/amiga/platform.c static int __init amiga_init_devices(void) · line 205

Quoted 6 lines
arch/m68k/amiga/platform.c +2 -1
@@ -199,8 +201,10 @@ static int __init amiga_init_devices(void)
                         return PTR_ERR(pdev);
                 error = platform_device_add_data(pdev, &a4000_ide_pdata,
                                                  sizeof(a4000_ide_pdata));
-               if (error)
+               if (error) {
+                       platform_device_unregister(pdev);

Likewise.

arch/m68k/amiga/platform.c static int __init amiga_init_devices(void) · line 207

Quoted 2 lines
arch/m68k/amiga/platform.c +1 -0
                         return error;
+               }

Gr{oetje,eeting}s,

Geert