From: David Brownell Subject: i2c: Shrink struct i2c_client 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 Signed-off-by: Jean Delvare --- 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 | 3 ++- drivers/media/dvb/dvb-usb/dvb-usb-i2c.c | 2 +- drivers/media/dvb/frontends/dibx000_common.c | 4 ++-- drivers/video/intelfb/intelfb_i2c.c | 3 ++- drivers/video/matrox/i2c-matroxfb.c | 2 +- include/linux/i2c.h | 21 +++++++++++++-------- 19 files changed, 34 insertions(+), 27 deletions(-) --- linux-2.6.21-rc2.orig/include/linux/i2c.h 2007-03-06 17:16:34.000000000 +0100 +++ linux-2.6.21-rc2/include/linux/i2c.h 2007-03-06 17:48:20.000000000 +0100 @@ -140,25 +140,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) @@ -231,7 +236,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) --- linux-2.6.21-rc2.orig/drivers/i2c/busses/i2c-i801.c 2007-03-06 17:16:34.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/i2c-i801.c 2007-03-06 17:48:20.000000000 +0100 @@ -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) { --- linux-2.6.21-rc2.orig/drivers/i2c/busses/i2c-sis96x.c 2007-03-06 13:43:47.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/i2c-sis96x.c 2007-03-06 17:48:20.000000000 +0100 @@ -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))) { --- linux-2.6.21-rc2.orig/drivers/i2c/busses/i2c-ali1535.c 2007-03-06 13:43:47.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/i2c-ali1535.c 2007-03-06 17:48:20.000000000 +0100 @@ -499,7 +499,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); } --- linux-2.6.21-rc2.orig/drivers/i2c/busses/i2c-mv64xxx.c 2007-03-06 13:43:47.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/i2c-mv64xxx.c 2007-03-06 17:48:20.000000000 +0100 @@ -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); --- linux-2.6.21-rc2.orig/drivers/i2c/busses/i2c-pasemi.c 2007-03-06 13:43:47.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/i2c-pasemi.c 2007-03-06 17:48:20.000000000 +0100 @@ -359,7 +359,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; --- linux-2.6.21-rc2.orig/drivers/i2c/busses/i2c-ali15x3.c 2007-03-06 13:43:47.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/i2c-ali15x3.c 2007-03-06 17:48:20.000000000 +0100 @@ -495,7 +495,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); } --- linux-2.6.21-rc2.orig/drivers/i2c/busses/scx200_acb.c 2007-02-21 08:36:07.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/scx200_acb.c 2007-03-06 17:48:20.000000000 +0100 @@ -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; --- linux-2.6.21-rc2.orig/drivers/i2c/busses/i2c-ixp2000.c 2007-02-09 09:15:20.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/i2c-ixp2000.c 2007-03-06 17:48:20.000000000 +0100 @@ -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; --- linux-2.6.21-rc2.orig/drivers/i2c/busses/i2c-piix4.c 2007-03-06 13:43:47.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/i2c-piix4.c 2007-03-06 17:48:20.000000000 +0100 @@ -430,7 +430,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))) { --- linux-2.6.21-rc2.orig/drivers/i2c/busses/i2c-ixp4xx.c 2007-02-09 09:15:20.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/i2c-ixp4xx.c 2007-03-06 17:48:20.000000000 +0100 @@ -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; --- linux-2.6.21-rc2.orig/drivers/i2c/busses/i2c-amd8111.c 2007-03-06 13:43:47.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/i2c-amd8111.c 2007-03-06 17:48:20.000000000 +0100 @@ -366,7 +366,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; --- linux-2.6.21-rc2.orig/drivers/i2c/busses/i2c-viapro.c 2007-03-06 13:43:47.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/i2c-viapro.c 2007-03-06 17:48:20.000000000 +0100 @@ -407,7 +407,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); --- linux-2.6.21-rc2.orig/drivers/i2c/busses/i2c-nforce2.c 2007-03-06 17:16:34.000000000 +0100 +++ linux-2.6.21-rc2/drivers/i2c/busses/i2c-nforce2.c 2007-03-06 17:48:20.000000000 +0100 @@ -242,7 +242,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); --- linux-2.6.21-rc2.orig/drivers/video/matrox/i2c-matroxfb.c 2007-02-21 08:36:18.000000000 +0100 +++ linux-2.6.21-rc2/drivers/video/matrox/i2c-matroxfb.c 2007-03-06 17:48:20.000000000 +0100 @@ -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; --- linux-2.6.21-rc2.orig/drivers/video/intelfb/intelfb_i2c.c 2007-02-28 21:16:33.000000000 +0100 +++ linux-2.6.21-rc2/drivers/video/intelfb/intelfb_i2c.c 2007-03-06 18:06:37.000000000 +0100 @@ -104,7 +104,8 @@ 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; --- linux-2.6.21-rc2.orig/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c 2007-02-21 08:36:09.000000000 +0100 +++ linux-2.6.21-rc2/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c 2007-03-06 17:48:20.000000000 +0100 @@ -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 --- linux-2.6.21-rc2.orig/drivers/media/dvb/frontends/dibx000_common.c 2007-02-04 19:44:54.000000000 +0100 +++ linux-2.6.21-rc2/drivers/media/dvb/frontends/dibx000_common.c 2007-03-06 17:48:20.000000000 +0100 @@ -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; --- linux-2.6.21-rc2.orig/drivers/media/dvb/b2c2/flexcop-i2c.c 2007-02-21 08:36:09.000000000 +0100 +++ linux-2.6.21-rc2/drivers/media/dvb/b2c2/flexcop-i2c.c 2007-03-06 18:06:26.000000000 +0100 @@ -183,7 +183,8 @@ 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);