mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: David Laight <david.laight.linux@gmail.com>
Cc: Andy Shevchenko <andriy.shevchenko@intel.com>,
	Di Wu <diwux@google.com>,
	dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	bleung@chromium.org, groeck@chromium.org, tzungbi@kernel.org,
	linux-iio@vger.kernel.org, chrome-platform@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: cros_ec: use sysfs_emit() in show callbacks
Date: Sat, 14 Nov 2026 02:15:54 +0000	[thread overview]
Message-ID: <20261114021554.2165a2bf@jic23-hlaptop> (raw)
In-Reply-To: <20261113092305.00ec8be5@pumpkin>

On Fri, 13 Nov 2026 09:23:05 +0000
David Laight <david.laight.linux@gmail.com> wrote:

> On Fri, 13 Nov 2026 01:36:46 +0000
> Jonathan Cameron <jic23@kernel.org> wrote:
> 
> > On Thu, 12 Nov 2026 22:02:18 +0000
> > David Laight <david.laight.linux@gmail.com> wrote:
> >   
> > > On Thu, 12 Nov 2026 02:04:39 +0000
> > > Jonathan Cameron <jic23@kernel.org> wrote:
> > >     
> > > > On Wed, 11 Nov 2026 16:39:37 +0200
> > > > Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > > >       
> > > > > On Wed, Nov 11, 2026 at 07:26:08AM +0000, Di Wu wrote:        
> > > > > > Replace sprintf() and snprintf() with sysfs_emit() in the sysfs show
> > > > > > and ext_info read callbacks. sysfs_emit() is aware of the sysfs buffer
> > > > > > PAGE_SIZE limit and is the preferred helper for show callbacks.          
> > > > > 
> > > > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> > > > > 
> > > > > ...
> > > > >         
> > > > > > -	return sprintf(buf, "%d.%06u\n",
> > > > > > -		       latency / 1000,
> > > > > > -		       (latency % 1000) * 1000);
> > > > > > +	return sysfs_emit(buf, "%d.%06u\n",
> > > > > > +			  latency / 1000,
> > > > > > +			  (latency % 1000) * 1000);          
> > > > > 
> > > > > As David said, since you touched these lines, make the less amount of them
> > > > > while at it.
> > > > > 
> > > > > (But no need to resend, usually Jonathan is kind to tweak this small thing.)
> > > > >         
> > > > Done and applied.
> > > > 
> > > >       
> > > 
> > > I just looked at that line again.
> > > Why is it multiplying the remainder by 1000?
> > > It could be:
> > > 	return sysfs_emit(buf, "%d.%03u000\n", latency / 1000, latency % 1000);
> > > if the 6 digits after the decimal point are required.    
> > 
> > Good point, I guess unrelated change that we could have on top.  
> 
> Indeed.
> 
> > Those trailing zeros shouldn't matter.  
> 
> There is a matching oddity in the set function (just above).
> It calls iio_str_to_fixpoint(buf, 1000000, &integer, &fract)
> then does latency = integer * 1000 + fract/1000.
> Just replace the 100000 by 1000 and you don't need the divide.
> 
> iio_str_to_fixpoint() will ignore are extra fractional digits.
> 
> Although I'm not at all sure its handling of negative value is correct.
> It converts -1.5 to -1/5 and -0.5 to 0/-5.
> I can't see how that is useful since i*10+f for both gives -5.
> 
> I'd have though that either the fractional part should always be positive
> so -1.4 would need converting to -2/6 or it would have the same sign as
> the integer part and -1.4 would be converted to -1/-4.

That is rather odd use of the output of iio_str_to_fixpoint()
which admittedly is a bit unusual because of the need to handle there
being no where to put that negative when the integer is 0.

Can get away with it here though as latencies aren't negative so.
The code doesn't seem to actually check that though which might
be a nice useability improvement rather than setting it to something odd.

Jonathan





> 
> David
> 
> >   
> > > 
> > > David    
> >   
> 


      reply	other threads:[~2026-11-14  2:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  7:26 Di Wu
2026-11-11  8:36 ` Benson Leung
2026-11-11 11:17 ` David Laight
2026-11-11 14:39 ` Andy Shevchenko
2026-11-12  2:04   ` Jonathan Cameron
2026-11-12 22:02     ` David Laight
2026-11-13  1:36       ` Jonathan Cameron
2026-11-13  9:23         ` David Laight
2026-11-14  2:15           ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261114021554.2165a2bf@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=david.laight.linux@gmail.com \
    --cc=diwux@google.com \
    --cc=dlechner@baylibre.com \
    --cc=groeck@chromium.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=tzungbi@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®