Skip to content

Commit faf7f9e

Browse files
dlechjic23
authored andcommitted
iio: adc: ad7124: use clamp()
Use clamp() instead of open-coding clamping. Signed-off-by: David Lechner <dlechner@baylibre.com> Reviewed-by: Andy Shevchenko <andy@kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 08a9e5f commit faf7f9e

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

drivers/iio/adc/ad7124.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/interrupt.h>
1616
#include <linux/kernel.h>
1717
#include <linux/kfifo.h>
18+
#include <linux/minmax.h>
1819
#include <linux/module.h>
1920
#include <linux/mod_devicetable.h>
2021
#include <linux/property.h>
@@ -299,11 +300,7 @@ static void ad7124_set_channel_odr(struct ad7124_state *st, unsigned int channel
299300
* FS[10:0] can have a value from 1 to 2047
300301
*/
301302
factor = 32 * 4; /* N = 4 for default sinc4 filter. */
302-
odr_sel_bits = DIV_ROUND_CLOSEST(fclk, odr * factor);
303-
if (odr_sel_bits < 1)
304-
odr_sel_bits = 1;
305-
else if (odr_sel_bits > 2047)
306-
odr_sel_bits = 2047;
303+
odr_sel_bits = clamp(DIV_ROUND_CLOSEST(fclk, odr * factor), 1, 2047);
307304

308305
if (odr_sel_bits != st->channels[channel].cfg.odr_sel_bits)
309306
st->channels[channel].cfg.live = false;

0 commit comments

Comments
 (0)