On Fri, Apr 17, 2020 at 2:42 PM Linus Walleij <linus.walleij@xxxxxxxxxx> wrote: > > This breaks out the measurement code to its own function > so we can handle this without swirling it up with the > big switch() statement inside ak8974_read_raw(). > > Keep a local s16 helper variable for the signed value > coming out of the measurement before assigning it to the > integer *val. The local variable makes the code easier > to read and the compiler will optimize it if possible. > + /* > + * This explicit cast to (s16) is necessary as the measurement > + * is done in 2's complement with positive and negative values. > + * The follwing assignment to *val will then convert the signed > + * s16 value to a signed int value. > + */ > + outval = (s16)le16_to_cpu(hw_values[address]); > + *val = outval; I'm wondering if you may use sign_extend32() here. -- With Best Regards, Andy Shevchenko