Re: [PATCH] platform/x86: simatic-ipc: fix platform device leak on registration failure

From: Dan Carpenter

Date: Tue Sep 22 2026 - 06:34:54 EST


On Tue, Sep 22, 2026 at 04:13:17PM +0800, Guangshuo Li wrote:
>
> Would it make sense to share the cleanup path and rely on
> platform_device_unregister() handling NULL/ERR_PTR, like this?
>
> +static void unregister_platform_devices(void)
> +{
> + platform_device_unregister(ipc_wdt_platform_device);
> + platform_device_unregister(ipc_led_platform_device);
> + platform_device_unregister(ipc_batt_platform_device);
> +}

Having one magical cleanup function is the most bug prone way to
write cleanup. Use an unwind ladder.

https://staticthinking.wordpress.com/2022/04/28/free-the-last-thing-style/

regards,
dan carpenter