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 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. You don't have to know that the !! idiom is used to cast an int to bool.



[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