[PATCH 06/10] Input: sparcspkr - use cleanup facility for device_node

Al Viro viro at zeniv.linux.org.uk
Thu Oct 10 14:43:48 PDT 2024


On Thu, Oct 10, 2024 at 11:25:56PM +0200, Javier Carrasco wrote:
> 
> diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
> index 20020cbc0752..bb1c732c8f95 100644
> --- a/drivers/input/misc/sparcspkr.c
> +++ b/drivers/input/misc/sparcspkr.c
> @@ -188,7 +188,6 @@ static int bbc_beep_probe(struct platform_device *op)
>  {
>  	struct sparcspkr_state *state;
>  	struct bbc_beep_info *info;
> -	struct device_node *dp;
>  	int err = -ENOMEM;
>  
>  	state = kzalloc(sizeof(*state), GFP_KERNEL);
> @@ -199,14 +198,13 @@ static int bbc_beep_probe(struct platform_device *op)
>  	state->event = bbc_spkr_event;
>  	spin_lock_init(&state->lock);
>  
> -	dp = of_find_node_by_path("/");
>  	err = -ENODEV;
> +	struct device_node *dp __free(device_node) = of_find_node_by_path("/");
>  	if (!dp)
>  		goto out_free;

Sigh...  See that
        state = kzalloc(sizeof(*state), GFP_KERNEL);
	if (!state)
		goto out_err;
above?

IOW, this will quietly generate broken code if built with gcc (and refuse to
compile with clang).  Yeah, this one is trivially fixed (return -ENOMEM instead
of a goto), but...

__cleanup() can be useful, but it's really *not* safe for blind use; you
need to watch out for changed scopes (harmless in case of device_node)
and for gotos (broken here).



More information about the Linux-mediatek mailing list