Skip to content

Commit 113ae7b

Browse files
committed
Merge tag 'hwmon-for-v7.0-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon fixes from Guenter Roeck: - max6639: Fix pulses-per-revolution implementation - Several PMBus drivers: Add missing error checks * tag 'hwmon-for-v7.0-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: (max6639) Fix pulses-per-revolution implementation hwmon: (pmbus/isl68137) Fix unchecked return value and use sysfs_emit() hwmon: (pmbus/ina233) Add error check for pmbus_read_word_data() return value hwmon: (pmbus/mp2869) Check pmbus_read_byte_data() before using its return value hwmon: (pmbus/mp2975) Add error check for pmbus_read_word_data() return value hwmon: (pmbus/hac300s) Add error check for pmbus_read_word_data() return value
2 parents 55d55b9 + e7bae9a commit 113ae7b

6 files changed

Lines changed: 37 additions & 21 deletions

File tree

drivers/hwmon/max6639.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static int max6639_read_fan(struct device *dev, u32 attr, int channel,
232232
static int max6639_set_ppr(struct max6639_data *data, int channel, u8 ppr)
233233
{
234234
/* Decrement the PPR value and shift left by 6 to match the register format */
235-
return regmap_write(data->regmap, MAX6639_REG_FAN_PPR(channel), ppr-- << 6);
235+
return regmap_write(data->regmap, MAX6639_REG_FAN_PPR(channel), --ppr << 6);
236236
}
237237

238238
static int max6639_write_fan(struct device *dev, u32 attr, int channel,
@@ -524,8 +524,8 @@ static int max6639_probe_child_from_dt(struct i2c_client *client,
524524

525525
{
526526
struct device *dev = &client->dev;
527-
u32 i;
528-
int err, val;
527+
u32 i, val;
528+
int err;
529529

530530
err = of_property_read_u32(child, "reg", &i);
531531
if (err) {
@@ -540,8 +540,8 @@ static int max6639_probe_child_from_dt(struct i2c_client *client,
540540

541541
err = of_property_read_u32(child, "pulses-per-revolution", &val);
542542
if (!err) {
543-
if (val < 1 || val > 5) {
544-
dev_err(dev, "invalid pulses-per-revolution %d of %pOFn\n", val, child);
543+
if (val < 1 || val > 4) {
544+
dev_err(dev, "invalid pulses-per-revolution %u of %pOFn\n", val, child);
545545
return -EINVAL;
546546
}
547547
data->ppr[i] = val;

drivers/hwmon/pmbus/hac300s.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ static int hac300s_read_word_data(struct i2c_client *client, int page,
5858
case PMBUS_MFR_VOUT_MIN:
5959
case PMBUS_READ_VOUT:
6060
rv = pmbus_read_word_data(client, page, phase, reg);
61+
if (rv < 0)
62+
return rv;
6163
return FIELD_GET(LINEAR11_MANTISSA_MASK, rv);
6264
default:
6365
return -ENODATA;

drivers/hwmon/pmbus/ina233.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ static int ina233_read_word_data(struct i2c_client *client, int page,
6767
switch (reg) {
6868
case PMBUS_VIRT_READ_VMON:
6969
ret = pmbus_read_word_data(client, 0, 0xff, MFR_READ_VSHUNT);
70+
if (ret < 0)
71+
return ret;
7072

7173
/* Adjust returned value to match VIN coefficients */
7274
/* VIN: 1.25 mV VSHUNT: 2.5 uV LSB */

drivers/hwmon/pmbus/isl68137.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,11 @@ static ssize_t isl68137_avs_enable_show_page(struct i2c_client *client,
9898
{
9999
int val = pmbus_read_byte_data(client, page, PMBUS_OPERATION);
100100

101-
return sprintf(buf, "%d\n",
102-
(val & ISL68137_VOUT_AVS) == ISL68137_VOUT_AVS ? 1 : 0);
101+
if (val < 0)
102+
return val;
103+
104+
return sysfs_emit(buf, "%d\n",
105+
(val & ISL68137_VOUT_AVS) == ISL68137_VOUT_AVS);
103106
}
104107

105108
static ssize_t isl68137_avs_enable_store_page(struct i2c_client *client,

drivers/hwmon/pmbus/mp2869.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static int mp2869_read_byte_data(struct i2c_client *client, int page, int reg)
165165
{
166166
const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
167167
struct mp2869_data *data = to_mp2869_data(info);
168-
int ret;
168+
int ret, mfr;
169169

170170
switch (reg) {
171171
case PMBUS_VOUT_MODE:
@@ -188,11 +188,14 @@ static int mp2869_read_byte_data(struct i2c_client *client, int page, int reg)
188188
if (ret < 0)
189189
return ret;
190190

191+
mfr = pmbus_read_byte_data(client, page,
192+
PMBUS_STATUS_MFR_SPECIFIC);
193+
if (mfr < 0)
194+
return mfr;
195+
191196
ret = (ret & ~GENMASK(2, 2)) |
192197
FIELD_PREP(GENMASK(2, 2),
193-
FIELD_GET(GENMASK(1, 1),
194-
pmbus_read_byte_data(client, page,
195-
PMBUS_STATUS_MFR_SPECIFIC)));
198+
FIELD_GET(GENMASK(1, 1), mfr));
196199
break;
197200
case PMBUS_STATUS_TEMPERATURE:
198201
/*
@@ -207,15 +210,16 @@ static int mp2869_read_byte_data(struct i2c_client *client, int page, int reg)
207210
if (ret < 0)
208211
return ret;
209212

213+
mfr = pmbus_read_byte_data(client, page,
214+
PMBUS_STATUS_MFR_SPECIFIC);
215+
if (mfr < 0)
216+
return mfr;
217+
210218
ret = (ret & ~GENMASK(7, 6)) |
211219
FIELD_PREP(GENMASK(6, 6),
212-
FIELD_GET(GENMASK(1, 1),
213-
pmbus_read_byte_data(client, page,
214-
PMBUS_STATUS_MFR_SPECIFIC))) |
220+
FIELD_GET(GENMASK(1, 1), mfr)) |
215221
FIELD_PREP(GENMASK(7, 7),
216-
FIELD_GET(GENMASK(1, 1),
217-
pmbus_read_byte_data(client, page,
218-
PMBUS_STATUS_MFR_SPECIFIC)));
222+
FIELD_GET(GENMASK(1, 1), mfr));
219223
break;
220224
default:
221225
ret = -ENODATA;
@@ -230,7 +234,7 @@ static int mp2869_read_word_data(struct i2c_client *client, int page, int phase,
230234
{
231235
const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
232236
struct mp2869_data *data = to_mp2869_data(info);
233-
int ret;
237+
int ret, mfr;
234238

235239
switch (reg) {
236240
case PMBUS_STATUS_WORD:
@@ -246,11 +250,14 @@ static int mp2869_read_word_data(struct i2c_client *client, int page, int phase,
246250
if (ret < 0)
247251
return ret;
248252

253+
mfr = pmbus_read_byte_data(client, page,
254+
PMBUS_STATUS_MFR_SPECIFIC);
255+
if (mfr < 0)
256+
return mfr;
257+
249258
ret = (ret & ~GENMASK(2, 2)) |
250259
FIELD_PREP(GENMASK(2, 2),
251-
FIELD_GET(GENMASK(1, 1),
252-
pmbus_read_byte_data(client, page,
253-
PMBUS_STATUS_MFR_SPECIFIC)));
260+
FIELD_GET(GENMASK(1, 1), mfr));
254261
break;
255262
case PMBUS_READ_VIN:
256263
/*

drivers/hwmon/pmbus/mp2975.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ static int mp2973_read_word_data(struct i2c_client *client, int page,
313313
case PMBUS_STATUS_WORD:
314314
/* MP2973 & MP2971 return PGOOD instead of PB_STATUS_POWER_GOOD_N. */
315315
ret = pmbus_read_word_data(client, page, phase, reg);
316+
if (ret < 0)
317+
return ret;
316318
ret ^= PB_STATUS_POWER_GOOD_N;
317319
break;
318320
case PMBUS_OT_FAULT_LIMIT:

0 commit comments

Comments
 (0)