* [PATCH] iio: adc: exynos5_adc: fix compilation warnings
@ 2013-03-06 4:11 Naveen Krishna Chatradhi
2013-03-06 8:44 ` Lars-Peter Clausen
0 siblings, 1 reply; 4+ messages in thread
From: Naveen Krishna Chatradhi @ 2013-03-06 4:11 UTC (permalink / raw)
To: linux-iio
Cc: linux-kernel, linux-samsung-soc, gregkh, naveenkrishna.ch, lars,
dan.carpenter
From: Naveen Krishna Ch <ch.naveen@samsung.com>
Fixes the compilation warnings and potential NULL pointer
dereferencing pointed out by "Dan Carpenter".
Signed-off-by: Naveen Krishna Ch <ch.naveen@samsung.com>
---
drivers/iio/adc/exynos_adc.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index ed6fdd7..67d07aa 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -92,7 +92,7 @@ struct exynos_adc {
struct completion completion;
u32 value;
- unsigned int version;
+ unsigned int version;
};
static const struct of_device_id exynos_adc_match[] = {
@@ -102,12 +102,15 @@ static const struct of_device_id exynos_adc_match[] = {
};
MODULE_DEVICE_TABLE(of, exynos_adc_match);
-static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
+static inline int exynos_adc_get_version(struct platform_device *pdev)
{
const struct of_device_id *match;
match = of_match_node(exynos_adc_match, pdev->dev.of_node);
- return (unsigned int)match->data;
+ if (!match)
+ return -ENODEV;
+
+ return (int)match->data;
}
static int exynos_read_raw(struct iio_dev *indio_dev,
@@ -117,7 +120,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
long mask)
{
struct exynos_adc *info = iio_priv(indio_dev);
- unsigned long timeout;
+ int timeout;
u32 con1, con2;
if (mask != IIO_CHAN_INFO_RAW)
@@ -255,7 +258,7 @@ static int exynos_adc_probe(struct platform_device *pdev)
struct iio_dev *indio_dev = NULL;
struct resource *mem;
int ret = -ENODEV;
- int irq;
+ int irq, version;
if (!np)
return ret;
@@ -268,6 +271,15 @@ static int exynos_adc_probe(struct platform_device *pdev)
info = iio_priv(indio_dev);
+ version = exynos_adc_get_version(pdev);
+ if (version < 0) {
+ dev_err(&pdev->dev, "no matching of_node, err = %d\n", version);
+ ret = version;
+ goto err_iio;
+ }
+
+ info->version = version;
+
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
info->regs = devm_request_and_ioremap(&pdev->dev, mem);
@@ -311,8 +323,6 @@ static int exynos_adc_probe(struct platform_device *pdev)
goto err_irq;
}
- info->version = exynos_adc_get_version(pdev);
-
platform_set_drvdata(pdev, indio_dev);
indio_dev->name = dev_name(&pdev->dev);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: adc: exynos5_adc: fix compilation warnings
2013-03-06 4:11 [PATCH] iio: adc: exynos5_adc: fix compilation warnings Naveen Krishna Chatradhi
@ 2013-03-06 8:44 ` Lars-Peter Clausen
2013-03-06 9:26 ` Dan Carpenter
2013-03-06 13:15 ` Naveen Krishna Ch
0 siblings, 2 replies; 4+ messages in thread
From: Lars-Peter Clausen @ 2013-03-06 8:44 UTC (permalink / raw)
To: Naveen Krishna Chatradhi
Cc: linux-iio, linux-kernel, linux-samsung-soc, gregkh,
naveenkrishna.ch, dan.carpenter
On 03/06/2013 05:11 AM, Naveen Krishna Chatradhi wrote:
> From: Naveen Krishna Ch <ch.naveen@samsung.com>
>
> Fixes the compilation warnings and potential NULL pointer
> dereferencing pointed out by "Dan Carpenter".
>
I'd say that's a rather un-potential NULL pointer dereferencing, but if it
makes the static checkers happy, why not. Since the same match table is used to
match the device, probe won't be called unless there is a match, so
of_match_node() will never return NULL in this case.
> Signed-off-by: Naveen Krishna Ch <ch.naveen@samsung.com>
> ---
> drivers/iio/adc/exynos_adc.c | 24 +++++++++++++++++-------
> 1 file changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index ed6fdd7..67d07aa 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -92,7 +92,7 @@ struct exynos_adc {
> struct completion completion;
>
> u32 value;
> - unsigned int version;
> + unsigned int version;
> };
>
> static const struct of_device_id exynos_adc_match[] = {
> @@ -102,12 +102,15 @@ static const struct of_device_id exynos_adc_match[] = {
> };
> MODULE_DEVICE_TABLE(of, exynos_adc_match);
>
> -static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
> +static inline int exynos_adc_get_version(struct platform_device *pdev)
> {
> const struct of_device_id *match;
>
> match = of_match_node(exynos_adc_match, pdev->dev.of_node);
> - return (unsigned int)match->data;
> + if (!match)
> + return -ENODEV;
> +
> + return (int)match->data;
> }
>
> static int exynos_read_raw(struct iio_dev *indio_dev,
> @@ -117,7 +120,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
> long mask)
> {
> struct exynos_adc *info = iio_priv(indio_dev);
> - unsigned long timeout;
> + int timeout;
> u32 con1, con2;
>
> if (mask != IIO_CHAN_INFO_RAW)
> @@ -255,7 +258,7 @@ static int exynos_adc_probe(struct platform_device *pdev)
> struct iio_dev *indio_dev = NULL;
> struct resource *mem;
> int ret = -ENODEV;
> - int irq;
> + int irq, version;
>
> if (!np)
> return ret;
> @@ -268,6 +271,15 @@ static int exynos_adc_probe(struct platform_device *pdev)
>
> info = iio_priv(indio_dev);
>
> + version = exynos_adc_get_version(pdev);
> + if (version < 0) {
> + dev_err(&pdev->dev, "no matching of_node, err = %d\n", version);
> + ret = version;
> + goto err_iio;
> + }
> +
> + info->version = version;
> +
> mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>
> info->regs = devm_request_and_ioremap(&pdev->dev, mem);
> @@ -311,8 +323,6 @@ static int exynos_adc_probe(struct platform_device *pdev)
> goto err_irq;
> }
>
> - info->version = exynos_adc_get_version(pdev);
> -
> platform_set_drvdata(pdev, indio_dev);
>
> indio_dev->name = dev_name(&pdev->dev);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: adc: exynos5_adc: fix compilation warnings
2013-03-06 8:44 ` Lars-Peter Clausen
@ 2013-03-06 9:26 ` Dan Carpenter
2013-03-06 13:15 ` Naveen Krishna Ch
1 sibling, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2013-03-06 9:26 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: Naveen Krishna Chatradhi, linux-iio, linux-kernel,
linux-samsung-soc, gregkh, naveenkrishna.ch, kbuild
On Wed, Mar 06, 2013 at 09:44:47AM +0100, Lars-Peter Clausen wrote:
> On 03/06/2013 05:11 AM, Naveen Krishna Chatradhi wrote:
> > From: Naveen Krishna Ch <ch.naveen@samsung.com>
> >
> > Fixes the compilation warnings and potential NULL pointer
> > dereferencing pointed out by "Dan Carpenter".
> >
>
> I'd say that's a rather un-potential NULL pointer dereferencing, but if it
> makes the static checkers happy, why not. Since the same match table is used to
> match the device, probe won't be called unless there is a match, so
> of_match_node() will never return NULL in this case.
>
Actually the reason Smatch complains is because this was built with
CONFIG_OF=n. Probably it should depend on that in the Kconfig file?
The static checker warnings are a semi automatic thing and we only
send the one email and then mark them as looked at. It's not worth
silencing false positives unless it makes the code easier to
audit.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: adc: exynos5_adc: fix compilation warnings
2013-03-06 8:44 ` Lars-Peter Clausen
2013-03-06 9:26 ` Dan Carpenter
@ 2013-03-06 13:15 ` Naveen Krishna Ch
1 sibling, 0 replies; 4+ messages in thread
From: Naveen Krishna Ch @ 2013-03-06 13:15 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: Naveen Krishna Chatradhi, linux-iio, linux-kernel,
linux-samsung-soc@vger.kernel.org, gregkh, dan.carpenter
On 6 March 2013 17:44, Lars-Peter Clausen <lars@metafoo.de> wrote:
> On 03/06/2013 05:11 AM, Naveen Krishna Chatradhi wrote:
>> From: Naveen Krishna Ch <ch.naveen@samsung.com>
>>
>> Fixes the compilation warnings and potential NULL pointer
>> dereferencing pointed out by "Dan Carpenter".
>>
>
> I'd say that's a rather un-potential NULL pointer dereferencing, but if it
> makes the static checkers happy, why not. Since the same match table is used to
> match the device, probe won't be called unless there is a match, so
> of_match_node() will never return NULL in this case.
Right, i was thinking how it is such a potential error.
Anyway, Dan's suggestion of Kconfig change holds very good.
I will submit v2, with the appropriate changes.
>
>> Signed-off-by: Naveen Krishna Ch <ch.naveen@samsung.com>
>> ---
>> drivers/iio/adc/exynos_adc.c | 24 +++++++++++++++++-------
>> 1 file changed, 17 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
>> index ed6fdd7..67d07aa 100644
>> --- a/drivers/iio/adc/exynos_adc.c
>> +++ b/drivers/iio/adc/exynos_adc.c
>> @@ -92,7 +92,7 @@ struct exynos_adc {
>> struct completion completion;
>>
>> u32 value;
>> - unsigned int version;
>> + unsigned int version;
>> };
>>
>> static const struct of_device_id exynos_adc_match[] = {
>> @@ -102,12 +102,15 @@ static const struct of_device_id exynos_adc_match[] = {
>> };
>> MODULE_DEVICE_TABLE(of, exynos_adc_match);
>>
>> -static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
>> +static inline int exynos_adc_get_version(struct platform_device *pdev)
>> {
>> const struct of_device_id *match;
>>
>> match = of_match_node(exynos_adc_match, pdev->dev.of_node);
>> - return (unsigned int)match->data;
>> + if (!match)
>> + return -ENODEV;
>> +
>> + return (int)match->data;
>> }
>>
>> static int exynos_read_raw(struct iio_dev *indio_dev,
>> @@ -117,7 +120,7 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>> long mask)
>> {
>> struct exynos_adc *info = iio_priv(indio_dev);
>> - unsigned long timeout;
>> + int timeout;
>> u32 con1, con2;
>>
>> if (mask != IIO_CHAN_INFO_RAW)
>> @@ -255,7 +258,7 @@ static int exynos_adc_probe(struct platform_device *pdev)
>> struct iio_dev *indio_dev = NULL;
>> struct resource *mem;
>> int ret = -ENODEV;
>> - int irq;
>> + int irq, version;
>>
>> if (!np)
>> return ret;
>> @@ -268,6 +271,15 @@ static int exynos_adc_probe(struct platform_device *pdev)
>>
>> info = iio_priv(indio_dev);
>>
>> + version = exynos_adc_get_version(pdev);
>> + if (version < 0) {
>> + dev_err(&pdev->dev, "no matching of_node, err = %d\n", version);
>> + ret = version;
>> + goto err_iio;
>> + }
>> +
>> + info->version = version;
>> +
>> mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>
>> info->regs = devm_request_and_ioremap(&pdev->dev, mem);
>> @@ -311,8 +323,6 @@ static int exynos_adc_probe(struct platform_device *pdev)
>> goto err_irq;
>> }
>>
>> - info->version = exynos_adc_get_version(pdev);
>> -
>> platform_set_drvdata(pdev, indio_dev);
>>
>> indio_dev->name = dev_name(&pdev->dev);
>
--
Shine bright,
(: Nav :)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-03-06 13:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-06 4:11 [PATCH] iio: adc: exynos5_adc: fix compilation warnings Naveen Krishna Chatradhi
2013-03-06 8:44 ` Lars-Peter Clausen
2013-03-06 9:26 ` Dan Carpenter
2013-03-06 13:15 ` Naveen Krishna Ch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox