Re: [PATCH v3 2/3] iio: mpl3115: add threshold events support

From: Marcelo Schmitt
Date: Sat Nov 08 2025 - 14:04:33 EST


...
> > > + switch (chan->type) {
> > > + case IIO_PRESSURE:
> > > + val >>= 1;
> > > +
> > > + if (val < 0 || val > U16_MAX)
> > Alternatively, could use in_range() for the check.
> >
> > > + return -EINVAL;
> > > +
> > > + tmp = cpu_to_be16(val);
> > > +
> > > + return i2c_smbus_write_i2c_block_data(data->client,
> > > + MPL3115_PRESS_TGT,
> > > + sizeof(tmp), (u8 *)&tmp);
> > > + case IIO_TEMP:
> > > + if (val < S8_MIN || val > S8_MAX)
> > this could also use in_range().
> >
> > If you opt for the macro,
> > #include <linux/minmax.h>
> >
> I see that the in_range() macro operates only on unsigned values, so
> placing it here would be wrong I guess. In order to keep the style
> consistenc in this function, I'd keep both checks as "val < x || val > y"
>
Ah, good point. Okay, no objection.

> > > + return -EINVAL;
> > > +
> > > + return i2c_smbus_write_byte_data(data->client,
> > > + MPL3115_TEMP_TGT, val);
> > > + default:
> > > + return -EINVAL;
> > > + }
> > > +}
> > > +
> Kind regards,
> Antoni Pokusinski
>