Re: [PATCH] i2c: busses: i2c-pxa.c: Fix for possible null pointer dereferenc

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

 



On Tue, Jun 03, 2014 at 11:30:34PM +0200, Rickard Strandqvist wrote:
> Fix for possible null pointer dereferenc, and there is a risk
> for memory leak in when something unexpected happens and the
> function returns.
> 
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@xxxxxxxxxxxxxxxxxx>
> ---
>  drivers/i2c/busses/i2c-pxa.c |   19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
> index bbe6dfb..948a3c7 100644
> --- a/drivers/i2c/busses/i2c-pxa.c
> +++ b/drivers/i2c/busses/i2c-pxa.c
> @@ -1142,10 +1142,8 @@ static int i2c_pxa_probe(struct platform_device *dev)
>  	int ret, irq;
>  
>  	i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL);
> -	if (!i2c) {
> -		ret = -ENOMEM;
> -		goto emalloc;
> -	}
> +	if (!i2c)
> +		return -ENOMEM;
>  
>  	/* Default adapter num to device id; i2c_pxa_probe_dt can override. */
>  	i2c->adap.nr = dev->id;
> @@ -1154,11 +1152,16 @@ static int i2c_pxa_probe(struct platform_device *dev)
>  	if (ret > 0)
>  		ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type);
>  	if (ret < 0)
> -		goto eclk;
> +		goto emalloc;
>  
>  	res = platform_get_resource(dev, IORESOURCE_MEM, 0);
> +	if (res == NULL) {
> +		ret = -ENODEV;
> +		goto emalloc;
> +	}
> +
>  	irq = platform_get_irq(dev, 0);
> -	if (res == NULL || irq < 0) {
> +	if (irq < 0) {
>  		ret = -ENODEV;
>  		goto eclk;

Nope, those should be emalloc as well since the region was not requested
here. May I ask you to just convert this driver to managed devices (devm_*
functions)? They are made to exactly avoid this hazzle and cleanup the
driver.

Thanks,

   Wolfram

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux