Skip to content

Commit

Permalink
i2c: Remove redundant 'driver' field from the i2c_client struct
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Wolfram Sang <[email protected]>
  • Loading branch information
larsclausen authored and Wolfram Sang committed Oct 3, 2013
1 parent 40df249 commit 0acc2b3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
21 changes: 12 additions & 9 deletions drivers/i2c/i2c-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,16 @@ static int i2c_device_probe(struct device *dev)
driver = to_i2c_driver(dev->driver);
if (!driver->probe || !driver->id_table)
return -ENODEV;
client->driver = driver;

if (!device_can_wakeup(&client->dev))
device_init_wakeup(&client->dev,
client->flags & I2C_CLIENT_WAKE);
dev_dbg(dev, "probe\n");

status = driver->probe(client, i2c_match_id(driver->id_table, client));
if (status) {
client->driver = NULL;
if (status)
i2c_set_clientdata(client, NULL);
}

return status;
}

Expand All @@ -279,10 +278,9 @@ static int i2c_device_remove(struct device *dev)
dev->driver = NULL;
status = 0;
}
if (status == 0) {
client->driver = NULL;
if (status == 0)
i2c_set_clientdata(client, NULL);
}

return status;
}

Expand Down Expand Up @@ -1606,9 +1604,14 @@ static int i2c_cmd(struct device *dev, void *_arg)
{
struct i2c_client *client = i2c_verify_client(dev);
struct i2c_cmd_arg *arg = _arg;
struct i2c_driver *driver;

if (!client || !client->dev.driver)
return 0;

if (client && client->driver && client->driver->command)
client->driver->command(client, arg->cmd, arg->arg);
driver = to_i2c_driver(client->dev.driver);
if (driver->command)
driver->command(client, arg->cmd, arg->arg);
return 0;
}

Expand Down
10 changes: 6 additions & 4 deletions drivers/i2c/i2c-smbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static int smbus_do_alert(struct device *dev, void *addrp)
{
struct i2c_client *client = i2c_verify_client(dev);
struct alert_data *data = addrp;
struct i2c_driver *driver;

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

/*
* Drivers should either disable alerts, or provide at least
* a minimal handler. Lock so client->driver won't change.
* a minimal handler. Lock so the driver won't change.
*/
device_lock(dev);
if (client->driver) {
if (client->driver->alert)
client->driver->alert(client, data->flag);
if (client->dev.driver) {
driver = to_i2c_driver(client->dev.driver);
if (driver->alert)
driver->alert(client, data->flag);
else
dev_warn(&client->dev, "no driver alert()!\n");
} else
Expand Down
2 changes: 0 additions & 2 deletions include/linux/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ struct i2c_driver {
* @name: Indicates the type of the device, usually a chip name that's
* generic enough to hide second-sourcing and compatible revisions.
* @adapter: manages the bus segment hosting this I2C device
* @driver: device's driver, hence pointer to access routines
* @dev: Driver model device node for the slave.
* @irq: indicates the IRQ generated by this device (if any)
* @detected: member of an i2c_driver.clients list or i2c-core's
Expand All @@ -222,7 +221,6 @@ struct i2c_client {
/* _LOWER_ 7 bits */
char name[I2C_NAME_SIZE];
struct i2c_adapter *adapter; /* the adapter we sit on */
struct i2c_driver *driver; /* and our access routines */
struct device dev; /* the device structure */
int irq; /* irq issued by device */
struct list_head detected;
Expand Down

0 comments on commit 0acc2b3

Please sign in to comment.