[PATCH] hwmon: (tmp513) Add missing check for device_property_read_u32_array

Chen Ni posted 1 patch 1 week, 2 days ago
drivers/hwmon/tmp513.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[PATCH] hwmon: (tmp513) Add missing check for device_property_read_u32_array
Posted by Chen Ni 1 week, 2 days ago
Add check for the return value of device_property_read_u32_array() and
return the error if it fails in order to catch the error.

Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
 drivers/hwmon/tmp513.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c
index 5acbfd7d088d..f201d0a9ba14 100644
--- a/drivers/hwmon/tmp513.c
+++ b/drivers/hwmon/tmp513.c
@@ -676,8 +676,10 @@ static int tmp51x_read_properties(struct device *dev, struct tmp51x_data *data)
 	if (ret < 0)
 		return ret;
 
-	device_property_read_u32_array(dev, "ti,nfactor", data->nfactor,
-				       data->max_channels - 1);
+	ret = device_property_read_u32_array(dev, "ti,nfactor", data->nfactor,
+					     data->max_channels - 1);
+	if (ret)
+		return ret;
 
 	// Check if shunt value is compatible with pga-gain
 	if (data->shunt_uohms > data->pga_gain * 40 * MICRO) {
-- 
2.25.1
Re: [PATCH] hwmon: (tmp513) Add missing check for device_property_read_u32_array
Posted by Guenter Roeck 1 week, 1 day ago
On Wed, Jan 28, 2026 at 03:30:21PM +0800, Chen Ni wrote:
> Add check for the return value of device_property_read_u32_array() and
> return the error if it fails in order to catch the error.
> 
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
> ---
>  drivers/hwmon/tmp513.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c
> index 5acbfd7d088d..f201d0a9ba14 100644
> --- a/drivers/hwmon/tmp513.c
> +++ b/drivers/hwmon/tmp513.c
> @@ -676,8 +676,10 @@ static int tmp51x_read_properties(struct device *dev, struct tmp51x_data *data)
>  	if (ret < 0)
>  		return ret;
>  
> -	device_property_read_u32_array(dev, "ti,nfactor", data->nfactor,
> -				       data->max_channels - 1);
> +	ret = device_property_read_u32_array(dev, "ti,nfactor", data->nfactor,
> +					     data->max_channels - 1);
> +	if (ret)
> +		return ret;

NACK. The default is 0, and the property is optional.

Guenter

>  
>  	// Check if shunt value is compatible with pga-gain
>  	if (data->shunt_uohms > data->pga_gain * 40 * MICRO) {
> -- 
> 2.25.1
> 
>
Re: [PATCH] hwmon: (tmp513) Add missing check for device_property_read_u32_array
Posted by Markus Elfring 1 week, 2 days ago
> Add check for the return value of device_property_read_u32_array() and
> return the error if it fails in order to catch the error.

* Were any source code analysis tools involved here?

* Did anything hinder to add any tags (like “Fixes” and “Cc”) accordingly?


Regards,
Markus