[i2c] [patch 2.6.21-rc2-git +i2c-patches] shrink i2c_client
David Brownell
david-b at pacbell.net
Tue Mar 6 07:44:18 CET 2007
This shrinks the size of "struct i2c_client" by over 32 bytes:
- Substantially shrinks the string used to identify the chip type
- The "flags" don't need to be so big
- Removes some internal padding
It also adds kerneldoc for that struct, explaining how "name" is really a
chip type identifier; it's otherwise potentially confusing.
Because the I2C_NAME_SIZE symbol was abused for both i2c_client.name
and for i2c_adapter.name, this needed to affect i2c_adapter too. The
adapters which used that symbol now use the more-obviously-correct
idiom of taking the size of that field.
Signed-off-by: David Brownell <dbrownell at users.sourceforge.net>
---
As previously discussed. Goes on top of various patches now in Jean's
I2C queue (#4-6 of a group posted recently) plus the cleanup patch
that I just posted.
drivers/i2c/busses/i2c-ali1535.c | 2 +-
drivers/i2c/busses/i2c-ali15x3.c | 2 +-
drivers/i2c/busses/i2c-amd8111.c | 2 +-
drivers/i2c/busses/i2c-i801.c | 2 +-
drivers/i2c/busses/i2c-ixp2000.c | 2 +-
drivers/i2c/busses/i2c-ixp4xx.c | 2 +-
drivers/i2c/busses/i2c-mv64xxx.c | 2 +-
drivers/i2c/busses/i2c-nforce2.c | 2 +-
drivers/i2c/busses/i2c-pasemi.c | 2 +-
drivers/i2c/busses/i2c-piix4.c | 2 +-
drivers/i2c/busses/i2c-sis96x.c | 2 +-
drivers/i2c/busses/i2c-viapro.c | 2 +-
drivers/i2c/busses/scx200_acb.c | 2 +-
drivers/media/dvb/b2c2/flexcop-i2c.c | 2 +-
drivers/media/dvb/dvb-usb/dvb-usb-i2c.c | 2 +-
drivers/media/dvb/frontends/dibx000_common.c | 4 ++--
drivers/video/intelfb/intelfb_i2c.c | 2 +-
drivers/video/matrox/i2c-matroxfb.c | 2 +-
include/linux/i2c.h | 21 +++++++++++++--------
19 files changed, 32 insertions(+), 27 deletions(-)
Index: at91/include/linux/i2c.h
===================================================================
--- at91.orig/include/linux/i2c.h 2007-03-05 12:45:47.000000000 -0800
+++ at91/include/linux/i2c.h 2007-03-05 12:45:52.000000000 -0800
@@ -139,25 +139,30 @@ struct i2c_driver {
};
#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
-#define I2C_NAME_SIZE 50
+#define I2C_NAME_SIZE 20
-/*
- * i2c_client identifies a single device (i.e. chip) that is connected to an
- * i2c bus. The behaviour is defined by the routines of the driver. This
- * function is mainly used for lookup & other admin. functions.
+/**
+ * struct i2c_client - represent an I2C slave device
+ * @addr: Address used on the I2C bus connected to the parent adapter.
+ * @name: Indicates the type of the device, usually a chip name that's
+ * generic enough to hide second-sourcing and compatible revisions.
+ * @dev: Driver model device node for the slave.
+ *
+ * An i2c_client identifies a single device (i.e. chip) connected to an
+ * i2c bus. The behaviour is defined by the routines of the driver.
*/
struct i2c_client {
- unsigned int flags; /* div., see below */
+ unsigned short flags; /* div., see below */
unsigned short addr; /* chip address - NOTE: 7bit */
/* addresses are stored in the */
/* _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 */
int usage_count; /* How many accesses currently */
/* to the client */
struct device dev; /* the device structure */
struct list_head list;
- char name[I2C_NAME_SIZE];
struct completion released;
};
#define to_i2c_client(d) container_of(d, struct i2c_client, dev)
@@ -230,7 +235,7 @@ struct i2c_adapter {
int nr;
struct list_head clients;
struct list_head list;
- char name[I2C_NAME_SIZE];
+ char name[50];
struct completion dev_released;
};
#define dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
Index: at91/drivers/i2c/busses/i2c-i801.c
===================================================================
--- at91.orig/drivers/i2c/busses/i2c-i801.c 2007-02-20 11:43:35.000000000 -0800
+++ at91/drivers/i2c/busses/i2c-i801.c 2007-03-05 12:47:20.000000000 -0800
@@ -525,7 +525,7 @@ static int __devinit i801_probe(struct p
/* set up the sysfs linkage to our parent device */
i801_adapter.dev.parent = &dev->dev;
- snprintf(i801_adapter.name, I2C_NAME_SIZE,
+ snprintf(i801_adapter.name, sizeof(i801_adapter.name),
"SMBus I801 adapter at %04lx", i801_smba);
err = i2c_add_adapter(&i801_adapter);
if (err) {
Index: at91/drivers/i2c/busses/i2c-sis96x.c
===================================================================
--- at91.orig/drivers/i2c/busses/i2c-sis96x.c 2007-02-20 11:43:35.000000000 -0800
+++ at91/drivers/i2c/busses/i2c-sis96x.c 2007-03-05 12:49:20.000000000 -0800
@@ -300,7 +300,7 @@ static int __devinit sis96x_probe(struct
/* set up the sysfs linkage to our parent device */
sis96x_adapter.dev.parent = &dev->dev;
- snprintf(sis96x_adapter.name, I2C_NAME_SIZE,
+ snprintf(sis96x_adapter.name, sizeof(sis96x_adapter.name),
"SiS96x SMBus adapter at 0x%04x", sis96x_smbus_base);
if ((retval = i2c_add_adapter(&sis96x_adapter))) {
Index: at91/drivers/i2c/busses/i2c-ali1535.c
===================================================================
--- at91.orig/drivers/i2c/busses/i2c-ali1535.c 2007-02-20 11:43:35.000000000 -0800
+++ at91/drivers/i2c/busses/i2c-ali1535.c 2007-03-05 12:46:34.000000000 -0800
@@ -497,7 +497,7 @@ static int __devinit ali1535_probe(struc
/* set up the sysfs linkage to our parent device */
ali1535_adapter.dev.parent = &dev->dev;
- snprintf(ali1535_adapter.name, I2C_NAME_SIZE,
+ snprintf(ali1535_adapter.name, sizeof(ali1535_adapter.name),
"SMBus ALI1535 adapter at %04x", ali1535_smba);
return i2c_add_adapter(&ali1535_adapter);
}
Index: at91/drivers/i2c/busses/i2c-mv64xxx.c
===================================================================
--- at91.orig/drivers/i2c/busses/i2c-mv64xxx.c 2007-02-15 15:32:29.000000000 -0800
+++ at91/drivers/i2c/busses/i2c-mv64xxx.c 2007-03-05 12:48:15.000000000 -0800
@@ -508,7 +508,7 @@ mv64xxx_i2c_probe(struct platform_device
}
strlcpy(drv_data->adapter.name, MV64XXX_I2C_CTLR_NAME " adapter",
- I2C_NAME_SIZE);
+ sizeof(drv_data->adapter.name));
init_waitqueue_head(&drv_data->waitq);
spin_lock_init(&drv_data->lock);
Index: at91/drivers/i2c/busses/i2c-pasemi.c
===================================================================
--- at91.orig/drivers/i2c/busses/i2c-pasemi.c 2007-02-15 15:32:29.000000000 -0800
+++ at91/drivers/i2c/busses/i2c-pasemi.c 2007-03-05 12:48:55.000000000 -0800
@@ -358,7 +358,7 @@ static int __devinit pasemi_smb_probe(st
}
smbus->adapter.owner = THIS_MODULE;
- snprintf(smbus->adapter.name, I2C_NAME_SIZE,
+ snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
"PA Semi SMBus adapter at 0x%lx", smbus->base);
smbus->adapter.class = I2C_CLASS_HWMON;
smbus->adapter.algo = &smbus_algorithm;
Index: at91/drivers/i2c/busses/i2c-ali15x3.c
===================================================================
--- at91.orig/drivers/i2c/busses/i2c-ali15x3.c 2007-02-20 11:43:35.000000000 -0800
+++ at91/drivers/i2c/busses/i2c-ali15x3.c 2007-03-05 12:46:52.000000000 -0800
@@ -492,7 +492,7 @@ static int __devinit ali15x3_probe(struc
/* set up the sysfs linkage to our parent device */
ali15x3_adapter.dev.parent = &dev->dev;
- snprintf(ali15x3_adapter.name, I2C_NAME_SIZE,
+ snprintf(ali15x3_adapter.name, sizeof(ali15x3_adapter.name),
"SMBus ALI15X3 adapter at %04x", ali15x3_smba);
return i2c_add_adapter(&ali15x3_adapter);
}
Index: at91/drivers/i2c/busses/scx200_acb.c
===================================================================
--- at91.orig/drivers/i2c/busses/scx200_acb.c 2007-02-15 15:32:29.000000000 -0800
+++ at91/drivers/i2c/busses/scx200_acb.c 2007-03-05 12:49:51.000000000 -0800
@@ -441,7 +441,7 @@ static __init struct scx200_acb_iface *s
adapter = &iface->adapter;
i2c_set_adapdata(adapter, iface);
- snprintf(adapter->name, I2C_NAME_SIZE, "%s ACB%d", text, index);
+ snprintf(adapter->name, sizeof(adapter->name), "%s ACB%d", text, index);
adapter->owner = THIS_MODULE;
adapter->id = I2C_HW_SMBUS_SCX200;
adapter->algo = &scx200_acb_algorithm;
Index: at91/drivers/i2c/busses/i2c-ixp2000.c
===================================================================
--- at91.orig/drivers/i2c/busses/i2c-ixp2000.c 2007-02-15 01:40:32.000000000 -0800
+++ at91/drivers/i2c/busses/i2c-ixp2000.c 2007-03-05 12:47:46.000000000 -0800
@@ -118,7 +118,7 @@ static int ixp2000_i2c_probe(struct plat
drv_data->adapter.id = I2C_HW_B_IXP2000,
strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name,
- I2C_NAME_SIZE);
+ sizeof(drv_data->adapter.name));
drv_data->adapter.algo_data = &drv_data->algo_data,
drv_data->adapter.dev.parent = &plat_dev->dev;
Index: at91/drivers/i2c/busses/i2c-piix4.c
===================================================================
--- at91.orig/drivers/i2c/busses/i2c-piix4.c 2007-02-20 11:43:35.000000000 -0800
+++ at91/drivers/i2c/busses/i2c-piix4.c 2007-03-05 12:49:08.000000000 -0800
@@ -428,7 +428,7 @@ static int __devinit piix4_probe(struct
/* set up the sysfs linkage to our parent device */
piix4_adapter.dev.parent = &dev->dev;
- snprintf(piix4_adapter.name, I2C_NAME_SIZE,
+ snprintf(piix4_adapter.name, sizeof(piix4_adapter.name),
"SMBus PIIX4 adapter at %04x", piix4_smba);
if ((retval = i2c_add_adapter(&piix4_adapter))) {
Index: at91/drivers/i2c/busses/i2c-ixp4xx.c
===================================================================
--- at91.orig/drivers/i2c/busses/i2c-ixp4xx.c 2007-02-15 01:40:32.000000000 -0800
+++ at91/drivers/i2c/busses/i2c-ixp4xx.c 2007-03-05 12:48:07.000000000 -0800
@@ -127,7 +127,7 @@ static int ixp4xx_i2c_probe(struct platf
drv_data->adapter.id = I2C_HW_B_IXP4XX;
drv_data->adapter.class = I2C_CLASS_HWMON;
strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name,
- I2C_NAME_SIZE);
+ sizeof(drv_data->adapter.name));
drv_data->adapter.algo_data = &drv_data->algo_data;
drv_data->adapter.dev.parent = &plat_dev->dev;
Index: at91/drivers/i2c/busses/i2c-amd8111.c
===================================================================
--- at91.orig/drivers/i2c/busses/i2c-amd8111.c 2007-02-20 11:43:35.000000000 -0800
+++ at91/drivers/i2c/busses/i2c-amd8111.c 2007-03-05 12:47:09.000000000 -0800
@@ -364,7 +364,7 @@ static int __devinit amd8111_probe(struc
}
smbus->adapter.owner = THIS_MODULE;
- snprintf(smbus->adapter.name, I2C_NAME_SIZE,
+ snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
"SMBus2 AMD8111 adapter at %04x", smbus->base);
smbus->adapter.id = I2C_HW_SMBUS_AMD8111;
smbus->adapter.class = I2C_CLASS_HWMON;
Index: at91/drivers/i2c/busses/i2c-viapro.c
===================================================================
--- at91.orig/drivers/i2c/busses/i2c-viapro.c 2007-02-15 15:32:29.000000000 -0800
+++ at91/drivers/i2c/busses/i2c-viapro.c 2007-03-05 12:49:30.000000000 -0800
@@ -404,7 +404,7 @@ found:
}
vt596_adapter.dev.parent = &pdev->dev;
- snprintf(vt596_adapter.name, I2C_NAME_SIZE,
+ snprintf(vt596_adapter.name, sizeof(vt596_adapter.name),
"SMBus Via Pro adapter at %04x", vt596_smba);
vt596_pdev = pci_dev_get(pdev);
Index: at91/drivers/i2c/busses/i2c-nforce2.c
===================================================================
--- at91.orig/drivers/i2c/busses/i2c-nforce2.c 2007-02-15 15:32:29.000000000 -0800
+++ at91/drivers/i2c/busses/i2c-nforce2.c 2007-03-05 12:48:45.000000000 -0800
@@ -240,7 +240,7 @@ static int __devinit nforce2_probe_smb (
smbus->adapter.algo = &smbus_algorithm;
smbus->adapter.algo_data = smbus;
smbus->adapter.dev.parent = &dev->dev;
- snprintf(smbus->adapter.name, I2C_NAME_SIZE,
+ snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
"SMBus nForce2 adapter at %04x", smbus->base);
error = i2c_add_adapter(&smbus->adapter);
Index: at91/drivers/video/matrox/i2c-matroxfb.c
===================================================================
--- at91.orig/drivers/video/matrox/i2c-matroxfb.c 2007-02-15 15:32:34.000000000 -0800
+++ at91/drivers/video/matrox/i2c-matroxfb.c 2007-03-05 12:53:47.000000000 -0800
@@ -111,7 +111,7 @@ static int i2c_bus_reg(struct i2c_bit_ad
b->mask.data = data;
b->mask.clock = clock;
b->adapter = matrox_i2c_adapter_template;
- snprintf(b->adapter.name, I2C_NAME_SIZE, name,
+ snprintf(b->adapter.name, sizeof(b->adapter.name), name,
minfo->fbcon.node);
i2c_set_adapdata(&b->adapter, b);
b->adapter.algo_data = &b->bac;
Index: at91/drivers/video/intelfb/intelfb_i2c.c
===================================================================
--- at91.orig/drivers/video/intelfb/intelfb_i2c.c 2007-02-15 15:32:34.000000000 -0800
+++ at91/drivers/video/intelfb/intelfb_i2c.c 2007-03-05 12:55:18.000000000 -0800
@@ -104,7 +104,7 @@ static int intelfb_setup_i2c_bus(struct
chan->dinfo = dinfo;
chan->reg = reg;
- snprintf(chan->adapter.name, I2C_NAME_SIZE, "intelfb %s", name);
+ snprintf(chan->adapter.name, sizeof(chan->adapter.name), "intelfb %s", name);
chan->adapter.owner = THIS_MODULE;
chan->adapter.id = I2C_HW_B_INTELFB;
chan->adapter.algo_data = &chan->algo;
Index: at91/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
===================================================================
--- at91.orig/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c 2007-02-15 15:32:29.000000000 -0800
+++ at91/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c 2007-03-05 12:59:17.000000000 -0800
@@ -19,7 +19,7 @@ int dvb_usb_i2c_init(struct dvb_usb_devi
return -EINVAL;
}
- strncpy(d->i2c_adap.name,d->desc->name,I2C_NAME_SIZE);
+ strncpy(d->i2c_adap.name, d->desc->name, sizeof(d->i2c_adap.name));
#ifdef I2C_ADAP_CLASS_TV_DIGITAL
d->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL,
#else
Index: at91/drivers/media/dvb/frontends/dibx000_common.c
===================================================================
--- at91.orig/drivers/media/dvb/frontends/dibx000_common.c 2006-09-30 19:15:58.000000000 -0700
+++ at91/drivers/media/dvb/frontends/dibx000_common.c 2007-03-05 12:57:53.000000000 -0800
@@ -105,9 +105,9 @@ struct i2c_adapter * dibx000_get_i2c_ada
}
EXPORT_SYMBOL(dibx000_get_i2c_adapter);
-static int i2c_adapter_init(struct i2c_adapter *i2c_adap, struct i2c_algorithm *algo, const char name[I2C_NAME_SIZE], struct dibx000_i2c_master *mst)
+static int i2c_adapter_init(struct i2c_adapter *i2c_adap, struct i2c_algorithm *algo, const char *name, struct dibx000_i2c_master *mst)
{
- strncpy(i2c_adap->name, name, I2C_NAME_SIZE);
+ strncpy(i2c_adap->name, name, sizeof(i2c_adap->name));
i2c_adap->class = I2C_CLASS_TV_DIGITAL,
i2c_adap->algo = algo;
i2c_adap->algo_data = NULL;
Index: at91/drivers/media/dvb/b2c2/flexcop-i2c.c
===================================================================
--- at91.orig/drivers/media/dvb/b2c2/flexcop-i2c.c 2007-02-15 15:32:29.000000000 -0800
+++ at91/drivers/media/dvb/b2c2/flexcop-i2c.c 2007-03-05 13:00:41.000000000 -0800
@@ -183,7 +183,7 @@ int flexcop_i2c_init(struct flexcop_devi
mutex_init(&fc->i2c_mutex);
memset(&fc->i2c_adap, 0, sizeof(struct i2c_adapter));
- strncpy(fc->i2c_adap.name, "B2C2 FlexCop device",I2C_NAME_SIZE);
+ strncpy(fc->i2c_adap.name, "B2C2 FlexCop device", sizeof(fc->i2c_adap.name));
i2c_set_adapdata(&fc->i2c_adap,fc);
More information about the i2c
mailing list