Re: [PATCH 4/4] iio: dac: Convert powerdown read callbacks to sysfs_emit()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Mar 20, 2021 at 1:26 PM Lars-Peter Clausen <lars@xxxxxxxxxx> wrote:

One side note for the future improvements.

> +       return sysfs_emit(buf, "%d\n",
> +                         !(st->pwr_down_mask & (1 << chan->channel)));

> +       return sysfs_emit(buf, "%d\n",
> +                         !!(st->pwr_down_mask & (1 << chan->channel)));

> -       return sprintf(buf, "%d\n", !!(st->pwr_down_mask &
> +       return sysfs_emit(buf, "%d\n", !!(st->pwr_down_mask &
>                                        (0x3 << (chan->channel * 2))));

Converting above to use BIT() / GENMASK() will help to avoid potential
UB when it will try to set the last (31st) bit.

> +       return sysfs_emit(buf, "%d\n",
> +                         (bool)(st->pwr_down & (1 << chan->channel)));

> +       return sysfs_emit(buf, "%d\n",
> +                         !!(st->powerdown_cache_mask & (1 << chan->channel)));

...

> -       return sprintf(buf, "%d\n", ret ? 0 : 1);
> +       return sysfs_emit(buf, "%d\n", ret ? 0 : 1);

Useless ternary, may be ret == 0 or !ret. (Yes, I know that compiler
optimizes this away)

-- 
With Best Regards,
Andy Shevchenko



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux