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.
Unified · Split
| @@ -981,10 +981,10 @@ static int adv7511_init_cec_regmap(struct adv7511 *adv) · 980 unmodified lines | |||
| 981 | { | 981 | { |
| 982 | int ret; | 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 | ADV7511_CEC_I2C_ADDR_DEFAULT); | 985 | ADV7511_CEC_I2C_ADDR_DEFAULT); |
| 986 | if (!adv->i2c_cec) | 986 | if (IS_ERR(adv->i2c_cec)) |
| 987 | return -EINVAL; | 987 | return PTR_ERR(adv->i2c_cec); |
| 988 | i2c_set_clientdata(adv->i2c_cec, adv); | 988 | i2c_set_clientdata(adv->i2c_cec, adv); |
| 989 | 989 | ||
| 990 | adv->regmap_cec = devm_regmap_init_i2c(adv->i2c_cec, | 990 | 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 | |||
| 1165 | 1165 | ||
| 1166 | adv7511_packet_disable(adv7511, 0xffff); | 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 | ADV7511_EDID_I2C_ADDR_DEFAULT); | 1169 | ADV7511_EDID_I2C_ADDR_DEFAULT); |
| 1170 | if (!adv7511->i2c_edid) { | 1170 | if (IS_ERR(adv7511->i2c_edid)) { |
| 1171 | ret = -EINVAL; | 1171 | ret = PTR_ERR(adv7511->i2c_edid); |
| 1172 | goto uninit_regulators; | 1172 | goto uninit_regulators; |
| 1173 | } | 1173 | } |
| 1174 | 1174 | ||
| 1175 | regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR, | 1175 | regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR, |
| 1176 | adv7511->i2c_edid->addr << 1); | 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 | ADV7511_PACKET_I2C_ADDR_DEFAULT); | 1179 | ADV7511_PACKET_I2C_ADDR_DEFAULT); |
| 1180 | if (!adv7511->i2c_packet) { | 1180 | if (IS_ERR(adv7511->i2c_packet)) { |
| 1181 | ret = -EINVAL; | 1181 | ret = PTR_ERR(adv7511->i2c_packet); |
| 1182 | goto err_i2c_unregister_edid; | 1182 | goto err_i2c_unregister_edid; |
| 1183 | } | 1183 | } |
| 1184 | 1184 | ||
| @@ -964,7 +964,7 @@ struct i2c_client *devm_i2c_new_dummy_device(struct device *dev, · 963 unmodified lines | |||
| 964 | EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device); | 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 | * and create the associated device | 968 | * and create the associated device |
| 969 | * @client: Handle to the primary client | 969 | * @client: Handle to the primary client |
| 970 | * @name: Handle to specify which secondary address to get | 970 | * @name: Handle to specify which secondary address to get |
| @@ -983,9 +983,9 @@ EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device); · 12 unmodified lines | |||
| 983 | * cell whose "reg-names" value matches the slave name. | 983 | * cell whose "reg-names" value matches the slave name. |
| 984 | * | 984 | * |
| 985 | * This returns the new i2c client, which should be saved for later use with | 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 | const char *name, | 989 | const char *name, |
| 990 | u16 default_addr) | 990 | u16 default_addr) |
| 991 | { | 991 | { |
| @@ -1000,9 +1000,9 @@ struct i2c_client *i2c_new_secondary_device(struct i2c_client *client, · 8 unmodified lines | |||
| 1000 | } | 1000 | } |
| 1001 | 1001 | ||
| 1002 | dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr); | 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 | ||
| @@ -183,14 +183,14 @@ static int adv748x_initialise_clients(struct adv748x_state *state) · 182 unmodified lines | |||
| 183 | int ret; | 183 | int ret; |
| 184 | 184 | ||
| 185 | for (i = ADV748X_PAGE_DPLL; i < ADV748X_PAGE_MAX; ++i) { | 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 | state->client, | 187 | state->client, |
| 188 | adv748x_default_addresses[i].name, | 188 | adv748x_default_addresses[i].name, |
| 189 | adv748x_default_addresses[i].default_addr); | 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 | adv_err(state, "failed to create i2c client %u\n", i); | 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 | ret = adv748x_configure_regmap(state, i); | 196 | ret = adv748x_configure_regmap(state, i); |
| @@ -2862,10 +2862,8 @@ static void adv76xx_unregister_clients(struct adv76xx_state *state) · 2861 unmodified lines | |||
| 2862 | { | 2862 | { |
| 2863 | unsigned int i; | 2863 | unsigned int i; |
| 2864 | 2864 | ||
| 2865 | for (i = 1; i < ARRAY_SIZE(state->i2c_clients); ++i) { | 2865 | for (i = 1; i < ARRAY_SIZE(state->i2c_clients); ++i) |
| 2866 | if (state->i2c_clients[i]) | 2866 | i2c_unregister_device(state->i2c_clients[i]); |
| 2867 | i2c_unregister_device(state->i2c_clients[i]); | ||
| 2868 | } | ||
| 2869 | } | 2867 | } |
| 2870 | 2868 | ||
| 2871 | static struct i2c_client *adv76xx_dummy_client(struct v4l2_subdev *sd, | 2869 | 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 | |||
| 2878 | struct i2c_client *new_client; | 2876 | struct i2c_client *new_client; |
| 2879 | 2877 | ||
| 2880 | if (pdata && pdata->i2c_addresses[page]) | 2878 | if (pdata && pdata->i2c_addresses[page]) |
| 2881 | new_client = i2c_new_dummy(client->adapter, | 2879 | new_client = i2c_new_dummy_device(client->adapter, |
| 2882 | pdata->i2c_addresses[page]); | 2880 | pdata->i2c_addresses[page]); |
| 2883 | else | 2881 | else |
| 2884 | new_client = i2c_new_secondary_device(client, | 2882 | new_client = i2c_new_ancillary_device(client, |
| 2885 | adv76xx_default_addresses[page].name, | 2883 | adv76xx_default_addresses[page].name, |
| 2886 | adv76xx_default_addresses[page].default_addr); | 2884 | adv76xx_default_addresses[page].default_addr); |
| 2887 | 2885 | ||
| 2888 | if (new_client) | 2886 | if (!IS_ERR(new_client)) |
| 2889 | io_write(sd, io_reg, new_client->addr << 1); | 2887 | io_write(sd, io_reg, new_client->addr << 1); |
| 2890 | 2888 | ||
| 2891 | return new_client; | 2889 | return new_client; |
| @@ -3516,15 +3514,19 @@ static int adv76xx_probe(struct i2c_client *client, · 624 unmodified lines | |||
| 3516 | } | 3514 | } |
| 3517 | 3515 | ||
| 3518 | for (i = 1; i < ADV76XX_PAGE_MAX; ++i) { | 3516 | for (i = 1; i < ADV76XX_PAGE_MAX; ++i) { |
| 3517 | struct i2c_client *dummy_client; | ||
| 3518 | |||
| 3519 | if (!(BIT(i) & state->info->page_mask)) | 3519 | if (!(BIT(i) & state->info->page_mask)) |
| 3520 | continue; | 3520 | continue; |
| 3521 | 3521 | ||
| 3522 | state->i2c_clients[i] = adv76xx_dummy_client(sd, i); | 3522 | dummy_client = adv76xx_dummy_client(sd, i); |
| 3523 | if (!state->i2c_clients[i]) { | 3523 | if (IS_ERR(dummy_client)) { |
| 3524 | err = -EINVAL; | 3524 | err = PTR_ERR(dummy_client); |
| 3525 | v4l2_err(sd, "failed to create i2c client %u\n", i); | 3525 | v4l2_err(sd, "failed to create i2c client %u\n", i); |
| 3526 | goto err_i2c; | 3526 | goto err_i2c; |
| 3527 | } | 3527 | } |
| 3528 | |||
| 3529 | state->i2c_clients[i] = dummy_client; | ||
| 3528 | } | 3530 | } |
| 3529 | 3531 | ||
| 3530 | INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug, | 3532 | INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug, |
| @@ -473,7 +473,7 @@ extern struct i2c_client * · 472 unmodified lines | |||
| 473 | devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address); | 473 | devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address); |
| 474 | 474 | ||
| 475 | extern struct i2c_client * | 475 | extern struct i2c_client * |
| 476 | i2c_new_secondary_device(struct i2c_client *client, | 476 | i2c_new_ancillary_device(struct i2c_client *client, |
| 477 | const char *name, | 477 | const char *name, |
| 478 | u16 default_addr); | 478 | u16 default_addr); |
| 479 | 479 | ||