Re: [PATCH v2 08/12] leds: flash: add support for Samsung S2M series PMIC flash LED device

From: André Draszik

Date: Thu Feb 05 2026 - 05:57:34 EST


Hi,

On Mon, 2026-01-26 at 00:37 +0530, Kaustabh Chakraborty wrote:

[...]

> diff --git a/drivers/leds/flash/leds-s2m-flash.c b/drivers/leds/flash/leds-s2m-flash.c
> new file mode 100644
> index 0000000000000..1be2745c475bf

[...]

> +
> +static int s2m_fled_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct sec_pmic_dev *pmic_drvdata = dev_get_drvdata(dev->parent);
> + struct s2m_fled *priv;
> + struct fwnode_handle *child;

[...]

> +
> + device_for_each_child_node(dev, child) {

If you switch to device_for_each_child_node_scoped(), you can get rid
of the goto and the struct fwnode_handle *child declaration at the top,
and you plug your leak in your early error return a few lines below.

> + u32 reg;
> +
> + if (fwnode_property_read_u32(child, "reg", &reg))
> + goto next_child;
> +
> + if (reg >= spec->num_channels) {
> + dev_warn(dev, "channel %d is non-existent\n", reg);
> + goto next_child;
> + }
> +
> + if (priv[reg].dev) {
> + dev_warn(dev, "duplicate node for channel %d\n", reg);
> + goto next_child;
> + }
> +
> + priv[reg].dev = dev;
> + priv[reg].regmap = regmap;
> + priv[reg].channel = (u8)reg;
> + priv[reg].spec = spec;
> + priv[reg].pmic_revision = pmic_drvdata->revision;
> +
> + ret = devm_mutex_init(dev, &priv[reg].lock);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to create mutex lock\n");
> +
> + ret = s2m_fled_init_channel(dev, child, &priv[reg]);
> + if (ret < 0)
> + dev_warn(dev, "channel init failed (%d)\n", ret);
> +
> +next_child:
> + fwnode_handle_put(child);
> + }
> +
> + return 0;
> +}

Cheers,
Andre'