Skip to content

Commit

Permalink
[PATCH] i2c: Drop i2c_driver.flags, 2 of 3
Browse files Browse the repository at this point in the history
Just about every i2c chip driver sets the I2C_DF_NOTIFY flag, so we
can simply make it the default and drop the flag. If any driver really
doesn't want to be notified when i2c adapters are added, that driver
can simply omit to set .attach_adapter. This approach is also more
robust as it prevents accidental NULL pointer dereferences.

Signed-off-by: Jean Delvare <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Jean Delvare authored and gregkh committed Jan 6, 2006
1 parent ff179c8 commit 8a99475
Show file tree
Hide file tree
Showing 91 changed files with 5 additions and 95 deletions.
3 changes: 3 additions & 0 deletions Documentation/i2c/porting-clients
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ Technical changes:
there is a MODULE_LICENSE() line, at the bottom of the file
(after MODULE_AUTHOR() and MODULE_DESCRIPTION(), in this order).

* [Driver] The flags field of the i2c_driver structure is gone.
I2C_DF_NOTIFY is now the default behavior.

Coding policy:

* [Copyright] Use (C), not (c), for copyright.
Expand Down
5 changes: 0 additions & 5 deletions Documentation/i2c/writing-clients
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ address.
static struct i2c_driver foo_driver = {
.owner = THIS_MODULE,
.name = "Foo version 2.3 driver",
.flags = I2C_DF_NOTIFY,
.attach_adapter = &foo_attach_adapter,
.detach_client = &foo_detach_client,
.command = &foo_command /* may be NULL */
Expand All @@ -36,10 +35,6 @@ static struct i2c_driver foo_driver = {
The name field must match the driver name, including the case. It must not
contain spaces, and may be up to 31 characters long.

Don't worry about the flags field; just put I2C_DF_NOTIFY into it. This
means that your driver will be notified when new adapters are found.
This is almost always what you want.

All other fields are for call-back functions which will be explained
below.

Expand Down
1 change: 0 additions & 1 deletion arch/arm/mach-pxa/akita-ioexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ static struct i2c_driver max7310_i2c_driver = {
.owner = THIS_MODULE,
.name = "akita-max7310",
.id = I2C_DRIVERID_AKITAIOEXP,
.flags = I2C_DF_NOTIFY,
.attach_adapter = max7310_attach_adapter,
.detach_client = max7310_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/acorn/char/pcf8583.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ pcf8583_command(struct i2c_client *client, unsigned int cmd, void *arg)
static struct i2c_driver pcf8583_driver = {
.name = "PCF8583",
.id = I2C_DRIVERID_PCF8583,
.flags = I2C_DF_NOTIFY,
.attach_adapter = pcf8583_probe,
.detach_client = pcf8583_detach,
.command = pcf8583_command
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/adm1021.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ static struct i2c_driver adm1021_driver = {
.owner = THIS_MODULE,
.name = "adm1021",
.id = I2C_DRIVERID_ADM1021,
.flags = I2C_DF_NOTIFY,
.attach_adapter = adm1021_attach_adapter,
.detach_client = adm1021_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/adm1025.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ static struct i2c_driver adm1025_driver = {
.owner = THIS_MODULE,
.name = "adm1025",
.id = I2C_DRIVERID_ADM1025,
.flags = I2C_DF_NOTIFY,
.attach_adapter = adm1025_attach_adapter,
.detach_client = adm1025_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/adm1026.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ static void adm1026_init_client(struct i2c_client *client);
static struct i2c_driver adm1026_driver = {
.owner = THIS_MODULE,
.name = "adm1026",
.flags = I2C_DF_NOTIFY,
.attach_adapter = adm1026_attach_adapter,
.detach_client = adm1026_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/adm1031.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ static struct adm1031_data *adm1031_update_device(struct device *dev);
static struct i2c_driver adm1031_driver = {
.owner = THIS_MODULE,
.name = "adm1031",
.flags = I2C_DF_NOTIFY,
.attach_adapter = adm1031_attach_adapter,
.detach_client = adm1031_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/adm9240.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ static struct i2c_driver adm9240_driver = {
.owner = THIS_MODULE,
.name = "adm9240",
.id = I2C_DRIVERID_ADM9240,
.flags = I2C_DF_NOTIFY,
.attach_adapter = adm9240_attach_adapter,
.detach_client = adm9240_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/asb100.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ static struct i2c_driver asb100_driver = {
.owner = THIS_MODULE,
.name = "asb100",
.id = I2C_DRIVERID_ASB100,
.flags = I2C_DF_NOTIFY,
.attach_adapter = asb100_attach_adapter,
.detach_client = asb100_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/atxp1.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind);
static struct i2c_driver atxp1_driver = {
.owner = THIS_MODULE,
.name = "atxp1",
.flags = I2C_DF_NOTIFY,
.attach_adapter = atxp1_attach_adapter,
.detach_client = atxp1_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/ds1621.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ static struct i2c_driver ds1621_driver = {
.owner = THIS_MODULE,
.name = "ds1621",
.id = I2C_DRIVERID_DS1621,
.flags = I2C_DF_NOTIFY,
.attach_adapter = ds1621_attach_adapter,
.detach_client = ds1621_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/fscher.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ static struct i2c_driver fscher_driver = {
.owner = THIS_MODULE,
.name = "fscher",
.id = I2C_DRIVERID_FSCHER,
.flags = I2C_DF_NOTIFY,
.attach_adapter = fscher_attach_adapter,
.detach_client = fscher_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/fscpos.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static struct i2c_driver fscpos_driver = {
.owner = THIS_MODULE,
.name = "fscpos",
.id = I2C_DRIVERID_FSCPOS,
.flags = I2C_DF_NOTIFY,
.attach_adapter = fscpos_attach_adapter,
.detach_client = fscpos_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/gl518sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ static struct i2c_driver gl518_driver = {
.owner = THIS_MODULE,
.name = "gl518sm",
.id = I2C_DRIVERID_GL518,
.flags = I2C_DF_NOTIFY,
.attach_adapter = gl518_attach_adapter,
.detach_client = gl518_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/gl520sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ static struct i2c_driver gl520_driver = {
.owner = THIS_MODULE,
.name = "gl520sm",
.id = I2C_DRIVERID_GL520,
.flags = I2C_DF_NOTIFY,
.attach_adapter = gl520_attach_adapter,
.detach_client = gl520_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/it87.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ static struct i2c_driver it87_driver = {
.owner = THIS_MODULE,
.name = "it87",
.id = I2C_DRIVERID_IT87,
.flags = I2C_DF_NOTIFY,
.attach_adapter = it87_attach_adapter,
.detach_client = it87_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/lm63.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ static void lm63_init_client(struct i2c_client *client);
static struct i2c_driver lm63_driver = {
.owner = THIS_MODULE,
.name = "lm63",
.flags = I2C_DF_NOTIFY,
.attach_adapter = lm63_attach_adapter,
.detach_client = lm63_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/lm75.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ static struct i2c_driver lm75_driver = {
.owner = THIS_MODULE,
.name = "lm75",
.id = I2C_DRIVERID_LM75,
.flags = I2C_DF_NOTIFY,
.attach_adapter = lm75_attach_adapter,
.detach_client = lm75_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/lm77.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ static struct lm77_data *lm77_update_device(struct device *dev);
static struct i2c_driver lm77_driver = {
.owner = THIS_MODULE,
.name = "lm77",
.flags = I2C_DF_NOTIFY,
.attach_adapter = lm77_attach_adapter,
.detach_client = lm77_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/lm78.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ static struct i2c_driver lm78_driver = {
.owner = THIS_MODULE,
.name = "lm78",
.id = I2C_DRIVERID_LM78,
.flags = I2C_DF_NOTIFY,
.attach_adapter = lm78_attach_adapter,
.detach_client = lm78_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/lm80.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ static struct i2c_driver lm80_driver = {
.owner = THIS_MODULE,
.name = "lm80",
.id = I2C_DRIVERID_LM80,
.flags = I2C_DF_NOTIFY,
.attach_adapter = lm80_attach_adapter,
.detach_client = lm80_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/lm83.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ static struct i2c_driver lm83_driver = {
.owner = THIS_MODULE,
.name = "lm83",
.id = I2C_DRIVERID_LM83,
.flags = I2C_DF_NOTIFY,
.attach_adapter = lm83_attach_adapter,
.detach_client = lm83_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/lm85.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ static struct i2c_driver lm85_driver = {
.owner = THIS_MODULE,
.name = "lm85",
.id = I2C_DRIVERID_LM85,
.flags = I2C_DF_NOTIFY,
.attach_adapter = lm85_attach_adapter,
.detach_client = lm85_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/lm87.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ static struct i2c_driver lm87_driver = {
.owner = THIS_MODULE,
.name = "lm87",
.id = I2C_DRIVERID_LM87,
.flags = I2C_DF_NOTIFY,
.attach_adapter = lm87_attach_adapter,
.detach_client = lm87_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/lm90.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ static struct i2c_driver lm90_driver = {
.owner = THIS_MODULE,
.name = "lm90",
.id = I2C_DRIVERID_LM90,
.flags = I2C_DF_NOTIFY,
.attach_adapter = lm90_attach_adapter,
.detach_client = lm90_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/lm92.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ static struct i2c_driver lm92_driver = {
.owner = THIS_MODULE,
.name = "lm92",
.id = I2C_DRIVERID_LM92,
.flags = I2C_DF_NOTIFY,
.attach_adapter = lm92_attach_adapter,
.detach_client = lm92_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/max1619.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ static struct max1619_data *max1619_update_device(struct device *dev);
static struct i2c_driver max1619_driver = {
.owner = THIS_MODULE,
.name = "max1619",
.flags = I2C_DF_NOTIFY,
.attach_adapter = max1619_attach_adapter,
.detach_client = max1619_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/w83781d.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ static struct i2c_driver w83781d_driver = {
.owner = THIS_MODULE,
.name = "w83781d",
.id = I2C_DRIVERID_W83781D,
.flags = I2C_DF_NOTIFY,
.attach_adapter = w83781d_attach_adapter,
.detach_client = w83781d_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/w83792d.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ static void w83792d_init_client(struct i2c_client *client);
static struct i2c_driver w83792d_driver = {
.owner = THIS_MODULE,
.name = "w83792d",
.flags = I2C_DF_NOTIFY,
.attach_adapter = w83792d_attach_adapter,
.detach_client = w83792d_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/hwmon/w83l785ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ static struct i2c_driver w83l785ts_driver = {
.owner = THIS_MODULE,
.name = "w83l785ts",
.id = I2C_DRIVERID_W83L785TS,
.flags = I2C_DF_NOTIFY,
.attach_adapter = w83l785ts_attach_adapter,
.detach_client = w83l785ts_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/chips/ds1337.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ static int ds1337_command(struct i2c_client *client, unsigned int cmd,
static struct i2c_driver ds1337_driver = {
.owner = THIS_MODULE,
.name = "ds1337",
.flags = I2C_DF_NOTIFY,
.attach_adapter = ds1337_attach_adapter,
.detach_client = ds1337_detach_client,
.command = ds1337_command,
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/chips/ds1374.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ static struct i2c_driver ds1374_driver = {
.owner = THIS_MODULE,
.name = DS1374_DRV_NAME,
.id = I2C_DRIVERID_DS1374,
.flags = I2C_DF_NOTIFY,
.attach_adapter = ds1374_attach,
.detach_client = ds1374_detach,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/chips/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ static struct i2c_driver eeprom_driver = {
.owner = THIS_MODULE,
.name = "eeprom",
.id = I2C_DRIVERID_EEPROM,
.flags = I2C_DF_NOTIFY,
.attach_adapter = eeprom_attach_adapter,
.detach_client = eeprom_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/chips/isp1301_omap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,6 @@ static struct i2c_driver isp1301_driver = {
.name = "isp1301_omap",
.id = 1301, /* FIXME "official", i2c-ids.h */
.class = I2C_CLASS_HWMON,
.flags = I2C_DF_NOTIFY,
.attach_adapter = isp1301_scan_bus,
.detach_client = isp1301_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/chips/m41t00.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ static struct i2c_driver m41t00_driver = {
.owner = THIS_MODULE,
.name = M41T00_DRV_NAME,
.id = I2C_DRIVERID_STM41T00,
.flags = I2C_DF_NOTIFY,
.attach_adapter = m41t00_attach,
.detach_client = m41t00_detach,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/chips/max6875.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ static int max6875_detach_client(struct i2c_client *client);
static struct i2c_driver max6875_driver = {
.owner = THIS_MODULE,
.name = "max6875",
.flags = I2C_DF_NOTIFY,
.attach_adapter = max6875_attach_adapter,
.detach_client = max6875_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/chips/pca9539.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ static int pca9539_detach_client(struct i2c_client *client);
static struct i2c_driver pca9539_driver = {
.owner = THIS_MODULE,
.name = "pca9539",
.flags = I2C_DF_NOTIFY,
.attach_adapter = pca9539_attach_adapter,
.detach_client = pca9539_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/chips/pcf8574.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ static struct i2c_driver pcf8574_driver = {
.owner = THIS_MODULE,
.name = "pcf8574",
.id = I2C_DRIVERID_PCF8574,
.flags = I2C_DF_NOTIFY,
.attach_adapter = pcf8574_attach_adapter,
.detach_client = pcf8574_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/chips/pcf8591.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ static struct i2c_driver pcf8591_driver = {
.owner = THIS_MODULE,
.name = "pcf8591",
.id = I2C_DRIVERID_PCF8591,
.flags = I2C_DF_NOTIFY,
.attach_adapter = pcf8591_attach_adapter,
.detach_client = pcf8591_detach_client,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/chips/rtc8564.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ static struct i2c_driver rtc8564_driver = {
.owner = THIS_MODULE,
.name = "RTC8564",
.id = I2C_DRIVERID_RTC8564,
.flags = I2C_DF_NOTIFY,
.attach_adapter = rtc8564_probe,
.detach_client = rtc8564_detach,
.command = rtc8564_command
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/chips/tps65010.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ static int __init tps65010_scan_bus(struct i2c_adapter *bus)
static struct i2c_driver tps65010_driver = {
.owner = THIS_MODULE,
.name = "tps65010",
.flags = I2C_DF_NOTIFY,
.attach_adapter = tps65010_scan_bus,
.detach_client = __exit_p(tps65010_detach_client),
};
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/chips/x1205.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ static int x1205_command(struct i2c_client *client, unsigned int cmd,
static struct i2c_driver x1205_driver = {
.owner = THIS_MODULE,
.name = "x1205",
.flags = I2C_DF_NOTIFY,
.attach_adapter = &x1205_attach,
.detach_client = &x1205_detach,
};
Expand Down
4 changes: 2 additions & 2 deletions drivers/i2c/i2c-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
/* inform drivers of new adapters */
list_for_each(item,&drivers) {
driver = list_entry(item, struct i2c_driver, list);
if (driver->flags & I2C_DF_NOTIFY)
if (driver->attach_adapter)
/* We ignore the return code; if it fails, too bad */
driver->attach_adapter(adap);
}
Expand Down Expand Up @@ -309,7 +309,7 @@ int i2c_add_driver(struct i2c_driver *driver)
pr_debug("i2c-core: driver [%s] registered\n", driver->name);

/* now look for instances of driver on our adapters */
if (driver->flags & I2C_DF_NOTIFY) {
if (driver->attach_adapter) {
list_for_each(item,&adapters) {
adapter = list_entry(item, struct i2c_adapter, list);
driver->attach_adapter(adapter);
Expand Down
1 change: 0 additions & 1 deletion drivers/i2c/i2c-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ static struct i2c_driver i2cdev_driver = {
.owner = THIS_MODULE,
.name = "dev_driver",
.id = I2C_DRIVERID_I2CDEV,
.flags = I2C_DF_NOTIFY,
.attach_adapter = i2cdev_attach_adapter,
.detach_adapter = i2cdev_detach_adapter,
.detach_client = i2cdev_detach_client,
Expand Down
1 change: 0 additions & 1 deletion drivers/macintosh/therm_adt746x.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ detach_thermostat(struct i2c_adapter *adapter)
static struct i2c_driver thermostat_driver = {
.owner = THIS_MODULE,
.name = "therm_adt746x",
.flags = I2C_DF_NOTIFY,
.attach_adapter = attach_thermostat,
.detach_adapter = detach_thermostat,
};
Expand Down
1 change: 0 additions & 1 deletion drivers/macintosh/therm_pm72.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ static struct i2c_driver therm_pm72_driver =
{
.owner = THIS_MODULE,
.name = "therm_pm72",
.flags = I2C_DF_NOTIFY,
.attach_adapter = therm_pm72_attach,
.detach_adapter = therm_pm72_detach,
};
Expand Down
Loading

0 comments on commit 8a99475

Please sign in to comment.