[PATCH v2 3/3] staging: iio: ad9834: use sysfs_emit() and simplify show functions
From: Gabriel Rondon
Date: Fri Mar 20 2026 - 18:25:21 EST
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@xxxxxxxxx>
---
drivers/staging/iio/frequency/ad9834.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index d339d5e8e..bdb2580e2 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -281,16 +281,12 @@ ssize_t ad9834_show_out0_wavetype_available(struct device *dev,
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ad9834_state *st = iio_priv(indio_dev);
- char *str;
if (st->devid == ID_AD9833 || st->devid == ID_AD9837)
- str = "sine triangle square";
- else if (st->control & AD9834_OPBITEN)
- str = "sine";
- else
- str = "sine triangle";
-
- return sprintf(buf, "%s\n", str);
+ return sysfs_emit(buf, "sine triangle square\n");
+ if (st->control & AD9834_OPBITEN)
+ return sysfs_emit(buf, "sine\n");
+ return sysfs_emit(buf, "sine triangle\n");
}
static IIO_DEVICE_ATTR(out_altvoltage0_out0_wavetype_available, 0444,
@@ -303,14 +299,10 @@ ssize_t ad9834_show_out1_wavetype_available(struct device *dev,
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ad9834_state *st = iio_priv(indio_dev);
- char *str;
if (st->control & AD9834_MODE)
- str = "";
- else
- str = "square";
-
- return sprintf(buf, "%s\n", str);
+ return sysfs_emit(buf, "\n");
+ return sysfs_emit(buf, "square\n");
}
static IIO_DEVICE_ATTR(out_altvoltage0_out1_wavetype_available, 0444,
--
2.33.0