diff mbox series

iio: adc: intel_mrfld_adc: Allocating too much data in probe()

Message ID 20191119062124.kgwg7ujxe6k2ft3o@kili.mountain (mailing list archive)
State New, archived
Headers show
Series iio: adc: intel_mrfld_adc: Allocating too much data in probe() | expand

Commit Message

Dan Carpenter Nov. 19, 2019, 6:21 a.m. UTC
This probe function is passing the wrong size to devm_iio_device_alloc().
It is supposed to be the size of the private data.  Fortunately,
sizeof(*indio_dev) is larger than sizeof(struct mrfld_adc) so it doesn't
cause a runtime problem.

Fixes: a7118662734a ("iio: adc: intel_mrfld_adc: Add Basin Cove ADC driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/iio/adc/intel_mrfld_adc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andy Shevchenko Nov. 19, 2019, 10:23 a.m. UTC | #1
On Tue, Nov 19, 2019 at 09:21:24AM +0300, Dan Carpenter wrote:
> This probe function is passing the wrong size to devm_iio_device_alloc().
> It is supposed to be the size of the private data.  Fortunately,
> sizeof(*indio_dev) is larger than sizeof(struct mrfld_adc) so it doesn't
> cause a runtime problem.
> 

Ah, indeed, thanks for fixing this!
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Fixes: a7118662734a ("iio: adc: intel_mrfld_adc: Add Basin Cove ADC driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/iio/adc/intel_mrfld_adc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/intel_mrfld_adc.c b/drivers/iio/adc/intel_mrfld_adc.c
> index 67d096f8180d..c35a1beb817c 100644
> --- a/drivers/iio/adc/intel_mrfld_adc.c
> +++ b/drivers/iio/adc/intel_mrfld_adc.c
> @@ -185,7 +185,7 @@ static int mrfld_adc_probe(struct platform_device *pdev)
>  	int irq;
>  	int ret;
>  
> -	indio_dev = devm_iio_device_alloc(dev, sizeof(*indio_dev));
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(struct mrfld_adc));

Many drivers use sizeof(*adc) form, but I'm okay with either.

>  	if (!indio_dev)
>  		return -ENOMEM;
>  
> -- 
> 2.11.0
>
Jonathan Cameron Nov. 23, 2019, 2:42 p.m. UTC | #2
On Tue, 19 Nov 2019 12:23:32 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Tue, Nov 19, 2019 at 09:21:24AM +0300, Dan Carpenter wrote:
> > This probe function is passing the wrong size to devm_iio_device_alloc().
> > It is supposed to be the size of the private data.  Fortunately,
> > sizeof(*indio_dev) is larger than sizeof(struct mrfld_adc) so it doesn't
> > cause a runtime problem.
> >   
> 
> Ah, indeed, thanks for fixing this!
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Applied to the fixes-togreg branch of iio.git.

I'll wait until after the merge window now to send a pull request for this
one so will be rc2ish before it's in.

Thanks,

Jonathan

> 
> > Fixes: a7118662734a ("iio: adc: intel_mrfld_adc: Add Basin Cove ADC driver")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> >  drivers/iio/adc/intel_mrfld_adc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/adc/intel_mrfld_adc.c b/drivers/iio/adc/intel_mrfld_adc.c
> > index 67d096f8180d..c35a1beb817c 100644
> > --- a/drivers/iio/adc/intel_mrfld_adc.c
> > +++ b/drivers/iio/adc/intel_mrfld_adc.c
> > @@ -185,7 +185,7 @@ static int mrfld_adc_probe(struct platform_device *pdev)
> >  	int irq;
> >  	int ret;
> >  
> > -	indio_dev = devm_iio_device_alloc(dev, sizeof(*indio_dev));
> > +	indio_dev = devm_iio_device_alloc(dev, sizeof(struct mrfld_adc));  
> 
> Many drivers use sizeof(*adc) form, but I'm okay with either.
> 
> >  	if (!indio_dev)
> >  		return -ENOMEM;
> >  
> > -- 
> > 2.11.0
> >   
>
Andy Shevchenko Nov. 25, 2019, 9:33 a.m. UTC | #3
On Sat, Nov 23, 2019 at 02:42:06PM +0000, Jonathan Cameron wrote:
> On Tue, 19 Nov 2019 12:23:32 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> > On Tue, Nov 19, 2019 at 09:21:24AM +0300, Dan Carpenter wrote:
> > > This probe function is passing the wrong size to devm_iio_device_alloc().
> > > It is supposed to be the size of the private data.  Fortunately,
> > > sizeof(*indio_dev) is larger than sizeof(struct mrfld_adc) so it doesn't
> > > cause a runtime problem.
> > >   
> > 
> > Ah, indeed, thanks for fixing this!
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Applied to the fixes-togreg branch of iio.git.

Thanks!

> I'll wait until after the merge window now to send a pull request for this
> one so will be rc2ish before it's in.

Sure, as pointed out by Dan it seems to work due to size of wrong structure is
bigger than needed, thus it's not a critical fix.
diff mbox series

Patch

diff --git a/drivers/iio/adc/intel_mrfld_adc.c b/drivers/iio/adc/intel_mrfld_adc.c
index 67d096f8180d..c35a1beb817c 100644
--- a/drivers/iio/adc/intel_mrfld_adc.c
+++ b/drivers/iio/adc/intel_mrfld_adc.c
@@ -185,7 +185,7 @@  static int mrfld_adc_probe(struct platform_device *pdev)
 	int irq;
 	int ret;
 
-	indio_dev = devm_iio_device_alloc(dev, sizeof(*indio_dev));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(struct mrfld_adc));
 	if (!indio_dev)
 		return -ENOMEM;