Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Wolfram 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: Wolfram Sang <wsa@the-dreams.de>

authored by

Wolfram Sang and committed by
Wolfram Sang
af80559b bbeb6b6c

+30 -28
+9 -9
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
··· 981 981 { 982 982 int ret; 983 983 984 - adv->i2c_cec = i2c_new_secondary_device(adv->i2c_main, "cec", 984 + adv->i2c_cec = i2c_new_ancillary_device(adv->i2c_main, "cec", 985 985 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); 988 988 i2c_set_clientdata(adv->i2c_cec, adv); 989 989 990 990 adv->regmap_cec = devm_regmap_init_i2c(adv->i2c_cec, ··· 1165 1165 1166 1166 adv7511_packet_disable(adv7511, 0xffff); 1167 1167 1168 - adv7511->i2c_edid = i2c_new_secondary_device(i2c, "edid", 1168 + adv7511->i2c_edid = i2c_new_ancillary_device(i2c, "edid", 1169 1169 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); 1172 1172 goto uninit_regulators; 1173 1173 } 1174 1174 1175 1175 regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR, 1176 1176 adv7511->i2c_edid->addr << 1); 1177 1177 1178 - adv7511->i2c_packet = i2c_new_secondary_device(i2c, "packet", 1178 + adv7511->i2c_packet = i2c_new_ancillary_device(i2c, "packet", 1179 1179 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); 1182 1182 goto err_i2c_unregister_edid; 1183 1183 } 1184 1184
+5 -5
drivers/i2c/i2c-core-base.c
··· 964 964 EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device); 965 965 966 966 /** 967 - * i2c_new_secondary_device - Helper to get the instantiated secondary address 967 + * i2c_new_ancillary_device - Helper to get the instantiated secondary address 968 968 * and create the associated device 969 969 * @client: Handle to the primary client 970 970 * @name: Handle to specify which secondary address to get ··· 983 983 * cell whose "reg-names" value matches the slave name. 984 984 * 985 985 * 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. 987 987 */ 988 - struct i2c_client *i2c_new_secondary_device(struct i2c_client *client, 988 + struct i2c_client *i2c_new_ancillary_device(struct i2c_client *client, 989 989 const char *name, 990 990 u16 default_addr) 991 991 { ··· 1000 1000 } 1001 1001 1002 1002 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); 1004 1004 } 1005 - EXPORT_SYMBOL_GPL(i2c_new_secondary_device); 1005 + EXPORT_SYMBOL_GPL(i2c_new_ancillary_device); 1006 1006 1007 1007 /* ------------------------------------------------------------------------- */ 1008 1008
+3 -3
drivers/media/i2c/adv748x/adv748x-core.c
··· 183 183 int ret; 184 184 185 185 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( 187 187 state->client, 188 188 adv748x_default_addresses[i].name, 189 189 adv748x_default_addresses[i].default_addr); 190 190 191 - if (state->i2c_clients[i] == NULL) { 191 + if (IS_ERR(state->i2c_clients[i])) { 192 192 adv_err(state, "failed to create i2c client %u\n", i); 193 - return -ENOMEM; 193 + return PTR_ERR(state->i2c_clients[i]); 194 194 } 195 195 196 196 ret = adv748x_configure_regmap(state, i);
+12 -10
drivers/media/i2c/adv7604.c
··· 2862 2862 { 2863 2863 unsigned int i; 2864 2864 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]); 2869 2867 } 2870 2868 2871 2869 static struct i2c_client *adv76xx_dummy_client(struct v4l2_subdev *sd, ··· 2876 2878 struct i2c_client *new_client; 2877 2879 2878 2880 if (pdata && pdata->i2c_addresses[page]) 2879 - new_client = i2c_new_dummy(client->adapter, 2881 + new_client = i2c_new_dummy_device(client->adapter, 2880 2882 pdata->i2c_addresses[page]); 2881 2883 else 2882 - new_client = i2c_new_secondary_device(client, 2884 + new_client = i2c_new_ancillary_device(client, 2883 2885 adv76xx_default_addresses[page].name, 2884 2886 adv76xx_default_addresses[page].default_addr); 2885 2887 2886 - if (new_client) 2888 + if (!IS_ERR(new_client)) 2887 2889 io_write(sd, io_reg, new_client->addr << 1); 2888 2890 2889 2891 return new_client; ··· 3514 3516 } 3515 3517 3516 3518 for (i = 1; i < ADV76XX_PAGE_MAX; ++i) { 3519 + struct i2c_client *dummy_client; 3520 + 3517 3521 if (!(BIT(i) & state->info->page_mask)) 3518 3522 continue; 3519 3523 3520 - state->i2c_clients[i] = adv76xx_dummy_client(sd, i); 3521 - if (!state->i2c_clients[i]) { 3522 - err = -EINVAL; 3524 + dummy_client = adv76xx_dummy_client(sd, i); 3525 + if (IS_ERR(dummy_client)) { 3526 + err = PTR_ERR(dummy_client); 3523 3527 v4l2_err(sd, "failed to create i2c client %u\n", i); 3524 3528 goto err_i2c; 3525 3529 } 3530 + 3531 + state->i2c_clients[i] = dummy_client; 3526 3532 } 3527 3533 3528 3534 INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug,
+1 -1
include/linux/i2c.h
··· 473 473 devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address); 474 474 475 475 extern struct i2c_client * 476 - i2c_new_secondary_device(struct i2c_client *client, 476 + i2c_new_ancillary_device(struct i2c_client *client, 477 477 const char *name, 478 478 u16 default_addr); 479 479