diff mbox series

[1/1] hwmon: check the return value of platform_get_resource()

Message ID 20230715094452.36119-1-ruc_gongyuanjun@163.com (mailing list archive)
State Rejected
Headers show
Series [1/1] hwmon: check the return value of platform_get_resource() | expand

Commit Message

Yuanjun Gong July 15, 2023, 9:44 a.m. UTC
platform_get_resource() may fail, therefore, the return value
of platform_get_resource should be checked to avoid null pointer
dereference in devm_request_region().

Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com>
---
 drivers/hwmon/w83627ehf.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Guenter Roeck July 15, 2023, 2:46 p.m. UTC | #1
On 7/15/23 02:44, Yuanjun Gong wrote:
> platform_get_resource() may fail, therefore, the return value
> of platform_get_resource should be checked to avoid null pointer
> dereference in devm_request_region().
> 

No, it can not, because the device was instantiated from
platform_create_bundle() which always creates the resource.

Guenter

> Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com>
> ---
>   drivers/hwmon/w83627ehf.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
> index fe960c0a624f..7793a4273e00 100644
> --- a/drivers/hwmon/w83627ehf.c
> +++ b/drivers/hwmon/w83627ehf.c
> @@ -1703,6 +1703,8 @@ static int __init w83627ehf_probe(struct platform_device *pdev)
>   	struct device *hwmon_dev;
>   
>   	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
> +	if (!res)
> +		return -EINVAL;
>   	if (!devm_request_region(dev, res->start, IOREGION_LENGTH, DRVNAME))
>   		return -EBUSY;
>
diff mbox series

Patch

diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index fe960c0a624f..7793a4273e00 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -1703,6 +1703,8 @@  static int __init w83627ehf_probe(struct platform_device *pdev)
 	struct device *hwmon_dev;
 
 	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
+	if (!res)
+		return -EINVAL;
 	if (!devm_request_region(dev, res->start, IOREGION_LENGTH, DRVNAME))
 		return -EBUSY;