Skip to content

Commit 0acc2b3

Browse files
larsclausenWolfram Sang
authored andcommitted
i2c: Remove redundant 'driver' field from the i2c_client struct
The 'driver' field of the i2c_client struct is redundant. The same data can be accessed through to_i2c_driver(client->dev.driver). The generated code for both approaches in more or less the same. E.g. on ARM the expression client->driver->command(...) generates ... ldr r3, [r0, #28] ldr r3, [r3, #32] blx r3 ... and the expression to_i2c_driver(client->dev.driver)->command(...) generates ... ldr r3, [r0, #160] ldr r3, [r3, #-4] blx r3 ... Other architectures will generate similar code. All users of the 'driver' field outside of the I2C core have already been converted. So this only leaves the core itself. This patch converts the remaining few users in the I2C core and then removes the 'driver' field from the i2c_client struct. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
1 parent 40df249 commit 0acc2b3

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

drivers/i2c/i2c-core.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,16 @@ static int i2c_device_probe(struct device *dev)
248248
driver = to_i2c_driver(dev->driver);
249249
if (!driver->probe || !driver->id_table)
250250
return -ENODEV;
251-
client->driver = driver;
251+
252252
if (!device_can_wakeup(&client->dev))
253253
device_init_wakeup(&client->dev,
254254
client->flags & I2C_CLIENT_WAKE);
255255
dev_dbg(dev, "probe\n");
256256

257257
status = driver->probe(client, i2c_match_id(driver->id_table, client));
258-
if (status) {
259-
client->driver = NULL;
258+
if (status)
260259
i2c_set_clientdata(client, NULL);
261-
}
260+
262261
return status;
263262
}
264263

@@ -279,10 +278,9 @@ static int i2c_device_remove(struct device *dev)
279278
dev->driver = NULL;
280279
status = 0;
281280
}
282-
if (status == 0) {
283-
client->driver = NULL;
281+
if (status == 0)
284282
i2c_set_clientdata(client, NULL);
285-
}
283+
286284
return status;
287285
}
288286

@@ -1606,9 +1604,14 @@ static int i2c_cmd(struct device *dev, void *_arg)
16061604
{
16071605
struct i2c_client *client = i2c_verify_client(dev);
16081606
struct i2c_cmd_arg *arg = _arg;
1607+
struct i2c_driver *driver;
1608+
1609+
if (!client || !client->dev.driver)
1610+
return 0;
16091611

1610-
if (client && client->driver && client->driver->command)
1611-
client->driver->command(client, arg->cmd, arg->arg);
1612+
driver = to_i2c_driver(client->dev.driver);
1613+
if (driver->command)
1614+
driver->command(client, arg->cmd, arg->arg);
16121615
return 0;
16131616
}
16141617

drivers/i2c/i2c-smbus.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static int smbus_do_alert(struct device *dev, void *addrp)
4646
{
4747
struct i2c_client *client = i2c_verify_client(dev);
4848
struct alert_data *data = addrp;
49+
struct i2c_driver *driver;
4950

5051
if (!client || client->addr != data->addr)
5152
return 0;
@@ -54,12 +55,13 @@ static int smbus_do_alert(struct device *dev, void *addrp)
5455

5556
/*
5657
* Drivers should either disable alerts, or provide at least
57-
* a minimal handler. Lock so client->driver won't change.
58+
* a minimal handler. Lock so the driver won't change.
5859
*/
5960
device_lock(dev);
60-
if (client->driver) {
61-
if (client->driver->alert)
62-
client->driver->alert(client, data->flag);
61+
if (client->dev.driver) {
62+
driver = to_i2c_driver(client->dev.driver);
63+
if (driver->alert)
64+
driver->alert(client, data->flag);
6365
else
6466
dev_warn(&client->dev, "no driver alert()!\n");
6567
} else

include/linux/i2c.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ struct i2c_driver {
205205
* @name: Indicates the type of the device, usually a chip name that's
206206
* generic enough to hide second-sourcing and compatible revisions.
207207
* @adapter: manages the bus segment hosting this I2C device
208-
* @driver: device's driver, hence pointer to access routines
209208
* @dev: Driver model device node for the slave.
210209
* @irq: indicates the IRQ generated by this device (if any)
211210
* @detected: member of an i2c_driver.clients list or i2c-core's
@@ -222,7 +221,6 @@ struct i2c_client {
222221
/* _LOWER_ 7 bits */
223222
char name[I2C_NAME_SIZE];
224223
struct i2c_adapter *adapter; /* the adapter we sit on */
225-
struct i2c_driver *driver; /* and our access routines */
226224
struct device dev; /* the device structure */
227225
int irq; /* irq issued by device */
228226
struct list_head detected;

0 commit comments

Comments
 (0)