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 2:54 PM Lars-Peter Clausen <lars@xxxxxxxxxx> wrote:
> On 3/20/21 12:01 PM, Joe Perches wrote:
> > On Sat, 2021-03-20 at 08:14 +0100, Lars-Peter Clausen wrote:
> >> Update DAC drivers powerdown attribute show callback to use the new
> >> sysfs_emit() function.
> >>
> >> sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> >> knows about the sysfs buffer specifics and has some built-in sanity checks.
> > Thanks.
> >
> > unrelated trivia:
> >
> >> diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
> > []
> >> @@ -255,7 +255,7 @@ static ssize_t ad5360_read_dac_powerdown(struct device *dev,
> >>      struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> >>      struct ad5360_state *st = iio_priv(indio_dev);
> >>
> >> -    return sprintf(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> >> +    return sysfs_emit(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> > rather than cast to bool, perhaps standardize to use !!(val & test)
> I very much prefer the cast to bool since it semantically stronger.

It's a mistake here. You have no special type for bool and you do
transition int -> bool -> int.
Why? !! is a proper way to deal with this.

> You
> don't have to know that the !! idiom is used to cast an int to bool.

As Joe said.


-- 
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