Le 12/06/2024 à 23:01, André Apitzsch via B4 Relay a écrit :
From: André Apitzsch <git@xxxxxxxxxxx> 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@xxxxxxxxxxx> --- 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 ...