Skip to content

Commit

Permalink
m68k: virt: Fix missing platform_device_unregister() on error in virt…
Browse files Browse the repository at this point in the history
…_platform_init()

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

Fixes: 05d51e4 ("m68k: Introduce a virtual m68k machine")
Reported-by: Hulk Robot <[email protected]>
Signed-off-by: Yang Yingliang <[email protected]>
Reviewed-by: Laurent Vivier <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Geert Uytterhoeven <[email protected]>
  • Loading branch information
Yang Yingliang authored and geertu committed Jul 6, 2022
1 parent a1ee38a commit 566a2d6
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions arch/m68k/virt/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -35,38 +30,51 @@ 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;

/* 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);

0 comments on commit 566a2d6

Please sign in to comment.