Re: [patch] [media] stv090x: handle allocation failures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday 07 February 2011 17:56:50 Dan Carpenter wrote:
> kmalloc() can fail so check whether state->internal is NULL.
> append_internal() can return NULL on allocation failures so check that.
> Also if we hit the error condition later in the function then there is
> a memory leak and we need to call remove_dev() to fix it.
> ...

Thanks for the patch. See my comment below.

> --- a/drivers/media/dvb/frontends/stv090x.c
> +++ b/drivers/media/dvb/frontends/stv090x.c
> @@ -4783,7 +4783,13 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
>  	} else {
>  		state->internal = kmalloc(sizeof(struct stv090x_internal),
>  					  GFP_KERNEL);
> +		if (!state->internal)
> +			goto error;
>  		temp_int = append_internal(state->internal);
> +		if (!temp_int) {
> +			kfree(state->internal);
> +			goto error;
> +		}
>  		state->internal->num_used = 1;
>  		state->internal->mclk = 0;
>  		state->internal->dev_ver = 0;
> @@ -4796,7 +4802,7 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
>  
>  		if (stv090x_setup(&state->frontend) < 0) {
>  			dprintk(FE_ERROR, 1, "Error setting up device");
> -			goto error;
> +			goto err_remove;
>  		}
>  	}
>  
> @@ -4811,6 +4817,8 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
>  
>  	return &state->frontend;
>  
> +err_remove:
> +	remove_dev(state->internal);

AFAICS
        kfree(state->internal);
must be added here, as we allocated state->internal, state and temp_int.

>  error:
>  	kfree(state);
>  	return NULL;

CU
Oliver

-- 
----------------------------------------------------------------
VDR Remote Plugin 0.4.0: http://www.escape-edv.de/endriss/vdr/
4 MByte Mod: http://www.escape-edv.de/endriss/dvb-mem-mod/
Full-TS Mod: http://www.escape-edv.de/endriss/dvb-full-ts-mod/
----------------------------------------------------------------
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux