All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vaittinen, Matti" <Matti.Vaittinen@fi.rohmeurope.com>
To: "andy.shevchenko@gmail.com" <andy.shevchenko@gmail.com>
Cc: "mark.rutland@arm.com" <mark.rutland@arm.com>,
	"milo.kim@ti.com" <milo.kim@ti.com>,
	"andrei.stefanescu@microchip.com"
	<andrei.stefanescu@microchip.com>,
	"rafael@kernel.org" <rafael@kernel.org>,
	"tony@atomide.com" <tony@atomide.com>,
	"linus.walleij@linaro.org" <linus.walleij@linaro.org>,
	"brendanhiggins@google.com" <brendanhiggins@google.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"yamada.masahiro@socionext.com" <yamada.masahiro@socionext.com>,
	"linux-omap@vger.kernel.org" <linux-omap@vger.kernel.org>,
	"vincenzo.frascino@arm.com" <vincenzo.frascino@arm.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"linux-samsung-soc@vger.kernel.org"
	<linux-samsung-soc@vger.kernel.org>,
	"herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
	"b.zolnierkie@samsung.com" <b.zolnierkie@samsung.com>,
	"krzk@kernel.org" <krzk@kernel.org>,
	"bgolaszewski@baylibre.com" <bgolaszewski@baylibre.com>,
	"wens@csie.org" <wens@csie.org>,
	"agross@kernel.org" <agross@kernel.org>,
	"Laine, Markus" <Markus.Laine@fi.rohmeurope.com>,
	"bp@suse.de" <bp@suse.de>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"zaslonko@linux.ibm.com" <zaslonko@linux.ibm.com>,
	"ckeepax@opensource.cirrus.com" <ckeepax@opensource.cirrus.com>,
	"arnd@arndb.de" <arnd@arndb.de>,
	"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
	"linux-arm-msm@vger.kernel.org" <linux-arm-msm@vger.kernel.org>,
	"rf@opensource.cirrus.com" <rf@opensource.cirrus.com>,
	"broonie@kernel.org" <broonie@kernel.org>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"sre@kernel.org" <sre@kernel.org>,
	"davidgow@google.com" <davidgow@google.com>,
	"skhan@linuxfoundation.org" <skhan@linuxfoundation.org>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"dan.j.williams@intel.com" <dan.j.williams@intel.com>,
	"bjorn.andersson@linaro.org" <bjorn.andersson@linaro.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"support.opensource@diasemi.com" <support.opensource@diasemi.com>,
	"sbkim73@samsung.com" <sbkim73@samsung.com>,
	"patches@opensource.cirrus.com" <patches@opensource.cirrus.com>,
	"rdunlap@infradead.org" <rdunlap@infradead.org>,
	"lgirdwood@gmail.com" <lgirdwood@gmail.com>,
	"talgi@mellanox.com" <talgi@mellanox.com>,
	"Mutanen, Mikko" <Mikko.Mutanen@fi.rohmeurope.com>,
	"robh+dt@kernel.org" <robh+dt@kernel.org>,
	"uwe@kleine-koenig.org" <uwe@kleine-koenig.org>,
	"mhiramat@kernel.org" <mhiramat@kernel.org>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"olteanv@gmail.com" <olteanv@gmail.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"mazziesaccount@gmail.com" <mazziesaccount@gmail.com>
Subject: Re: [SPF Softfail] Re: [PATCH v7 03/10] lib: add linear ranges helpers
Date: Thu, 2 Apr 2020 04:03:03 +0000	[thread overview]
Message-ID: <bbdf3a3e12bd2ba11a019192e492d135f92634cc.camel@fi.rohmeurope.com> (raw)
In-Reply-To: <CAHp75Vd24w6dqqCYH46GKnJ5Nzase6LdVgSSVwQ3FEzMd5gsYA@mail.gmail.com>

Hello Andy,

On Wed, 2020-04-01 at 17:42 +0300, Andy Shevchenko wrote:
> On Wed, Apr 1, 2020 at 4:18 PM Vaittinen, Matti
> <Matti.Vaittinen@fi.rohmeurope.com> wrote:
> > On Wed, 2020-04-01 at 15:39 +0300, Andy Shevchenko wrote:
> > > On Wed, Apr 1, 2020 at 1:09 PM Vaittinen, Matti
> > > <Matti.Vaittinen@fi.rohmeurope.com> wrote:
> > > > On Tue, 2020-03-31 at 17:05 +0300, Andy Shevchenko wrote:
> > > > > On Tue, Mar 31, 2020 at 03:23:03PM +0300, Matti Vaittinen
> > > > > wrote:
> > > > > > +int linear_range_get_selector_low_array(const struct
> > > > > > linear_range
> > > > > > *r,
> > > > > > +                                   int ranges, unsigned
> > > > > > int
> > > > > > val,
> > > > > > +                                   unsigned int *selector,
> > > > > > bool
> > > > > > *found)
> > > > > > +{
> > > > > > +   int i;
> > > > > > +   int ret = -EINVAL;
> > > > > > +
> > > > > > +   for (i = 0; i < ranges; i++) {
> > > > > > +           int tmpret;
> > > > > > +
> > > > > > +           tmpret = linear_range_get_selector_low(&r[i],
> > > > > > val,
> > > > > > selector,
> > > > > > +                                                  found);
> > > > > > +
> > > > > > +           if (!tmpret)
> > > > > > +                   ret = 0;
> > > > > > +
> > > > > > +           if (*found)
> > > > > > +                   break;
> > > > > > +   }
> > > > > > +
> > > > > > +   return ret;
> > > > > > +}
> 
> Looked again at the code of the callee.
> So, *found becomes true if and only if the return is 0

Yes. If found is true, then ret is 0.

>  (or other way
> around if you prefer).

No. Not other way around. Ret can be 0 and found false. This is what we
need to handle. Ret means we found range value smaller than given
input. Found means also the given input was in range.

> Now I'm wondering why you need 'found' at all?

To separate case where given input was in range.

> It means above may be as simple as
> 
>       int i;
>       int ret = -EINVAL;
> 
>       for (i = 0; i < ranges; i++) {
>                ret = linear_range_get_selector_low(&r[i], val,
> selector, found);
>                if (*found)
>                        break;
>       }

No. It can't. Here we get wrong return value if one of the calls to
linear_range_get_selector_low() return zero with found being false and
subsequent calls return non zero ret. Then we actually found lower-
than-given-input value from one of the ranges and updated the selector
(that would be usable for example for regulator voltage control) but
end up returning non zero ret as the subsequent calls to
linear_range_get_selector_low() do overwrite the ret.

OTOH, we should not stop for first range having zero ret if found is
false because some of the ranges may have range where given input is
in-range (and this is considered better value).

> 
>       return ret;
> 
> or assuming 'found' will gone

No. We should not drop the 'found'.

> 
>   int i
>   int ret = -EINVAL;
> 
>   for (i = 0; i < ranges && ret; i++) {
>       ret = linear_range_get_selector_low(&r[i], val, selector);
>   }
>   return ret;
> 
> ...
> 
> >  * value. If given value is found to be in a range scannins is
> > I think it is but I am open to all suggestions how to improve doc!
> 
> Thanks. At least fix a typo: scannins -> scannings
> 

Thanks :) I'll fix it

> ...
> 
> > Compared to:
> > for (i = 0; i < ranges; i++) {
> >         ret = ...
> > }
> > 
> > I wouldn't say so.
> > 
> > As I explained, we need to have "temporary" return value in any
> > case
> > because we need to return 0 if any of the calls to
> > linear_range_get_selector_low() returned 0. Return value 0 from
> > linear_range_get_selector_low() means we found "matching" value
> > (lower
> > than input) and selector was updated (although input value was not
> > in
> > range).
> 
> See above.


Best Regards
	--Matti
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

  reply	other threads:[~2020-04-02  4:03 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-31 12:20 [PATCH v7 00/10] Support ROHM BD99954 charger IC Matti Vaittinen
2020-03-31 12:21 ` [PATCH v7 01/10] dt-bindings: battery: add new battery parameters Matti Vaittinen
2020-03-31 12:22 ` [PATCH v7 02/10] dt_bindings: ROHM BD99954 Charger Matti Vaittinen
2020-03-31 12:23 ` [PATCH v7 03/10] lib: add linear ranges helpers Matti Vaittinen
2020-03-31 14:05   ` Andy Shevchenko
2020-04-01 10:09     ` [SPF Softfail] " Vaittinen, Matti
2020-04-01 12:39       ` Andy Shevchenko
2020-04-01 13:18         ` Vaittinen, Matti
2020-04-01 14:42           ` Andy Shevchenko
2020-04-02  4:03             ` Vaittinen, Matti [this message]
2020-03-31 12:23 ` [PATCH v7 04/10] lib/test_linear_ranges: add a test for the 'linear_ranges' Matti Vaittinen
2020-03-31 18:08   ` Brendan Higgins
2020-04-01  8:45     ` Vaittinen, Matti
2020-04-01 18:48       ` Brendan Higgins
2020-04-02 15:39         ` Vaittinen, Matti
2020-03-31 12:24 ` [PATCH v7 05/10] power: supply: bd70528: rename linear_range to avoid collision Matti Vaittinen
2020-03-31 12:24 ` [PATCH v7 00/10] Support ROHM BD99954 charger IC Ard Biesheuvel
2020-03-31 14:02   ` Vaittinen, Matti
2020-03-31 14:21     ` andriy.shevchenko
2020-03-31 12:25 ` [PATCH v7 06/10] regulator: use linear_ranges helper Matti Vaittinen
2020-04-01 10:17   ` Mark Brown
2020-03-31 12:26 ` [PATCH v7 07/10] power: supply: bd70528: use linear ranges Matti Vaittinen
2020-03-31 12:26 ` [PATCH v7 08/10] power: supply: add battery parameters Matti Vaittinen
2020-03-31 12:28 ` [PATCH v7 09/10] power: supply: Support ROHM bd99954 charger Matti Vaittinen
2020-03-31 14:19   ` Andy Shevchenko
2020-04-01  8:08     ` Vaittinen, Matti
2020-03-31 12:29 ` [PATCH v7 10/10] power: supply: Fix Kconfig help text indentiation Matti Vaittinen

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=bbdf3a3e12bd2ba11a019192e492d135f92634cc.camel@fi.rohmeurope.com \
    --to=matti.vaittinen@fi.rohmeurope.com \
    --cc=Markus.Laine@fi.rohmeurope.com \
    --cc=Mikko.Mutanen@fi.rohmeurope.com \
    --cc=agross@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andrei.stefanescu@microchip.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=arnd@arndb.de \
    --cc=b.zolnierkie@samsung.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=bp@suse.de \
    --cc=brendanhiggins@google.com \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=dan.j.williams@intel.com \
    --cc=davem@davemloft.net \
    --cc=davidgow@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=krzk@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mazziesaccount@gmail.com \
    --cc=mhiramat@kernel.org \
    --cc=milo.kim@ti.com \
    --cc=olteanv@gmail.com \
    --cc=patches@opensource.cirrus.com \
    --cc=rafael@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=rf@opensource.cirrus.com \
    --cc=robh+dt@kernel.org \
    --cc=sbkim73@samsung.com \
    --cc=skhan@linuxfoundation.org \
    --cc=sre@kernel.org \
    --cc=support.opensource@diasemi.com \
    --cc=talgi@mellanox.com \
    --cc=tglx@linutronix.de \
    --cc=tony@atomide.com \
    --cc=uwe@kleine-koenig.org \
    --cc=vincenzo.frascino@arm.com \
    --cc=wens@csie.org \
    --cc=yamada.masahiro@socionext.com \
    --cc=zaslonko@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.