lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <50b9ca3f-36e8-d13b-672c-5e72b6158869@ti.com>
Date:   Tue, 19 May 2020 10:46:43 -0400
From:   "Andrew F. Davis" <afd@...com>
To:     Dan Murphy <dmurphy@...com>, <sre@...nel.org>
CC:     <sspatil@...roid.com>, <linux-pm@...r.kernel.org>,
        <robh@...nel.org>, <linux-kernel@...r.kernel.org>,
        <devicetree@...r.kernel.org>,
        Ricardo Rivera-Matos <r-rivera-matos@...com>
Subject: Re: [PATCH v7 3/3] power: supply: bq25150 introduce the bq25150

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

> +				i = i - 1;
> +				break;
> +			}
> +		}
> +	}
> +
> +	return regmap_write(bq2515x->regmap, BQ2515X_ILIMCTRL, i);
> +}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ