mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: 'Andy Shevchenko' <andriy.shevchenko@linux.intel.com>
To: David Laight <David.Laight@aculab.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1 1/1] pktcdvd: Use clamp_val() instead of min()+max()
Date: Tue, 20 Jun 2023 18:03:17 +0300	[thread overview]
Message-ID: <ZJG/tfh7kKauoMZJ@smile.fi.intel.com> (raw)
In-Reply-To: <cd039ed4855c4e78a0867c4b5173e879@AcuMS.aculab.com>

On Tue, Jun 20, 2023 at 01:35:11PM +0000, David Laight wrote:
> From: 'Andy Shevchenko'
> > Sent: 20 June 2023 14:25
> > On Tue, Jun 20, 2023 at 12:06:49PM +0000, David Laight wrote:

...

> > > > +		*hi = clamp_val(*hi, 500, 1000000);
> > >
> > > (standard rant about minmax.h)
> > >
> > > clamp_val() is pretty much broken by design.
> > > It MIGHT be ok here but it casts both limits to the
> > > type of the value being compared.
> > > In general that is just plain wrong.
> > >
> > > Like min_t() it is generally ok because the kernel only uses
> > > unsigned values between 0 and MAXINT.
> > >
> > > If min/max were ok, then using clamp() should also be ok.
> > 
> > Submit a patch to fix it, if you think you can make it better.
> > Obviously your comment can be addressed separately if we even
> > need that.
> 
> Did you try using clamp() ?
> 
> To see why clamp_val() is broken consider?
> 	unsigned char val = 200;
> 	...
> 	xxx = clamp_val(val, 10, 300);
>  
> This sets xxx to 44 - not exactly expected.

Right, clamp_val() has to be improved.
However this is not the case in this driver.

I have just sent a v2 with clamp().

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2023-06-20 15:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-16 14:26 Andy Shevchenko
2023-06-20 12:06 ` David Laight
2023-06-20 13:24   ` 'Andy Shevchenko'
2023-06-20 13:35     ` David Laight
2023-06-20 15:03       ` 'Andy Shevchenko' [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=ZJG/tfh7kKauoMZJ@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=David.Laight@aculab.com \
    --cc=axboe@kernel.dk \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.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®