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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <2c05eb25-a21a-40f5-a573-09f9ddd4c578@wanadoo.fr>
Date: Thu, 13 Jun 2024 22:28:44 +0200
From: Christophe JAILLET <christophe.jaillet@...adoo.fr>
To: git@...tzsch.eu, Pavel Machek <pavel@....cz>, Lee Jones <lee@...nel.org>,
 Rob Herring <robh@...nel.org>,
 Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
 Conor Dooley <conor+dt@...nel.org>,
 "Gustavo A. R. Silva" <gustavoars@...nel.org>,
 Bjorn Andersson <andersson@...nel.org>,
 Konrad Dybcio <konrad.dybcio@...aro.org>,
 Trilok Soni <quic_tsoni@...cinc.com>, Kees Cook <kees@...nel.org>
Cc: linux-leds@...r.kernel.org, devicetree@...r.kernel.org,
 linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org,
 linux-arm-msm@...r.kernel.org, ~postmarketos/upstreaming@...ts.sr.ht,
 phone-devel@...r.kernel.org
Subject: Re: [PATCH v3 2/3] leds: sy7802: Add support for Silergy SY7802 flash
 LED controller

Le 12/06/2024 à 23:01, André Apitzsch via B4 Relay a écrit :
> From: André Apitzsch <git@...tzsch.eu>
> 
> The SY7802 is a current-regulated charge pump which can regulate two
> current levels for Flash and Torch modes.
> 
> It is a high-current synchronous boost converter with 2-channel high
> side current sources. Each channel is able to deliver 900mA current.
> 
> Signed-off-by: André Apitzsch <git@...tzsch.eu>
> ---
>   drivers/leds/flash/Kconfig       |  11 +
>   drivers/leds/flash/Makefile      |   1 +
>   drivers/leds/flash/leds-sy7802.c | 546 +++++++++++++++++++++++++++++++++++++++
>   3 files changed, 558 insertions(+)
> 

Hi,

...

> +static int sy7802_probe_dt(struct sy7802 *chip)
> +{
> +	struct device_node *np = dev_of_node(chip->dev);
> +	struct device_node *child;
> +	int child_num;
> +	int ret;
> +
> +	regmap_write(chip->regmap, SY7802_REG_ENABLE, SY7802_MODE_OFF);
> +	regmap_write(chip->regmap, SY7802_REG_TORCH_BRIGHTNESS, LED_OFF);
> +
> +	child_num = 0;
> +	for_each_available_child_of_node(np, child) {

Using for_each_available_child_of_node_scoped() would slightly simplify 
the code below.

> +		struct sy7802_led *led = chip->leds + child_num;
> +
> +		led->chip = chip;
> +		led->led_id = child_num;
> +
> +		ret = sy7802_init_flash_properties(chip->dev, led, child);
> +		if (ret) {
> +			of_node_put(child);
> +			return ret;
> +		}
> +
> +		ret = sy7802_led_register(chip->dev, led, child);
> +		if (ret) {
> +			of_node_put(child);
> +			return ret;
> +		}
> +
> +		child_num++;
> +	}
> +	return 0;
> +}

...

> +static int sy7802_probe(struct i2c_client *client)
> +{
> +	struct device *dev = &client->dev;
> +	struct sy7802 *chip;
> +	size_t count;
> +	int ret;
> +
> +	count = device_get_child_node_count(dev);
> +	if (!count || count > SY7802_MAX_LEDS)
> +		return dev_err_probe(dev, -EINVAL, "Invalid amount of LED nodes %zu\n", count);
> +
> +	chip = devm_kzalloc(dev, struct_size(chip, leds, count), GFP_KERNEL);
> +	if (!chip)
> +		return -ENOMEM;
> +
> +	chip->num_leds = count;
> +
> +	chip->dev = dev;
> +	i2c_set_clientdata(client, chip);
> +
> +	chip->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
> +	ret = PTR_ERR_OR_ZERO(chip->enable_gpio);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "Failed to request enable gpio\n");
> +
> +	chip->vin_regulator = devm_regulator_get(dev, "vin");
> +	ret = PTR_ERR_OR_ZERO(chip->vin_regulator);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "Failed to request regulator\n");
> +
> +	ret = regulator_enable(chip->vin_regulator);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "Failed to enable regulator\n");
> +
> +	ret = devm_mutex_init(dev, &chip->mutex);
> +	if (ret)
> +		return ret;

The regulator_enable() above is not balanced if we return here.

> +
> +	mutex_lock(&chip->mutex);
> +
> +	chip->regmap = devm_regmap_init_i2c(client, &sy7802_regmap_config);
> +	if (IS_ERR(chip->regmap)) {
> +		ret = PTR_ERR(chip->regmap);
> +		dev_err(dev, "Failed to allocate register map: %d\n", ret);

dev_err_probe() to be consistent with the code above?

> +		goto error;
> +	}
> +
> +	ret = devm_add_action(dev, sy7802_chip_disable_action, chip);

I think that having 2 devm_add_action_or_reset() each at a logical 
location, 1 for regulator_disable() and 1 for sy7802_disable() would help.

> +	if (ret)
> +		goto error;
> +
> +	ret = sy7802_probe_dt(chip);
> +	if (ret < 0)
> +		goto error;
> +
> +	sy7802_enable(chip);
> +
> +	ret = sy7802_chip_check(chip);
> +	if (ret) {
> +		sy7802_disable(chip);
> +		goto error;
> +	}
> +
> +	mutex_unlock(&chip->mutex);
> +
> +	return 0;
> +
> +error:
> +	regulator_disable(chip->vin_regulator);
> +	mutex_unlock(&chip->mutex);
> +	return ret;
> +}

CJ

...


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ