mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Joshua Crofts <joshua.crofts1@gmail.com>
Cc: Yang Zi <2959243019@qq.com>,
	lorenzo@kernel.org, linux-iio@vger.kernel.org,
	dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: humidity: hts221: fix division by zero in calibration data parsing
Date: Mon, 31 Aug 2026 01:17:45 +0100	[thread overview]
Message-ID: <20260831011745.1ac064c5@jic23-huawei> (raw)
In-Reply-To: <20260825113958.000038b8@gmail.com>

On Tue, 25 Aug 2026 11:39:58 +0200
Joshua Crofts <joshua.crofts1@gmail.com> wrote:

> On Tue, 25 Aug 2026 17:21:10 +0800
> Yang Zi <2959243019@qq.com> wrote:
> 
> > hts221_parse_temp_caldata() and hts221_parse_rh_caldata() compute the
> > sensor slope as ((cal_y1 - cal_y0) * 8000) / (cal_x1 - cal_x0). If the
> > device reports cal_x1 == cal_x0 the division causes a divide-by-zero
> > error.
> > 
> > Return -EINVAL when cal_x1 == cal_x0 in both functions before performing
> > the division.
> > 
> > Signed-off-by: Yang Zi <2959243019@qq.com>
> > ---
> > diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c
> > index bfeb0a60d3af..7d1f04951d8b 100644
> > --- a/drivers/iio/humidity/hts221_core.c
> > +++ b/drivers/iio/humidity/hts221_core.c
> > @@ -288,6 +288,9 @@ static int hts221_parse_temp_caldata(struct hts221_hw *hw)
> >          return err;
> >      cal_x1 = le16_to_cpu(val);
> >  
> > +    if (cal_x1 == cal_x0)
> > +        return -EINVAL;
> > +
> >      slope = &hw->sensors[HTS221_SENSOR_T].slope;
> >      b_gen = &hw->sensors[HTS221_SENSOR_T].b_gen;
> >  
> > @@ -327,6 +330,9 @@ static int hts221_parse_rh_caldata(struct hts221_hw *hw)
> >          return err;
> >      cal_x1 = le16_to_cpu(val);
> >  
> > +    if (cal_x1 == cal_x0)
> > +        return -EINVAL;
> > +
> >      slope = &hw->sensors[HTS221_SENSOR_H].slope;
> >      b_gen = &hw->sensors[HTS221_SENSOR_H].b_gen;
> >  
> > 
> >   
> 
> This definitely needs a Fixes: tag, otherwise LGTM.
Looks like hardening to me rather than a fix. Given those algs come
off the datasheet and the div zero case makes no sense, I'd not expect
the hardware to ever return a combination that triggers this.

With that said, the cost in catching it is low.

I was going to pick this up, but seems patch is corrupted.
Looks like we have tabs replaced with white space but I haven't checked closely.

Please fix that up and send a v2.

thanks,

Jonathan


> 
> Feel free to carry my review tag.
> 
> Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
> 
> PS, a bit of process info: I noticed Sashiko (sashiko.dev) failed to apply your
> patches. To prevent this from happening in the future, please use the `--base` flag
> when running `git format-patch` to specify which commit it should be applied onto.
> 


  reply	other threads:[~2026-08-31  0:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  9:21 Yang Zi
2026-08-25  9:39 ` Joshua Crofts
2026-08-31  0:17   ` Jonathan Cameron [this message]
2026-08-26 14:09 ` Andy Shevchenko
2026-08-31  0:00   ` Jonathan Cameron
2026-08-31  7:05     ` Andy Shevchenko
2026-09-01  1:35       ` Jonathan Cameron
2026-09-01  6:53         ` Andy Shevchenko

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=20260831011745.1ac064c5@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=2959243019@qq.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=joshua.crofts1@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=nuno.sa@analog.com \
    /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®