History

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.

Wolfram Sang committed 7 years ago

Commit af805591 parent bbeb6b65 files · +30 −28Browse files

Unified · Split

5 files
  1. drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +9 −9
  2. drivers/i2c/i2c-core-base.c +5 −5
  3. drivers/media/i2c/adv748x/adv748x-core.c +3 −3
  4. drivers/media/i2c/adv7604.c +12 −10
  5. include/linux/i2c.h +1 −1
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c+9−9
@@ -981,10 +981,10 @@ static int adv7511_init_cec_regmap(struct adv7511 *adv) · 980 unmodified lines
981981 {
982982 int ret;
983983
984− adv->i2c_cec = i2c_new_secondary_device(adv->i2c_main, "cec",
984+ adv->i2c_cec = i2c_new_ancillary_device(adv->i2c_main, "cec",
985985 ADV7511_CEC_I2C_ADDR_DEFAULT);
986− if (!adv->i2c_cec)
987− return -EINVAL;
986+ if (IS_ERR(adv->i2c_cec))
987+ return PTR_ERR(adv->i2c_cec);
988988 i2c_set_clientdata(adv->i2c_cec, adv);
989989
990990 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) · 174 unmodified lines
11651165
11661166 adv7511_packet_disable(adv7511, 0xffff);
11671167
1168− adv7511->i2c_edid = i2c_new_secondary_device(i2c, "edid",
1168+ adv7511->i2c_edid = i2c_new_ancillary_device(i2c, "edid",
11691169 ADV7511_EDID_I2C_ADDR_DEFAULT);
1170− if (!adv7511->i2c_edid) {
1171− ret = -EINVAL;
1170+ if (IS_ERR(adv7511->i2c_edid)) {
1171+ ret = PTR_ERR(adv7511->i2c_edid);
11721172 goto uninit_regulators;
11731173 }
11741174
11751175 regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR,
11761176 adv7511->i2c_edid->addr << 1);
11771177
1178− adv7511->i2c_packet = i2c_new_secondary_device(i2c, "packet",
1178+ adv7511->i2c_packet = i2c_new_ancillary_device(i2c, "packet",
11791179 ADV7511_PACKET_I2C_ADDR_DEFAULT);
1180− if (!adv7511->i2c_packet) {
1181− ret = -EINVAL;
1180+ if (IS_ERR(adv7511->i2c_packet)) {
1181+ ret = PTR_ERR(adv7511->i2c_packet);
11821182 goto err_i2c_unregister_edid;
11831183 }
11841184
drivers/i2c/i2c-core-base.c+5−5
@@ -964,7 +964,7 @@ struct i2c_client *devm_i2c_new_dummy_device(struct device *dev, · 963 unmodified lines
964964 EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device);
965965
966966 /**
967− * i2c_new_secondary_device - Helper to get the instantiated secondary address
967+ * i2c_new_ancillary_device - Helper to get the instantiated secondary address
968968 * and create the associated device
969969 * @client: Handle to the primary client
970970 * @name: Handle to specify which secondary address to get
@@ -983,9 +983,9 @@ EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device); · 12 unmodified lines
983983 * cell whose "reg-names" value matches the slave name.
984984 *
985985 * This returns the new i2c client, which should be saved for later use with
986− * i2c_unregister_device(); or NULL to indicate an error.
986+ * i2c_unregister_device(); or an ERR_PTR to describe the error.
987987 */
988−struct i2c_client *i2c_new_secondary_device(struct i2c_client *client,
988+struct i2c_client *i2c_new_ancillary_device(struct i2c_client *client,
989989 const char *name,
990990 u16 default_addr)
991991 {
@@ -1000,9 +1000,9 @@ struct i2c_client *i2c_new_secondary_device(struct i2c_client *client, · 8 unmodified lines
10001000 }
10011001
10021002 dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr);
1003− return i2c_new_dummy(client->adapter, addr);
1003+ return i2c_new_dummy_device(client->adapter, addr);
10041004 }
1005−EXPORT_SYMBOL_GPL(i2c_new_secondary_device);
1005+EXPORT_SYMBOL_GPL(i2c_new_ancillary_device);
10061006
10071007 /* ------------------------------------------------------------------------- */
10081008
drivers/media/i2c/adv748x/adv748x-core.c+3−3
@@ -183,14 +183,14 @@ static int adv748x_initialise_clients(struct adv748x_state *state) · 182 unmodified lines
183183 int ret;
184184
185185 for (i = ADV748X_PAGE_DPLL; i < ADV748X_PAGE_MAX; ++i) {
186− state->i2c_clients[i] = i2c_new_secondary_device(
186+ state->i2c_clients[i] = i2c_new_ancillary_device(
187187 state->client,
188188 adv748x_default_addresses[i].name,
189189 adv748x_default_addresses[i].default_addr);
190190
191− if (state->i2c_clients[i] == NULL) {
191+ if (IS_ERR(state->i2c_clients[i])) {
192192 adv_err(state, "failed to create i2c client %u\n", i);
193− return -ENOMEM;
193+ return PTR_ERR(state->i2c_clients[i]);
194194 }
195195
196196 ret = adv748x_configure_regmap(state, i);
drivers/media/i2c/adv7604.c+12−10
@@ -2862,10 +2862,8 @@ static void adv76xx_unregister_clients(struct adv76xx_state *state) · 2861 unmodified lines
28622862 {
28632863 unsigned int i;
28642864
2865− for (i = 1; i < ARRAY_SIZE(state->i2c_clients); ++i) {
2866− if (state->i2c_clients[i])
2867− i2c_unregister_device(state->i2c_clients[i]);
2868− }
2865+ for (i = 1; i < ARRAY_SIZE(state->i2c_clients); ++i)
2866+ i2c_unregister_device(state->i2c_clients[i]);
28692867 }
28702868
28712869 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, · 6 unmodified lines
28782876 struct i2c_client *new_client;
28792877
28802878 if (pdata && pdata->i2c_addresses[page])
2881− new_client = i2c_new_dummy(client->adapter,
2879+ new_client = i2c_new_dummy_device(client->adapter,
28822880 pdata->i2c_addresses[page]);
28832881 else
2884− new_client = i2c_new_secondary_device(client,
2882+ new_client = i2c_new_ancillary_device(client,
28852883 adv76xx_default_addresses[page].name,
28862884 adv76xx_default_addresses[page].default_addr);
28872885
2888− if (new_client)
2886+ if (!IS_ERR(new_client))
28892887 io_write(sd, io_reg, new_client->addr << 1);
28902888
28912889 return new_client;
@@ -3516,15 +3514,19 @@ static int adv76xx_probe(struct i2c_client *client, · 624 unmodified lines
35163514 }
35173515
35183516 for (i = 1; i < ADV76XX_PAGE_MAX; ++i) {
3517+ struct i2c_client *dummy_client;
3518+
35193519 if (!(BIT(i) & state->info->page_mask))
35203520 continue;
35213521
3522− state->i2c_clients[i] = adv76xx_dummy_client(sd, i);
3523− if (!state->i2c_clients[i]) {
3524− err = -EINVAL;
3522+ dummy_client = adv76xx_dummy_client(sd, i);
3523+ if (IS_ERR(dummy_client)) {
3524+ err = PTR_ERR(dummy_client);
35253525 v4l2_err(sd, "failed to create i2c client %u\n", i);
35263526 goto err_i2c;
35273527 }
3528+
3529+ state->i2c_clients[i] = dummy_client;
35283530 }
35293531
35303532 INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug,
include/linux/i2c.h+1−1
@@ -473,7 +473,7 @@ extern struct i2c_client * · 472 unmodified lines
473473 devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address);
474474
475475 extern struct i2c_client *
476−i2c_new_secondary_device(struct i2c_client *client,
476+i2c_new_ancillary_device(struct i2c_client *client,
477477 const char *name,
478478 u16 default_addr);
479479

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t