Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

staging: iio: ad9834: use sysfs_emit() and simplify show functions

Replace sprintf() with sysfs_emit() in sysfs attribute show functions.
sysfs_emit() is the preferred API for sysfs callbacks as it is aware
of the PAGE_SIZE buffer limit.

Also simplify the wavetype_available show functions by removing
the intermediate string variable and returning directly from each
branch.

Signed-off-by: Gabriel Rondon <grondon@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Gabriel Rondon and committed by
Jonathan Cameron
8a75ac8f f6192780

+6 -14
+6 -14
drivers/staging/iio/frequency/ad9834.c
··· 281 281 { 282 282 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 283 283 struct ad9834_state *st = iio_priv(indio_dev); 284 - char *str; 285 284 286 285 if (st->devid == ID_AD9833 || st->devid == ID_AD9837) 287 - str = "sine triangle square"; 288 - else if (st->control & AD9834_OPBITEN) 289 - str = "sine"; 290 - else 291 - str = "sine triangle"; 292 - 293 - return sprintf(buf, "%s\n", str); 286 + return sysfs_emit(buf, "sine triangle square\n"); 287 + if (st->control & AD9834_OPBITEN) 288 + return sysfs_emit(buf, "sine\n"); 289 + return sysfs_emit(buf, "sine triangle\n"); 294 290 } 295 291 296 292 static IIO_DEVICE_ATTR(out_altvoltage0_out0_wavetype_available, 0444, ··· 299 303 { 300 304 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 301 305 struct ad9834_state *st = iio_priv(indio_dev); 302 - char *str; 303 306 304 307 if (st->control & AD9834_MODE) 305 - str = ""; 306 - else 307 - str = "square"; 308 - 309 - return sprintf(buf, "%s\n", str); 308 + return sysfs_emit(buf, "\n"); 309 + return sysfs_emit(buf, "square\n"); 310 310 } 311 311 312 312 static IIO_DEVICE_ATTR(out_altvoltage0_out1_wavetype_available, 0444,