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. No functional change.
Signed-off-by: Gabriel Rondon <grondon@gmail.com>
---
drivers/staging/iio/frequency/ad9834.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index d339d5e8e..844e92adc 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -290,7 +290,7 @@ ssize_t ad9834_show_out0_wavetype_available(struct device *dev,
else
str = "sine triangle";
- return sprintf(buf, "%s\n", str);
+ return sysfs_emit(buf, "%s\n", str);
}
static IIO_DEVICE_ATTR(out_altvoltage0_out0_wavetype_available, 0444,
@@ -310,7 +310,7 @@ ssize_t ad9834_show_out1_wavetype_available(struct device *dev,
else
str = "square";
- return sprintf(buf, "%s\n", str);
+ return sysfs_emit(buf, "%s\n", str);
}
static IIO_DEVICE_ATTR(out_altvoltage0_out1_wavetype_available, 0444,
--
2.33.0
On Thu, Mar 19, 2026 at 10:57:19PM +0000, Gabriel Rondon wrote: > 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. No functional change. ... > else > str = "sine triangle"; > > - return sprintf(buf, "%s\n", str); > + return sysfs_emit(buf, "%s\n", str); Do more, drop these unneeded 'else' and return directly, if (st->devid == ID_AD9833 || st->devid == ID_AD9837) 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"); But again, check what is the modern ways of providing static _avail lists. ... > - return sprintf(buf, "%s\n", str); > + return sysfs_emit(buf, "%s\n", str); Ditto. -- With Best Regards, Andy Shevchenko
On Fri, 20 Mar 2026 10:15:07 +0200 Andy Shevchenko <andriy.shevchenko@intel.com> wrote: > On Thu, Mar 19, 2026 at 10:57:19PM +0000, Gabriel Rondon wrote: > > 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. No functional change. > > ... > > > else > > str = "sine triangle"; > > > > - return sprintf(buf, "%s\n", str); > > + return sysfs_emit(buf, "%s\n", str); > > Do more, drop these unneeded 'else' and return directly, > > if (st->devid == ID_AD9833 || st->devid == ID_AD9837) > 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"); > > But again, check what is the modern ways of providing static _avail lists. FWIW, they don't work for strings and I'm not sure I'd want to add string support! More generally good advice, just not applicable in this particular case. Thanks, Jonathan > > ... > > > - return sprintf(buf, "%s\n", str); > > + return sysfs_emit(buf, "%s\n", str); > > Ditto. >
© 2016 - 2026 Red Hat, Inc.