linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] hwmon: axi-fan-control: fix uninitialized dereference of pointer res
@ 2020-02-11 16:20 Colin King
  2020-02-11 16:39 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2020-02-11 16:20 UTC (permalink / raw)
  To: Nuno Sá, Jean Delvare, Guenter Roeck, linux-hwmon
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently the resource pointer ret is uninitialized and it is
being dereferenced when printing out a debug message. Fix this
by fetching the resource and assigning pointer res.  It is
a moot point that we sanity check for a null res since a successful
call to devm_platform_ioremap_resource has already occurred so
in theory it should never be non-null.

Addresses-Coverity: ("Uninitialized pointer read")
Fixes: 690dd9ce04f6 ("hwmon: Support ADI Fan Control IP")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/hwmon/axi-fan-control.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/hwmon/axi-fan-control.c b/drivers/hwmon/axi-fan-control.c
index 8041ba7cc152..36e0d060510a 100644
--- a/drivers/hwmon/axi-fan-control.c
+++ b/drivers/hwmon/axi-fan-control.c
@@ -415,6 +415,9 @@ static int axi_fan_control_probe(struct platform_device *pdev)
 	if (!ctl->clk_rate)
 		return -EINVAL;
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
 	dev_dbg(&pdev->dev, "Re-mapped from 0x%08llX to %p\n",
 		(unsigned long long)res->start, ctl->base);
 
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] hwmon: axi-fan-control: fix uninitialized dereference of pointer res
  2020-02-11 16:20 [PATCH][next] hwmon: axi-fan-control: fix uninitialized dereference of pointer res Colin King
@ 2020-02-11 16:39 ` Guenter Roeck
  2020-02-11 16:41   ` Colin Ian King
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2020-02-11 16:39 UTC (permalink / raw)
  To: Colin King
  Cc: Nuno Sá, Jean Delvare, linux-hwmon, kernel-janitors, linux-kernel

On Tue, Feb 11, 2020 at 04:20:59PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently the resource pointer ret is uninitialized and it is
> being dereferenced when printing out a debug message. Fix this
> by fetching the resource and assigning pointer res.  It is
> a moot point that we sanity check for a null res since a successful
> call to devm_platform_ioremap_resource has already occurred so
> in theory it should never be non-null.
> 
> Addresses-Coverity: ("Uninitialized pointer read")
> Fixes: 690dd9ce04f6 ("hwmon: Support ADI Fan Control IP")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

This has already been fixed by removing the message (and the
then unused variable). The message was useless anyway since
it printed the remapped address with %p.

Guenter

> ---
>  drivers/hwmon/axi-fan-control.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/hwmon/axi-fan-control.c b/drivers/hwmon/axi-fan-control.c
> index 8041ba7cc152..36e0d060510a 100644
> --- a/drivers/hwmon/axi-fan-control.c
> +++ b/drivers/hwmon/axi-fan-control.c
> @@ -415,6 +415,9 @@ static int axi_fan_control_probe(struct platform_device *pdev)
>  	if (!ctl->clk_rate)
>  		return -EINVAL;
>  
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res)
> +		return -EINVAL;
>  	dev_dbg(&pdev->dev, "Re-mapped from 0x%08llX to %p\n",
>  		(unsigned long long)res->start, ctl->base);
>  
> -- 
> 2.25.0
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] hwmon: axi-fan-control: fix uninitialized dereference of pointer res
  2020-02-11 16:39 ` Guenter Roeck
@ 2020-02-11 16:41   ` Colin Ian King
  0 siblings, 0 replies; 3+ messages in thread
From: Colin Ian King @ 2020-02-11 16:41 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Nuno Sá, Jean Delvare, linux-hwmon, kernel-janitors, linux-kernel

On 11/02/2020 16:39, Guenter Roeck wrote:
> On Tue, Feb 11, 2020 at 04:20:59PM +0000, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Currently the resource pointer ret is uninitialized and it is
>> being dereferenced when printing out a debug message. Fix this
>> by fetching the resource and assigning pointer res.  It is
>> a moot point that we sanity check for a null res since a successful
>> call to devm_platform_ioremap_resource has already occurred so
>> in theory it should never be non-null.
>>
>> Addresses-Coverity: ("Uninitialized pointer read")
>> Fixes: 690dd9ce04f6 ("hwmon: Support ADI Fan Control IP")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> This has already been fixed by removing the message (and the
> then unused variable). The message was useless anyway since
> it printed the remapped address with %p.
> 
> Guenter

OK, thanks. My static anaylsis can't keep up!
> 
>> ---
>>  drivers/hwmon/axi-fan-control.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/hwmon/axi-fan-control.c b/drivers/hwmon/axi-fan-control.c
>> index 8041ba7cc152..36e0d060510a 100644
>> --- a/drivers/hwmon/axi-fan-control.c
>> +++ b/drivers/hwmon/axi-fan-control.c
>> @@ -415,6 +415,9 @@ static int axi_fan_control_probe(struct platform_device *pdev)
>>  	if (!ctl->clk_rate)
>>  		return -EINVAL;
>>  
>> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> +	if (!res)
>> +		return -EINVAL;
>>  	dev_dbg(&pdev->dev, "Re-mapped from 0x%08llX to %p\n",
>>  		(unsigned long long)res->start, ctl->base);
>>  
>> -- 
>> 2.25.0
>>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-11 16:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-11 16:20 [PATCH][next] hwmon: axi-fan-control: fix uninitialized dereference of pointer res Colin King
2020-02-11 16:39 ` Guenter Roeck
2020-02-11 16:41   ` Colin Ian King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).