lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250723164100.34e864d6@jic23-huawei>
Date: Wed, 23 Jul 2025 16:41:00 +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 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:
> > Update the sysfs interface for sampling frequency and scale attributes.
> > Replace `scnprintf()` with `sysfs_emit_at()` which is PAGE_SIZE-aware
> > and recommended for use in sysfs.  
> 
> ...
> 
> >  	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 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?

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

Powered by Openwall GNU/*/Linux Powered by OpenVZ