Re: [PATCH 2/2] PCI/pwrctrl: tc9563: use devm-managed I2C dummy device allocation

Manivannan Sadhasivam <[email protected]>
Newsgroups org.kernel.vger.linux-pci
Message-ID <z6hu4e4qey5kg6vsqs2rhonhiaoz2i43py7xsxrkuwzev2fukw@qx265rzsv2k6>
On Wed, Jul 29, 2026 at 03:34:26PM +0200, Lorenzo Bianconi wrote:
> Switch from i2c_new_dummy_device() to its devm variant
> devm_i2c_new_dummy_device() so the I2C client is automatically
> unregistered when the driver is removed or on probe failure.
> 
> This allows removing the manual i2c_unregister_device() calls from
> both the probe error path and the remove function, and lets the
> i2c_client pointer be a local variable in probe instead of storing
> it in the driver data structure.
> 
> Signed-off-by: Lorenzo Bianconi <[email protected]>

Reviewed-by: Manivannan Sadhasivam <[email protected]>

- Mani

> ---
>  drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c b/drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c
> index 8bccf3abd189..5b05e76f6c80 100644
> --- a/drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c
> +++ b/drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c
> @@ -106,7 +106,6 @@ struct tc9563_pwrctrl {
>  	struct tc9563_pwrctrl_cfg ep_cfg;
>  	struct gpio_desc *reset_gpio;
>  	struct i2c_adapter *adapter;
> -	struct i2c_client *client;
>  	struct regmap *regmap;
>  };
>  
> @@ -505,6 +504,7 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)
>  	enum tc9563_pwrctrl_ports port;
>  	struct tc9563_pwrctrl *tc9563;
>  	struct device_node *i2c_node;
> +	struct i2c_client *client;
>  	int ret, addr;
>  
>  	tc9563 = devm_kzalloc(dev, sizeof(*tc9563), GFP_KERNEL);
> @@ -521,15 +521,14 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)
>  	if (!tc9563->adapter)
>  		return dev_err_probe(dev, -EPROBE_DEFER, "Failed to find I2C adapter\n");
>  
> -	tc9563->client = i2c_new_dummy_device(tc9563->adapter, addr);
> -	if (IS_ERR(tc9563->client)) {
> +	client = devm_i2c_new_dummy_device(dev, tc9563->adapter, addr);
> +	if (IS_ERR(client)) {
>  		dev_err(dev, "Failed to create I2C client\n");
> -		i2c_put_adapter(tc9563->adapter);
> -		return PTR_ERR(tc9563->client);
> +		ret = PTR_ERR(client);
> +		goto remove_i2c;
>  	}
>  
> -	tc9563->regmap = devm_regmap_init_i2c(tc9563->client,
> -					      &tc9563_regmap_config);
> +	tc9563->regmap = devm_regmap_init_i2c(client, &tc9563_regmap_config);
>  	if (IS_ERR(tc9563->regmap)) {
>  		ret = dev_err_probe(dev, PTR_ERR(tc9563->regmap),
>  				    "Failed to allocate register map\n");
> @@ -607,7 +606,6 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)
>  power_off:
>  	tc9563_pwrctrl_power_off(&tc9563->pwrctrl);
>  remove_i2c:
> -	i2c_unregister_device(tc9563->client);
>  	i2c_put_adapter(tc9563->adapter);
>  	return ret;
>  }
> @@ -619,7 +617,6 @@ static void tc9563_pwrctrl_remove(struct platform_device *pdev)
>  					struct tc9563_pwrctrl, pwrctrl);
>  
>  	tc9563_pwrctrl_power_off(&tc9563->pwrctrl);
> -	i2c_unregister_device(tc9563->client);
>  	i2c_put_adapter(tc9563->adapter);
>  }
>  
> 
> -- 
> 2.55.0
> 

-- 
மணிவண்ணன் சதாசிவம்
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.