PCI/pwrctrl: tc9563: Use devm-managed I2C dummy device allocation

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 <lorenzo.bianconi@oss.qualcomm.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Link: https://patch.msgid.link/20260729-pci-pwrctrl-tc956x-regmap-v1-2-20ce61a3ce12@oss.qualcomm.com
This commit is contained in:
Lorenzo Bianconi 2026-07-29 15:34:26 +02:00 committed by Bjorn Helgaas
parent ebaa06fc5b
commit 854fc493df

View File

@ -105,7 +105,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;
};
@ -504,6 +503,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);
@ -520,15 +520,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");
@ -606,7 +605,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;
}
@ -618,7 +616,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);
}