2020-10-13 09:39:12

by Fabien Parent

[permalink] [raw]
Subject: [PATCH] iio: adc: mediatek: fix unset field

dev_comp field is used in a couple of places but it is never set. This
results in kernel oops when dereferencing a NULL pointer. Set the
`dev_comp` field correctly in the probe function.

Fixes: 6d97024dce23 ("iio: adc: mediatek: mt6577-auxadc, add mt6765 support")

Signed-off-by: Fabien Parent <[email protected]>
---
drivers/iio/adc/mt6577_auxadc.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c
index ac415cb089cd..7bd48377cd79 100644
--- a/drivers/iio/adc/mt6577_auxadc.c
+++ b/drivers/iio/adc/mt6577_auxadc.c
@@ -276,6 +276,8 @@ static int mt6577_auxadc_probe(struct platform_device *pdev)
goto err_disable_clk;
}

+ adc_dev->dev_comp = of_device_get_match_data(&pdev->dev);
+
mutex_init(&adc_dev->lock);

mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC,
--
2.28.0


2020-10-13 17:47:11

by Matthias Brugger

[permalink] [raw]
Subject: Re: [PATCH] iio: adc: mediatek: fix unset field



On 12/10/2020 21:46, Fabien Parent wrote:
> dev_comp field is used in a couple of places but it is never set. This
> results in kernel oops when dereferencing a NULL pointer. Set the
> `dev_comp` field correctly in the probe function.
>
> Fixes: 6d97024dce23 ("iio: adc: mediatek: mt6577-auxadc, add mt6765 support")
>
> Signed-off-by: Fabien Parent <[email protected]>

Ouch.

Reviewed-by: Matthias Brugger <[email protected]>

> ---
> drivers/iio/adc/mt6577_auxadc.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c
> index ac415cb089cd..7bd48377cd79 100644
> --- a/drivers/iio/adc/mt6577_auxadc.c
> +++ b/drivers/iio/adc/mt6577_auxadc.c
> @@ -276,6 +276,8 @@ static int mt6577_auxadc_probe(struct platform_device *pdev)
> goto err_disable_clk;
> }
>
> + adc_dev->dev_comp = of_device_get_match_data(&pdev->dev);
> +
> mutex_init(&adc_dev->lock);
>
> mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC,
>

2020-10-18 10:24:36

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH] iio: adc: mediatek: fix unset field

On Tue, 13 Oct 2020 17:37:12 +0200
Matthias Brugger <[email protected]> wrote:

> On 12/10/2020 21:46, Fabien Parent wrote:
> > dev_comp field is used in a couple of places but it is never set. This
> > results in kernel oops when dereferencing a NULL pointer. Set the
> > `dev_comp` field correctly in the probe function.
> >
> > Fixes: 6d97024dce23 ("iio: adc: mediatek: mt6577-auxadc, add mt6765 support")
> >
> > Signed-off-by: Fabien Parent <[email protected]>
>
> Ouch.
>
> Reviewed-by: Matthias Brugger <[email protected]>
>
> > ---
> > drivers/iio/adc/mt6577_auxadc.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c
> > index ac415cb089cd..7bd48377cd79 100644
> > --- a/drivers/iio/adc/mt6577_auxadc.c
> > +++ b/drivers/iio/adc/mt6577_auxadc.c
> > @@ -276,6 +276,8 @@ static int mt6577_auxadc_probe(struct platform_device *pdev)
> > goto err_disable_clk;
> > }
> >
> > + adc_dev->dev_comp = of_device_get_match_data(&pdev->dev);
> > +

Could we switch this to device_get_match_data(&pdev->dev)?

Whilst is unlikely this driver will used in a platform using ACPI, there
is nothing inside the driver itself preventing this (which is good as no
reason to do so!) My main motivation for this is to reduce the chances
of cut and paste of the of_* functions in future driver.

Also switch the headers to linux/property.h and linux/mod_devicetable.h
to more tightly reflect what we are using in the driver.

Thanks,

Jonathan

> > mutex_init(&adc_dev->lock);
> >
> > mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC,
> >

2020-10-18 17:18:35

by Fabien Parent

[permalink] [raw]
Subject: Re: [PATCH] iio: adc: mediatek: fix unset field

Hi Jonathan,

On Sun, Oct 18, 2020 at 12:07 PM Jonathan Cameron <[email protected]> wrote:
>
> On Tue, 13 Oct 2020 17:37:12 +0200
> Matthias Brugger <[email protected]> wrote:
>
> > On 12/10/2020 21:46, Fabien Parent wrote:
> > > dev_comp field is used in a couple of places but it is never set. This
> > > results in kernel oops when dereferencing a NULL pointer. Set the
> > > `dev_comp` field correctly in the probe function.
> > >
> > > Fixes: 6d97024dce23 ("iio: adc: mediatek: mt6577-auxadc, add mt6765 support")
> > >
> > > Signed-off-by: Fabien Parent <[email protected]>
> >
> > Ouch.
> >
> > Reviewed-by: Matthias Brugger <[email protected]>
> >
> > > ---
> > > drivers/iio/adc/mt6577_auxadc.c | 2 ++
> > > 1 file changed, 2 insertions(+)
> > >
> > > diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c
> > > index ac415cb089cd..7bd48377cd79 100644
> > > --- a/drivers/iio/adc/mt6577_auxadc.c
> > > +++ b/drivers/iio/adc/mt6577_auxadc.c
> > > @@ -276,6 +276,8 @@ static int mt6577_auxadc_probe(struct platform_device *pdev)
> > > goto err_disable_clk;
> > > }
> > >
> > > + adc_dev->dev_comp = of_device_get_match_data(&pdev->dev);
> > > +
>
> Could we switch this to device_get_match_data(&pdev->dev)?
>
> Whilst is unlikely this driver will used in a platform using ACPI, there
> is nothing inside the driver itself preventing this (which is good as no
> reason to do so!) My main motivation for this is to reduce the chances
> of cut and paste of the of_* functions in future driver.
>
> Also switch the headers to linux/property.h and linux/mod_devicetable.h
> to more tightly reflect what we are using in the driver.

I applied these changes in v2.

>
> Thanks,
>
> Jonathan
>
> > > mutex_init(&adc_dev->lock);
> > >
> > > mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC,
> > >
>