Linux Hardware Monitor development
 help / color / mirror / Atom feed
* [PATCH 1/2] hwmon: (adt7475) Potential error pointer dereferences
@ 2018-08-14  9:12 Dan Carpenter
  2018-08-14  9:14 ` [PATCH 2/2] hwmon: (adt7475) Remove some unnecessary checks Dan Carpenter
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Dan Carpenter @ 2018-08-14  9:12 UTC (permalink / raw)
  To: Jean Delvare, Tokunori Ikegami
  Cc: Guenter Roeck, linux-hwmon, kernel-janitors

The adt7475_update_device() function returns error pointers.  The
problem is that in show_pwmfreq() we dereference it before the check.
And then in pwm_use_point2_pwm_at_crit_show() there isn't a check at
all.  I don't know if it's required, but it silences a static checker
warning and it's doesn't hurt anything to check.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index 90837f7c7d0f..16045149f3db 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -962,13 +962,14 @@ static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr,
 {
 	struct adt7475_data *data = adt7475_update_device(dev);
 	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
-	int i = clamp_val(data->range[sattr->index] & 0xf, 0,
-			  ARRAY_SIZE(pwmfreq_table) - 1);
+	int idx;
 
 	if (IS_ERR(data))
 		return PTR_ERR(data);
+	idx = clamp_val(data->range[sattr->index] & 0xf, 0,
+			ARRAY_SIZE(pwmfreq_table) - 1);
 
-	return sprintf(buf, "%d\n", pwmfreq_table[i]);
+	return sprintf(buf, "%d\n", pwmfreq_table[idx]);
 }
 
 static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
@@ -1004,6 +1005,10 @@ static ssize_t pwm_use_point2_pwm_at_crit_show(struct device *dev,
 					char *buf)
 {
 	struct adt7475_data *data = adt7475_update_device(dev);
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
 	return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY));
 }
 

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

end of thread, other threads:[~2018-08-21  5:58 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-14  9:12 [PATCH 1/2] hwmon: (adt7475) Potential error pointer dereferences Dan Carpenter
2018-08-14  9:14 ` [PATCH 2/2] hwmon: (adt7475) Remove some unnecessary checks Dan Carpenter
2018-08-14  9:34   ` IKEGAMI Tokunori
2018-08-14  9:57     ` Dan Carpenter
2018-08-14 10:07     ` [PATCH 2/2 v2] hwmon: (adt7475) Make adt7475_read_word() return errors Dan Carpenter
2018-08-14 10:12       ` IKEGAMI Tokunori
2018-08-14 13:40       ` Guenter Roeck
2018-08-15  6:02         ` IKEGAMI Tokunori
2018-08-15 12:37           ` Guenter Roeck
2018-08-21  2:40             ` IKEGAMI Tokunori
2018-08-14  9:32 ` [PATCH 1/2] hwmon: (adt7475) Potential error pointer dereferences IKEGAMI Tokunori
2018-08-14 13:39 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox