Re: [PATCH v5 10/11] input: misc: Add support for MAX7360 rotary
From: Andy Shevchenko
Date: Tue Mar 25 2025 - 12:14:47 EST
On Tue, Mar 25, 2025 at 04:56:20PM +0100, Mathieu Dubois-Briand wrote:
> On Wed Mar 19, 2025 at 1:11 PM CET, Andy Shevchenko wrote:
> > On Tue, Mar 18, 2025 at 05:26:26PM +0100, Mathieu Dubois-Briand wrote:
...
> > > + int val;
Btw, this has to be unsigned to match the API.
> > > + int ret;
> > > +
> > > + ret = regmap_read(max7360_rotary->regmap, MAX7360_REG_RTR_CNT, &val);
> > > + if (ret < 0) {
> > > + dev_err(&max7360_rotary->input->dev,
> > > + "Failed to read rotary counter\n");
> > > + return IRQ_NONE;
> > > + }
> > > + input_report_rel(max7360_rotary->input, max7360_rotary->axis,
> > > + (int8_t)val);
> >
> > This is strange:
> > 1) why casting to begin with?
> > 2) why to C type and not kernel (s8) type?
>
> I believe the cast is needed, as, while the value read with
> regmap_read() is stored in an int, the underlying value is indeed a
> signed 8 bits integer.
>
> Without cast negative values will not be correct: -1 (0xFF) -> will be
> interpreted as 255 (0x000000FF).
With the above fix it makes sense, but it's not clear for the reader still.
What you want is most likely to call sign_extend32().
--
With Best Regards,
Andy Shevchenko