Re: [PATCH 3/3] staging: iio: ad9834: use sysfs_emit() in show functions
From: Jonathan Cameron
Date: Sat Mar 21 2026 - 09:20:16 EST
On Fri, 20 Mar 2026 10:15:07 +0200
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> 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.
>