Skip to content

Commit f909f22

Browse files
groeckgregkh
authored andcommitted
hwmon: (max6639) Fix pulses-per-revolution implementation
[ Upstream commit e7bae9a7a5e1251ab414291f4e9304d702bb9221 ] The valid range for the pulses-per-revolution devicetree property is 1..4. The current code checks for a range of 1..5. Fix it. Declare the variable used to retrieve pulses per revolution from devicetree as u32 (unsigned) to match the of_property_read_u32() API. The current code uses a postfix decrement when writing the pulses per resolution into the chip. This has no effect since the value is evaluated before it is decremented. Fix it by decrementing before evaluating the value. Fixes: 7506ebc ("hwmon: (max6639) : Configure based on DT property") Cc: Naresh Solanki <naresh.solanki@9elements.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 96955cf commit f909f22

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

drivers/hwmon/max6639.c

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

241241
static int max6639_write_fan(struct device *dev, u32 attr, int channel,
@@ -537,8 +537,8 @@ static int max6639_probe_child_from_dt(struct i2c_client *client,
537537

538538
{
539539
struct device *dev = &client->dev;
540-
u32 i;
541-
int err, val;
540+
u32 i, val;
541+
int err;
542542

543543
err = of_property_read_u32(child, "reg", &i);
544544
if (err) {
@@ -553,8 +553,8 @@ static int max6639_probe_child_from_dt(struct i2c_client *client,
553553

554554
err = of_property_read_u32(child, "pulses-per-revolution", &val);
555555
if (!err) {
556-
if (val < 1 || val > 5) {
557-
dev_err(dev, "invalid pulses-per-revolution %d of %pOFn\n", val, child);
556+
if (val < 1 || val > 4) {
557+
dev_err(dev, "invalid pulses-per-revolution %u of %pOFn\n", val, child);
558558
return -EINVAL;
559559
}
560560
data->ppr[i] = val;

0 commit comments

Comments
 (0)