linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH]  hwmon: (dme1737): Add missing null check on return from platform_get_resource
@ 2021-04-06 18:54 Colin King
  2021-04-09 23:08 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2021-04-06 18:54 UTC (permalink / raw)
  To: Juerg Haefliger, Jean Delvare, Guenter Roeck, Mark M . Hoffman,
	linux-hwmon
  Cc: kernel-janitors, linux-kernel

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

The call to platform_get_resource can potentially return a NULL pointer
on failure, so add this check and return -EINVAL if it fails.

Addresses-Coverity: ("Dereference null return")
Fixes: e95c237d78c0 ("hwmon: (dme1737) Add sch311x support")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/hwmon/dme1737.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index c1e4cfb40c3d..a2157872e126 100644
--- a/drivers/hwmon/dme1737.c
+++ b/drivers/hwmon/dme1737.c
@@ -2633,6 +2633,8 @@ static int dme1737_isa_probe(struct platform_device *pdev)
 	int err;
 
 	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
+	if (!res)
+		return -EINVAL;
 	if (!devm_request_region(dev, res->start, DME1737_EXTENT, "dme1737")) {
 		dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n",
 			(unsigned short)res->start,
-- 
2.30.2


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

* Re: [PATCH]  hwmon: (dme1737): Add missing null check on return from platform_get_resource
  2021-04-06 18:54 [PATCH] hwmon: (dme1737): Add missing null check on return from platform_get_resource Colin King
@ 2021-04-09 23:08 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2021-04-09 23:08 UTC (permalink / raw)
  To: Colin King
  Cc: Juerg Haefliger, Jean Delvare, Mark M . Hoffman, linux-hwmon,
	kernel-janitors, linux-kernel

On Tue, Apr 06, 2021 at 07:54:58PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The call to platform_get_resource can potentially return a NULL pointer
> on failure, so add this check and return -EINVAL if it fails.
> 
> Addresses-Coverity: ("Dereference null return")
> Fixes: e95c237d78c0 ("hwmon: (dme1737) Add sch311x support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Not really sure what to do with this; it is a false positive.
The resource is always set by the instantiating code (in the same
driver). Adding an error check just to make coverity happy seems
like a waste. Maybe we should introduce the equivalent of
devm_ioremap_resource() for IORESOURCE_IO.

Guenter

> ---
>  drivers/hwmon/dme1737.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
> index c1e4cfb40c3d..a2157872e126 100644
> --- a/drivers/hwmon/dme1737.c
> +++ b/drivers/hwmon/dme1737.c
> @@ -2633,6 +2633,8 @@ static int dme1737_isa_probe(struct platform_device *pdev)
>  	int err;
>  
>  	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
> +	if (!res)
> +		return -EINVAL;
>  	if (!devm_request_region(dev, res->start, DME1737_EXTENT, "dme1737")) {
>  		dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n",
>  			(unsigned short)res->start,

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

end of thread, other threads:[~2021-04-09 23:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-06 18:54 [PATCH] hwmon: (dme1737): Add missing null check on return from platform_get_resource Colin King
2021-04-09 23:08 ` Guenter Roeck

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).