Devicetree
 help / color / mirror / Atom feed
From: Ricardo Rivera-Matos <r-rivera-matos@ti.com>
To: "Andrew F. Davis" <afd@ti.com>, Dan Murphy <dmurphy@ti.com>,
	<sre@kernel.org>
Cc: <sspatil@android.com>, <linux-pm@vger.kernel.org>,
	<robh@kernel.org>, <linux-kernel@vger.kernel.org>,
	<devicetree@vger.kernel.org>
Subject: Re: [PATCH v7 3/3] power: supply: bq25150 introduce the bq25150
Date: Tue, 19 May 2020 12:15:51 -0500	[thread overview]
Message-ID: <1eaa381f-0c05-8bcf-ce30-96104ddd9080@ti.com> (raw)
In-Reply-To: <50b9ca3f-36e8-d13b-672c-5e72b6158869@ti.com>


On 5/19/20 9:46 AM, Andrew F. Davis wrote:
> On 5/19/20 10:19 AM, Dan Murphy wrote:
>> +static int bq2515x_set_ilim_lvl(struct bq2515x_device *bq2515x, int val)
>> +{
>> +	int i;
>> +
>> +	if (val > BQ2515X_ILIM_MAX || val < BQ2515X_ILIM_MIN)
>> +		return -EINVAL;
> Clamp to these limits, not reject. Or better, modify the below loop so
> it clamps to the highest or lowest value in bq2515x_ilim_lvl_values[],
> then drop these #defines.
>
>> +
>> +	for (i = 0; i < ARRAY_SIZE(bq2515x_ilim_lvl_values); i++) {
>> +		if (val == bq2515x_ilim_lvl_values[i])
>> +			break;
>> +
>> +		if (val > bq2515x_ilim_lvl_values[i - 1] &&
> Index out of bounds for the i = 0 case.
>
>> +		    val < bq2515x_ilim_lvl_values[i]) {
>> +			if (val - bq2515x_ilim_lvl_values[i - 1] <
>> +			    bq2515x_ilim_lvl_values[i] - val) {
> You are still missing the case where the value is closer to the [i]
> element, you check that it is between [i-1] and [i], but only chose
> [i-1] when it is closer to that than [i] but equal and greater case is
> missing.
>
> Given this sets input current limits, would instead always rounding down
> be the safer option?
>
> Andrew
ACK. I am going to rewrite that altogether.
>
>> +				i = i - 1;
>> +				break;
>> +			}
>> +		}
>> +	}
>> +
>> +	return regmap_write(bq2515x->regmap, BQ2515X_ILIMCTRL, i);
>> +}

      reply	other threads:[~2020-05-19 17:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19 14:19 [PATCH v7 0/3] Add JEITA properties and introduce the bq2515x charger Dan Murphy
2020-05-19 14:19 ` [PATCH v7 1/3] power_supply: Add additional health properties to the header Dan Murphy
2020-05-19 14:19 ` [PATCH v7 2/3] Add the bindings for the bq25150 and bq25155 500mA charging ICs from Texas Instruments Dan Murphy
2020-05-19 14:19 ` [PATCH v7 3/3] power: supply: bq25150 introduce the bq25150 Dan Murphy
2020-05-19 14:46   ` Andrew F. Davis
2020-05-19 17:15     ` Ricardo Rivera-Matos [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=1eaa381f-0c05-8bcf-ce30-96104ddd9080@ti.com \
    --to=r-rivera-matos@ti.com \
    --cc=afd@ti.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmurphy@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sre@kernel.org \
    --cc=sspatil@android.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