Commit af80559b authored by Wolfram Sang's avatar Wolfram Sang Committed by Wolfram Sang

i2c: replace i2c_new_secondary_device with an ERR_PTR variant

In the general move to have i2c_new_*_device functions which return
ERR_PTR instead of NULL, this patch converts i2c_new_secondary_device().

There are only few users, so this patch converts the I2C core and all
users in one go. The function gets renamed to i2c_new_ancillary_device()
so out-of-tree users will get a build failure to understand they need to
adapt their error checking code.
Signed-off-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com> # adv748x
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> # adv7511 + adv7604
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> # adv7604
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent bbeb6b6c
...@@ -981,10 +981,10 @@ static int adv7511_init_cec_regmap(struct adv7511 *adv) ...@@ -981,10 +981,10 @@ static int adv7511_init_cec_regmap(struct adv7511 *adv)
{ {
int ret; int ret;
adv->i2c_cec = i2c_new_secondary_device(adv->i2c_main, "cec", adv->i2c_cec = i2c_new_ancillary_device(adv->i2c_main, "cec",
ADV7511_CEC_I2C_ADDR_DEFAULT); ADV7511_CEC_I2C_ADDR_DEFAULT);
if (!adv->i2c_cec) if (IS_ERR(adv->i2c_cec))
return -EINVAL; return PTR_ERR(adv->i2c_cec);
i2c_set_clientdata(adv->i2c_cec, adv); i2c_set_clientdata(adv->i2c_cec, adv);
adv->regmap_cec = devm_regmap_init_i2c(adv->i2c_cec, adv->regmap_cec = devm_regmap_init_i2c(adv->i2c_cec,
...@@ -1165,20 +1165,20 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id) ...@@ -1165,20 +1165,20 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
adv7511_packet_disable(adv7511, 0xffff); adv7511_packet_disable(adv7511, 0xffff);
adv7511->i2c_edid = i2c_new_secondary_device(i2c, "edid", adv7511->i2c_edid = i2c_new_ancillary_device(i2c, "edid",
ADV7511_EDID_I2C_ADDR_DEFAULT); ADV7511_EDID_I2C_ADDR_DEFAULT);
if (!adv7511->i2c_edid) { if (IS_ERR(adv7511->i2c_edid)) {
ret = -EINVAL; ret = PTR_ERR(adv7511->i2c_edid);
goto uninit_regulators; goto uninit_regulators;
} }
regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR, regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR,
adv7511->i2c_edid->addr << 1); adv7511->i2c_edid->addr << 1);
adv7511->i2c_packet = i2c_new_secondary_device(i2c, "packet", adv7511->i2c_packet = i2c_new_ancillary_device(i2c, "packet",
ADV7511_PACKET_I2C_ADDR_DEFAULT); ADV7511_PACKET_I2C_ADDR_DEFAULT);
if (!adv7511->i2c_packet) { if (IS_ERR(adv7511->i2c_packet)) {
ret = -EINVAL; ret = PTR_ERR(adv7511->i2c_packet);
goto err_i2c_unregister_edid; goto err_i2c_unregister_edid;
} }
......
...@@ -964,7 +964,7 @@ struct i2c_client *devm_i2c_new_dummy_device(struct device *dev, ...@@ -964,7 +964,7 @@ struct i2c_client *devm_i2c_new_dummy_device(struct device *dev,
EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device); EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device);
/** /**
* i2c_new_secondary_device - Helper to get the instantiated secondary address * i2c_new_ancillary_device - Helper to get the instantiated secondary address
* and create the associated device * and create the associated device
* @client: Handle to the primary client * @client: Handle to the primary client
* @name: Handle to specify which secondary address to get * @name: Handle to specify which secondary address to get
...@@ -983,9 +983,9 @@ EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device); ...@@ -983,9 +983,9 @@ EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device);
* cell whose "reg-names" value matches the slave name. * cell whose "reg-names" value matches the slave name.
* *
* This returns the new i2c client, which should be saved for later use with * This returns the new i2c client, which should be saved for later use with
* i2c_unregister_device(); or NULL to indicate an error. * i2c_unregister_device(); or an ERR_PTR to describe the error.
*/ */
struct i2c_client *i2c_new_secondary_device(struct i2c_client *client, struct i2c_client *i2c_new_ancillary_device(struct i2c_client *client,
const char *name, const char *name,
u16 default_addr) u16 default_addr)
{ {
...@@ -1000,9 +1000,9 @@ struct i2c_client *i2c_new_secondary_device(struct i2c_client *client, ...@@ -1000,9 +1000,9 @@ struct i2c_client *i2c_new_secondary_device(struct i2c_client *client,
} }
dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr); dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr);
return i2c_new_dummy(client->adapter, addr); return i2c_new_dummy_device(client->adapter, addr);
} }
EXPORT_SYMBOL_GPL(i2c_new_secondary_device); EXPORT_SYMBOL_GPL(i2c_new_ancillary_device);
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
......
...@@ -183,14 +183,14 @@ static int adv748x_initialise_clients(struct adv748x_state *state) ...@@ -183,14 +183,14 @@ static int adv748x_initialise_clients(struct adv748x_state *state)
int ret; int ret;
for (i = ADV748X_PAGE_DPLL; i < ADV748X_PAGE_MAX; ++i) { for (i = ADV748X_PAGE_DPLL; i < ADV748X_PAGE_MAX; ++i) {
state->i2c_clients[i] = i2c_new_secondary_device( state->i2c_clients[i] = i2c_new_ancillary_device(
state->client, state->client,
adv748x_default_addresses[i].name, adv748x_default_addresses[i].name,
adv748x_default_addresses[i].default_addr); adv748x_default_addresses[i].default_addr);
if (state->i2c_clients[i] == NULL) { if (IS_ERR(state->i2c_clients[i])) {
adv_err(state, "failed to create i2c client %u\n", i); adv_err(state, "failed to create i2c client %u\n", i);
return -ENOMEM; return PTR_ERR(state->i2c_clients[i]);
} }
ret = adv748x_configure_regmap(state, i); ret = adv748x_configure_regmap(state, i);
......
...@@ -2862,10 +2862,8 @@ static void adv76xx_unregister_clients(struct adv76xx_state *state) ...@@ -2862,10 +2862,8 @@ static void adv76xx_unregister_clients(struct adv76xx_state *state)
{ {
unsigned int i; unsigned int i;
for (i = 1; i < ARRAY_SIZE(state->i2c_clients); ++i) { for (i = 1; i < ARRAY_SIZE(state->i2c_clients); ++i)
if (state->i2c_clients[i]) i2c_unregister_device(state->i2c_clients[i]);
i2c_unregister_device(state->i2c_clients[i]);
}
} }
static struct i2c_client *adv76xx_dummy_client(struct v4l2_subdev *sd, static struct i2c_client *adv76xx_dummy_client(struct v4l2_subdev *sd,
...@@ -2878,14 +2876,14 @@ static struct i2c_client *adv76xx_dummy_client(struct v4l2_subdev *sd, ...@@ -2878,14 +2876,14 @@ static struct i2c_client *adv76xx_dummy_client(struct v4l2_subdev *sd,
struct i2c_client *new_client; struct i2c_client *new_client;
if (pdata && pdata->i2c_addresses[page]) if (pdata && pdata->i2c_addresses[page])
new_client = i2c_new_dummy(client->adapter, new_client = i2c_new_dummy_device(client->adapter,
pdata->i2c_addresses[page]); pdata->i2c_addresses[page]);
else else
new_client = i2c_new_secondary_device(client, new_client = i2c_new_ancillary_device(client,
adv76xx_default_addresses[page].name, adv76xx_default_addresses[page].name,
adv76xx_default_addresses[page].default_addr); adv76xx_default_addresses[page].default_addr);
if (new_client) if (!IS_ERR(new_client))
io_write(sd, io_reg, new_client->addr << 1); io_write(sd, io_reg, new_client->addr << 1);
return new_client; return new_client;
...@@ -3516,15 +3514,19 @@ static int adv76xx_probe(struct i2c_client *client, ...@@ -3516,15 +3514,19 @@ static int adv76xx_probe(struct i2c_client *client,
} }
for (i = 1; i < ADV76XX_PAGE_MAX; ++i) { for (i = 1; i < ADV76XX_PAGE_MAX; ++i) {
struct i2c_client *dummy_client;
if (!(BIT(i) & state->info->page_mask)) if (!(BIT(i) & state->info->page_mask))
continue; continue;
state->i2c_clients[i] = adv76xx_dummy_client(sd, i); dummy_client = adv76xx_dummy_client(sd, i);
if (!state->i2c_clients[i]) { if (IS_ERR(dummy_client)) {
err = -EINVAL; err = PTR_ERR(dummy_client);
v4l2_err(sd, "failed to create i2c client %u\n", i); v4l2_err(sd, "failed to create i2c client %u\n", i);
goto err_i2c; goto err_i2c;
} }
state->i2c_clients[i] = dummy_client;
} }
INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug, INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug,
......
...@@ -473,7 +473,7 @@ extern struct i2c_client * ...@@ -473,7 +473,7 @@ extern struct i2c_client *
devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address); devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address);
extern struct i2c_client * extern struct i2c_client *
i2c_new_secondary_device(struct i2c_client *client, i2c_new_ancillary_device(struct i2c_client *client,
const char *name, const char *name,
u16 default_addr); u16 default_addr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment