]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
hwmon: (ina3221) Check channel status for alarms attribute read
authorNicolin Chen <nicoleotsuka@gmail.com>
Mon, 5 Nov 2018 20:48:40 +0000 (12:48 -0800)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 16 Dec 2018 23:13:11 +0000 (15:13 -0800)
There is nothing critically wrong to read these two attributes
without having a is_enabled() check at this point. But reading
the MASK_ENABLE register would clear the CVRF bit according to
the datasheet. So it'd be safer to fence for disabled channels
in order to add pm runtime feature.

Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/ina3221.c

index d61688f045949d12c6b4eea90d7122a923ac77f0..26cdf3342d808ff2e3aeacbc4aa1ffb4bfaf231c 100644 (file)
@@ -200,6 +200,12 @@ static int ina3221_read_curr(struct device *dev, u32 attr,
                return 0;
        case hwmon_curr_crit_alarm:
        case hwmon_curr_max_alarm:
+               /* No actual register read if channel is disabled */
+               if (!ina3221_is_enabled(ina, channel)) {
+                       /* Return 0 for alert flags */
+                       *val = 0;
+                       return 0;
+               }
                ret = regmap_field_read(ina->fields[reg], &regval);
                if (ret)
                        return ret;