public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: "'Rafael J. Wysocki'" <rafael@kernel.org>,
	Jiangshan Yi <yijiangshan@kylinos.cn>
Cc: "rui.zhang@intel.com" <rui.zhang@intel.com>,
	"lenb@kernel.org" <lenb@kernel.org>,
	"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"13667453960@163.com" <13667453960@163.com>
Subject: RE: [PATCH] ACPI: thermal: replace ternary operator with min_t()
Date: Fri, 31 Mar 2023 08:58:42 +0000	[thread overview]
Message-ID: <8781eb11ce42448aa9cd206168cb22db@AcuMS.aculab.com> (raw)
In-Reply-To: <CAJZ5v0hPbH9BMOLbrGOKcy1sGAXbq=7OTyFECA966i37wBp_AQ@mail.gmail.com>

From: Rafael J. Wysocki
> Sent: 30 March 2023 18:12
> 
> On Tue, Mar 28, 2023 at 5:17 AM Jiangshan Yi <yijiangshan@kylinos.cn> wrote:
> >
> > Fix the following coccicheck warning:
> 
> This is not a fix, because the current code is correct AFAICS.
> 
> It merely makes the code follow the coccicheck recommendation, which
> is a cleanup (although arguably a good one).
> 
> But because the new code is way more readable, I've applied this as
> 6.4 material (with edits in the changelog).

Also if you need to use min_t() there is really something wrong
with your types.

> > drivers/acpi/thermal.c:422: WARNING opportunity for min().
> >
> > min_t() macro is defined in include/linux/minmax.h. It avoids multiple
> > evaluations of the arguments when non-constant and performs strict
> > type-checking.

min_t() casts the arguments and performs absolutely no type-checking.
The casts can even mask off high bits that ought to be checked.

	David

> >
> > Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn>
> > ---
> >  drivers/acpi/thermal.c | 7 +++----
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
> > index 0b4b844f9d4c..179f41196a9d 100644
> > --- a/drivers/acpi/thermal.c
> > +++ b/drivers/acpi/thermal.c
> > @@ -419,10 +419,9 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
> >                                          * the next higher trip point
> >                                          */
> >                                         tz->trips.active[i-1].temperature =
> > -                                               (tz->trips.active[i-2].temperature <
> > -                                               celsius_to_deci_kelvin(act) ?
> > -                                               tz->trips.active[i-2].temperature :
> > -                                               celsius_to_deci_kelvin(act));
> > +                                               min_t(unsigned long,
> > +                                                     tz->trips.active[i-2].temperature,
> > +                                                     celsius_to_deci_kelvin(act));
> >
> >                                 break;
> >                         } else {
> > --
> > 2.25.1
> >

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

      reply	other threads:[~2023-03-31  8:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28  3:16 [PATCH] ACPI: thermal: replace ternary operator with min_t() Jiangshan Yi
2023-03-30 17:11 ` Rafael J. Wysocki
2023-03-31  8:58   ` David Laight [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=8781eb11ce42448aa9cd206168cb22db@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=13667453960@163.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=yijiangshan@kylinos.cn \
    /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