Skip to content

Commit

Permalink
hwmon: (max31827) Return closest value in update_interval
Browse files Browse the repository at this point in the history
When user writes a value to update_interval which does not match the
possible values, instead of returning invalid error, return the closest
value.

Signed-off-by: Daniel Matyas <daniel.matyas@analog.com>
Link: https://lore.kernel.org/r/20231031182158.124608-4-daniel.matyas@analog.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Daniel Matyas authored and Guenter Roeck committed Dec 11, 2023
1 parent 8a0806d commit 64176bd
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/hwmon/max31827.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,8 @@ static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
val < max31827_conversions[res])
res++;

if (res == ARRAY_SIZE(max31827_conversions) ||
val != max31827_conversions[res])
return -EINVAL;
if (res == ARRAY_SIZE(max31827_conversions))
res = ARRAY_SIZE(max31827_conversions) - 1;

res = FIELD_PREP(MAX31827_CONFIGURATION_CNV_RATE_MASK,
res);
Expand Down

0 comments on commit 64176bd

Please sign in to comment.