i2c: Shrink struct i2c_client
authorDavid Brownell <david-b@pacbell.net>
Tue, 1 May 2007 21:26:28 +0000 (23:26 +0200)
committerJean Delvare <khali@hyperion.delvare>
Tue, 1 May 2007 21:26:28 +0000 (23:26 +0200)
This shrinks the size of "struct i2c_client" by 40 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.

JD: Shorten i2c_adapter.name from 50 to 48 bytes while we're here, to
avoid wasting space in padding.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
19 files changed:
drivers/i2c/busses/i2c-ali1535.c
drivers/i2c/busses/i2c-ali15x3.c
drivers/i2c/busses/i2c-amd8111.c
drivers/i2c/busses/i2c-i801.c
drivers/i2c/busses/i2c-ixp2000.c
drivers/i2c/busses/i2c-ixp4xx.c
drivers/i2c/busses/i2c-mv64xxx.c
drivers/i2c/busses/i2c-nforce2.c
drivers/i2c/busses/i2c-pasemi.c
drivers/i2c/busses/i2c-piix4.c
drivers/i2c/busses/i2c-sis96x.c
drivers/i2c/busses/i2c-viapro.c
drivers/i2c/busses/scx200_acb.c
drivers/media/dvb/b2c2/flexcop-i2c.c
drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
drivers/media/dvb/frontends/dibx000_common.c
drivers/video/intelfb/intelfb_i2c.c
drivers/video/matrox/i2c-matroxfb.c
include/linux/i2c.h

index 1e277ba..f14372a 100644 (file)
@@ -497,7 +497,7 @@ static int __devinit ali1535_probe(struct pci_dev *dev, const struct pci_device_
        /* 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 e47fe01..93bf87d 100644 (file)
@@ -492,7 +492,7 @@ static int __devinit ali15x3_probe(struct pci_dev *dev, const struct pci_device_
        /* 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 0c70f82..c9fca7b 100644 (file)
@@ -365,7 +365,7 @@ static int __devinit amd8111_probe(struct pci_dev *dev,
        }
 
        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 a320e7d..611b571 100644 (file)
@@ -527,7 +527,7 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
        /* 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 efa3ecc..6352121 100644 (file)
@@ -118,7 +118,7 @@ static int ixp2000_i2c_probe(struct platform_device *plat_dev)
 
        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 08e89b8..069ed7f 100644 (file)
@@ -127,7 +127,7 @@ static int ixp4xx_i2c_probe(struct platform_device *plat_dev)
        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 a3283b9..a55b333 100644 (file)
@@ -508,7 +508,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
        }
 
        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 1514ec5..cdc67dc 100644 (file)
@@ -240,7 +240,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
        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 bf89eee..58e3271 100644 (file)
@@ -358,7 +358,7 @@ static int __devinit pasemi_smb_probe(struct pci_dev *dev,
        }
 
        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 21b1809..5a52bf5 100644 (file)
@@ -428,7 +428,7 @@ static int __devinit piix4_probe(struct pci_dev *dev,
        /* 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 4157b0c..dc235bb 100644 (file)
@@ -300,7 +300,7 @@ static int __devinit sis96x_probe(struct pci_dev *dev,
        /* 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 03c5fc8..7a2bc06 100644 (file)
@@ -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 0b082c5..d816ab0 100644 (file)
@@ -441,7 +441,7 @@ static __init struct scx200_acb_iface *scx200_create_iface(const char *text,
 
        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 5347a40..02a0ea6 100644 (file)
@@ -183,7 +183,8 @@ int flexcop_i2c_init(struct flexcop_device *fc)
        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);
 
index 70df31b..088b6de 100644 (file)
@@ -19,7 +19,7 @@ int dvb_usb_i2c_init(struct dvb_usb_device *d)
                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 a18c8f4..315e09e 100644 (file)
@@ -105,9 +105,9 @@ struct i2c_adapter * dibx000_get_i2c_adapter(struct dibx000_i2c_master *mst, enu
 }
 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 f4ede5f..61e4c87 100644 (file)
@@ -104,7 +104,8 @@ static int intelfb_setup_i2c_bus(struct intelfb_info *dinfo,
 
        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 5ec718a..4baab7b 100644 (file)
@@ -111,7 +111,7 @@ static int i2c_bus_reg(struct i2c_bit_adapter* b, struct matrox_fb_info* minfo,
        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 47c2a19..953e71f 100644 (file)
@@ -140,25 +140,30 @@ struct i2c_driver {
 };
 #define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
 
-#define I2C_NAME_SIZE  50
-
-/*
- * 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.
+#define I2C_NAME_SIZE  20
+
+/**
+ * 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[48];
        struct completion dev_released;
 };
 #define dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)