All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next v2] m68k: virt: platform: fix missing platform_device_unregister() on error in virt_platform_init()
@ 2022-06-28  8:49 Yang Yingliang
  2022-06-28 10:45 ` Laurent Vivier
  2022-07-06  9:17 ` Geert Uytterhoeven
  0 siblings, 2 replies; 3+ messages in thread
From: Yang Yingliang @ 2022-06-28  8:49 UTC (permalink / raw)
  To: linux-kernel, linux-m68k; +Cc: laurent, geert

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

Fixes: 05d51e42df06 ("m68k: Introduce a virtual m68k machine")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
v2:
  change for loop to while at lable err_unregister_rtc_virtio.
---
 arch/m68k/virt/platform.c | 58 ++++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 25 deletions(-)

diff --git a/arch/m68k/virt/platform.c b/arch/m68k/virt/platform.c
index cb820f19a221..1560c4140ab9 100644
--- a/arch/m68k/virt/platform.c
+++ b/arch/m68k/virt/platform.c
@@ -8,20 +8,15 @@
 
 #define VIRTIO_BUS_NB	128
 
-static int __init virt_virtio_init(unsigned int id)
+static struct platform_device * __init virt_virtio_init(unsigned int id)
 {
 	const struct resource res[] = {
 		DEFINE_RES_MEM(virt_bi_data.virtio.mmio + id * 0x200, 0x200),
 		DEFINE_RES_IRQ(virt_bi_data.virtio.irq + id),
 	};
-	struct platform_device *pdev;
 
-	pdev = platform_device_register_simple("virtio-mmio", id,
+	return platform_device_register_simple("virtio-mmio", id,
 					       res, ARRAY_SIZE(res));
-	if (IS_ERR(pdev))
-		return PTR_ERR(pdev);
-
-	return 0;
 }
 
 static int __init virt_platform_init(void)
@@ -35,8 +30,10 @@ static int __init virt_platform_init(void)
 		DEFINE_RES_MEM(virt_bi_data.rtc.mmio + 0x1000, 0x1000),
 		DEFINE_RES_IRQ(virt_bi_data.rtc.irq + 1),
 	};
-	struct platform_device *pdev;
+	struct platform_device *pdev1, *pdev2;
+	struct platform_device *pdevs[VIRTIO_BUS_NB];
 	unsigned int i;
+	int ret = 0;
 
 	if (!MACH_IS_VIRT)
 		return -ENODEV;
@@ -44,29 +41,40 @@ static int __init virt_platform_init(void)
 	/* We need this to have DMA'able memory provided to goldfish-tty */
 	min_low_pfn = 0;
 
-	pdev = platform_device_register_simple("goldfish_tty",
-					       PLATFORM_DEVID_NONE,
-					       goldfish_tty_res,
-					       ARRAY_SIZE(goldfish_tty_res));
-	if (IS_ERR(pdev))
-		return PTR_ERR(pdev);
+	pdev1 = platform_device_register_simple("goldfish_tty",
+						PLATFORM_DEVID_NONE,
+						goldfish_tty_res,
+						ARRAY_SIZE(goldfish_tty_res));
+	if (IS_ERR(pdev1))
+		return PTR_ERR(pdev1);
 
-	pdev = platform_device_register_simple("goldfish_rtc",
-					       PLATFORM_DEVID_NONE,
-					       goldfish_rtc_res,
-					       ARRAY_SIZE(goldfish_rtc_res));
-	if (IS_ERR(pdev))
-		return PTR_ERR(pdev);
+	pdev2 = platform_device_register_simple("goldfish_rtc",
+						PLATFORM_DEVID_NONE,
+						goldfish_rtc_res,
+						ARRAY_SIZE(goldfish_rtc_res));
+	if (IS_ERR(pdev2)) {
+		ret = PTR_ERR(pdev2);
+		goto err_unregister_tty;
+	}
 
 	for (i = 0; i < VIRTIO_BUS_NB; i++) {
-		int err;
-
-		err = virt_virtio_init(i);
-		if (err)
-			return err;
+		pdevs[i] = virt_virtio_init(i);
+		if (IS_ERR(pdevs[i])) {
+			ret = PTR_ERR(pdevs[i]);
+			goto err_unregister_rtc_virtio;
+		}
 	}
 
 	return 0;
+
+err_unregister_rtc_virtio:
+	while (i > 0)
+		platform_device_unregister(pdevs[--i]);
+	platform_device_unregister(pdev2);
+err_unregister_tty:
+	platform_device_unregister(pdev1);
+
+	return ret;
 }
 
 arch_initcall(virt_platform_init);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH -next v2] m68k: virt: platform: fix missing platform_device_unregister() on error in virt_platform_init()
  2022-06-28  8:49 [PATCH -next v2] m68k: virt: platform: fix missing platform_device_unregister() on error in virt_platform_init() Yang Yingliang
@ 2022-06-28 10:45 ` Laurent Vivier
  2022-07-06  9:17 ` Geert Uytterhoeven
  1 sibling, 0 replies; 3+ messages in thread
From: Laurent Vivier @ 2022-06-28 10:45 UTC (permalink / raw)
  To: Yang Yingliang, linux-kernel, linux-m68k; +Cc: geert

Le 28/06/2022 à 10:49, Yang Yingliang a écrit :
> Add the missing platform_device_unregister() before return
> from virt_platform_init() in the error handling case.
> 
> Fixes: 05d51e42df06 ("m68k: Introduce a virtual m68k machine")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> v2:
>    change for loop to while at lable err_unregister_rtc_virtio.
> ---
>   arch/m68k/virt/platform.c | 58 ++++++++++++++++++++++-----------------
>   1 file changed, 33 insertions(+), 25 deletions(-)
> 
> diff --git a/arch/m68k/virt/platform.c b/arch/m68k/virt/platform.c
> index cb820f19a221..1560c4140ab9 100644
> --- a/arch/m68k/virt/platform.c
> +++ b/arch/m68k/virt/platform.c
> @@ -8,20 +8,15 @@
>   
>   #define VIRTIO_BUS_NB	128
>   
> -static int __init virt_virtio_init(unsigned int id)
> +static struct platform_device * __init virt_virtio_init(unsigned int id)
>   {
>   	const struct resource res[] = {
>   		DEFINE_RES_MEM(virt_bi_data.virtio.mmio + id * 0x200, 0x200),
>   		DEFINE_RES_IRQ(virt_bi_data.virtio.irq + id),
>   	};
> -	struct platform_device *pdev;
>   
> -	pdev = platform_device_register_simple("virtio-mmio", id,
> +	return platform_device_register_simple("virtio-mmio", id,
>   					       res, ARRAY_SIZE(res));
> -	if (IS_ERR(pdev))
> -		return PTR_ERR(pdev);
> -
> -	return 0;
>   }
>   
>   static int __init virt_platform_init(void)
> @@ -35,8 +30,10 @@ static int __init virt_platform_init(void)
>   		DEFINE_RES_MEM(virt_bi_data.rtc.mmio + 0x1000, 0x1000),
>   		DEFINE_RES_IRQ(virt_bi_data.rtc.irq + 1),
>   	};
> -	struct platform_device *pdev;
> +	struct platform_device *pdev1, *pdev2;
> +	struct platform_device *pdevs[VIRTIO_BUS_NB];
>   	unsigned int i;
> +	int ret = 0;
>   
>   	if (!MACH_IS_VIRT)
>   		return -ENODEV;
> @@ -44,29 +41,40 @@ static int __init virt_platform_init(void)
>   	/* We need this to have DMA'able memory provided to goldfish-tty */
>   	min_low_pfn = 0;
>   
> -	pdev = platform_device_register_simple("goldfish_tty",
> -					       PLATFORM_DEVID_NONE,
> -					       goldfish_tty_res,
> -					       ARRAY_SIZE(goldfish_tty_res));
> -	if (IS_ERR(pdev))
> -		return PTR_ERR(pdev);
> +	pdev1 = platform_device_register_simple("goldfish_tty",
> +						PLATFORM_DEVID_NONE,
> +						goldfish_tty_res,
> +						ARRAY_SIZE(goldfish_tty_res));
> +	if (IS_ERR(pdev1))
> +		return PTR_ERR(pdev1);
>   
> -	pdev = platform_device_register_simple("goldfish_rtc",
> -					       PLATFORM_DEVID_NONE,
> -					       goldfish_rtc_res,
> -					       ARRAY_SIZE(goldfish_rtc_res));
> -	if (IS_ERR(pdev))
> -		return PTR_ERR(pdev);
> +	pdev2 = platform_device_register_simple("goldfish_rtc",
> +						PLATFORM_DEVID_NONE,
> +						goldfish_rtc_res,
> +						ARRAY_SIZE(goldfish_rtc_res));
> +	if (IS_ERR(pdev2)) {
> +		ret = PTR_ERR(pdev2);
> +		goto err_unregister_tty;
> +	}
>   
>   	for (i = 0; i < VIRTIO_BUS_NB; i++) {
> -		int err;
> -
> -		err = virt_virtio_init(i);
> -		if (err)
> -			return err;
> +		pdevs[i] = virt_virtio_init(i);
> +		if (IS_ERR(pdevs[i])) {
> +			ret = PTR_ERR(pdevs[i]);
> +			goto err_unregister_rtc_virtio;
> +		}
>   	}
>   
>   	return 0;
> +
> +err_unregister_rtc_virtio:
> +	while (i > 0)
> +		platform_device_unregister(pdevs[--i]);
> +	platform_device_unregister(pdev2);
> +err_unregister_tty:
> +	platform_device_unregister(pdev1);
> +
> +	return ret;
>   }
>   
>   arch_initcall(virt_platform_init);

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH -next v2] m68k: virt: platform: fix missing platform_device_unregister() on error in virt_platform_init()
  2022-06-28  8:49 [PATCH -next v2] m68k: virt: platform: fix missing platform_device_unregister() on error in virt_platform_init() Yang Yingliang
  2022-06-28 10:45 ` Laurent Vivier
@ 2022-07-06  9:17 ` Geert Uytterhoeven
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2022-07-06  9:17 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: Linux Kernel Mailing List, linux-m68k, Laurent Vivier

On Tue, Jun 28, 2022 at 10:39 AM Yang Yingliang
<yangyingliang@huawei.com> wrote:
> Add the missing platform_device_unregister() before return
> from virt_platform_init() in the error handling case.
>
> Fixes: 05d51e42df06 ("m68k: Introduce a virtual m68k machine")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> v2:
>   change for loop to while at lable err_unregister_rtc_virtio.

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
i.e. will queue in the m68k for-v5.20 branch.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-06  9:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-28  8:49 [PATCH -next v2] m68k: virt: platform: fix missing platform_device_unregister() on error in virt_platform_init() Yang Yingliang
2022-06-28 10:45 ` Laurent Vivier
2022-07-06  9:17 ` Geert Uytterhoeven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.