[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250802125038.7a02cbce@jic23-huawei>
Date: Sat, 2 Aug 2025 12:50:38 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Andy Shevchenko <andriy.shevchenko@...el.com>
Cc: Akshay Bansod <akbansd@...il.com>, Lorenzo Bianconi
<lorenzo@...nel.org>, David Lechner <dlechner@...libre.com>, Nuno
Sá <nuno.sa@...log.com>, Andy Shevchenko <andy@...nel.org>,
linux-kernel-mentees@...ts.linuxfoundation.org, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3] iio: st_lsm6dsx: Replace scnprintf with sysfs_emit
On Thu, 24 Jul 2025 14:47:31 +0300
Andy Shevchenko <andriy.shevchenko@...el.com> wrote:
> On Wed, Jul 23, 2025 at 04:41:00PM +0100, Jonathan Cameron wrote:
> > On Wed, 23 Jul 2025 17:42:28 +0300
> > Andy Shevchenko <andriy.shevchenko@...el.com> wrote:
> > > On Wed, Jul 23, 2025 at 07:43:59PM +0530, Akshay Bansod wrote:
>
> ...
>
> > > > fs_table = &hw->settings->fs_table[sensor->id];
> > > > for (i = 0; i < fs_table->fs_len; i++)
> > > > - len += scnprintf(buf + len, PAGE_SIZE - len, "0.%09u ",
> > > > - fs_table->fs_avl[i].gain);
> > > > - buf[len - 1] = '\n';
> > > > + len += sysfs_emit_at(buf, len, "0.%09u ",
> > > > + fs_table->fs_avl[i].gain);
> > > > +
> > > > + sysfs_emit_at(buf, len - 1, "\n");
> > >
> > > Still looks a bit weird (while working).
> > >
> > > > return len;
> > >
> > > I deally we should have a helper doing all this under the hood for plenty of
> > > the (existing) users in the kernel.
> >
> > hmm I'm not sure generic is terribly easy
>
> I agree, I have some plans for %p specifier extension, but I was stuck with it
> and it in half-basked state in some of my local Git branches.
>
> > and I'd prefer this using the
> > read_avail callbacks that require the data in an array where ever possible.
> > Mind you that does the same print at len - 1 as this. Let's play.
> > Completely untested.
> >
> > for (i = 0; i < fs_table->fs_len; i++)
> > len += sysfs_emit_at(buf, len, "0x%09u%c",
> > fs_table->fs_avl[i].gain,
> > ((i == fs_table->fs_len - 1) ? '\n', ' '));
> >
> > better?
>
> Without extra parentheses this makes the job.
>
Akshay, can you spin a new version along those lines?
>
> > It's definitely not more readable than the above, but it does avoid the write
> > to len - 1.
> >
> > > In any case, I leave this change to others to comment, I don't object pushing
> > > it in this form, either way len - 1 is simply weird.
>
Powered by blists - more mailing lists