[PATCH] char: xilinx_hwicap: unregister class on init errors

Pandey, Radhey Shyam radheys at amd.com
Tue Jun 23 05:26:09 PDT 2026


> hwicap_module_init() registers icap_class before reserving the
> character-device region and registering the platform driver.  If either
> of those later steps fails, the init path must undo the successful class
> registration before returning an error.
> 
> Route the chrdev registration failure through a class unwind label, and
> let the platform-driver registration failure fall through the existing
> chrdev unwind before unregistering the class.  The normal module exit path
> is unchanged.
> 
> This issue was identified during our ongoing static-analysis research while
> reviewing kernel code.
> 
> Fixes: ef141a0bb0dc ("[POWERPC] Xilinx: hwicap driver")
> Co-developed-by: Ijae Kim <ae878000 at gmail.com>
> Signed-off-by: Ijae Kim <ae878000 at gmail.com>
> Signed-off-by: Myeonghun Pak <mhun512 at gmail.com>
> 
> ---

Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey at amd.com>
Thanks!

>   drivers/char/xilinx_hwicap/xilinx_hwicap.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
> index 34a345dc5e..9bb5fa642f 100644
> --- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
> +++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
> @@ -760,7 +760,7 @@ static int __init hwicap_module_init(void)
>   					HWICAP_DEVICES,
>   					DRIVER_NAME);
>   	if (retval < 0)
> -		return retval;
> +		goto failed_class;
>   
>   	retval = platform_driver_register(&hwicap_platform_driver);
>   	if (retval)
> @@ -771,6 +771,9 @@ static int __init hwicap_module_init(void)
>    failed:
>   	unregister_chrdev_region(devt, HWICAP_DEVICES);
>   
> + failed_class:
> +	class_unregister(&icap_class);
> +
>   	return retval;
>   }
>   




More information about the linux-arm-kernel mailing list