[PATCH] i2c: Rework client usage count, 2 of 3

Make I2C_CLIENT_ALLOW_USE the default for all i2c clients. It doesn't
hurt if the usage count is actually never used for any given driver,
and allows for nice code simplifications in i2c-core.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Jean Delvare 2005-11-26 21:00:54 +01:00 committed by Greg Kroah-Hartman
parent cb748fb201
commit cde7859bda
29 changed files with 10 additions and 46 deletions

View File

@ -133,7 +133,6 @@ static struct i2c_driver max7310_i2c_driver = {
static struct i2c_client max7310_template = { static struct i2c_client max7310_template = {
name: "akita-max7310", name: "akita-max7310",
flags: I2C_CLIENT_ALLOW_USE,
driver: &max7310_i2c_driver, driver: &max7310_i2c_driver,
}; };

View File

@ -155,7 +155,6 @@ static int rtc8564_attach(struct i2c_adapter *adap, int addr, int kind)
strlcpy(new_client->name, "RTC8564", I2C_NAME_SIZE); strlcpy(new_client->name, "RTC8564", I2C_NAME_SIZE);
i2c_set_clientdata(new_client, d); i2c_set_clientdata(new_client, d);
new_client->flags = I2C_CLIENT_ALLOW_USE;
new_client->addr = addr; new_client->addr = addr;
new_client->adapter = adap; new_client->adapter = adap;
new_client->driver = &rtc8564_driver; new_client->driver = &rtc8564_driver;

View File

@ -419,7 +419,6 @@ int i2c_attach_client(struct i2c_client *client)
} }
} }
if (client->flags & I2C_CLIENT_ALLOW_USE)
client->usage_count = 0; client->usage_count = 0;
client->dev.parent = &client->adapter->dev; client->dev.parent = &client->adapter->dev;
@ -443,8 +442,7 @@ int i2c_detach_client(struct i2c_client *client)
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
int res = 0; int res = 0;
if ((client->flags & I2C_CLIENT_ALLOW_USE) if (client->usage_count > 0) {
&& (client->usage_count > 0)) {
dev_warn(&client->dev, "Client [%s] still busy, " dev_warn(&client->dev, "Client [%s] still busy, "
"can't detach\n", client->name); "can't detach\n", client->name);
return -EBUSY; return -EBUSY;
@ -499,12 +497,9 @@ int i2c_use_client(struct i2c_client *client)
if (ret) if (ret)
return ret; return ret;
if (client->flags & I2C_CLIENT_ALLOW_USE) {
if (client->usage_count > 0) if (client->usage_count > 0)
goto busy; goto busy;
else
client->usage_count++; client->usage_count++;
}
return 0; return 0;
busy: busy:
@ -514,16 +509,13 @@ int i2c_use_client(struct i2c_client *client)
int i2c_release_client(struct i2c_client *client) int i2c_release_client(struct i2c_client *client)
{ {
if(client->flags & I2C_CLIENT_ALLOW_USE) { if (!client->usage_count) {
if(client->usage_count>0)
client->usage_count--;
else {
pr_debug("i2c-core: %s used one too many times\n", pr_debug("i2c-core: %s used one too many times\n",
__FUNCTION__); __FUNCTION__);
return -EPERM; return -EPERM;
} }
}
client->usage_count--;
i2c_dec_use_client(client); i2c_dec_use_client(client);
return 0; return 0;

View File

@ -420,7 +420,6 @@ adv7170_detect_client (struct i2c_adapter *adapter,
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_adv7170; client->driver = &i2c_driver_adv7170;
client->flags = I2C_CLIENT_ALLOW_USE;
if ((client->addr == I2C_ADV7170 >> 1) || if ((client->addr == I2C_ADV7170 >> 1) ||
(client->addr == (I2C_ADV7170 >> 1) + 1)) { (client->addr == (I2C_ADV7170 >> 1) + 1)) {
dname = adv7170_name; dname = adv7170_name;

View File

@ -470,7 +470,6 @@ adv7175_detect_client (struct i2c_adapter *adapter,
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_adv7175; client->driver = &i2c_driver_adv7175;
client->flags = I2C_CLIENT_ALLOW_USE;
if ((client->addr == I2C_ADV7175 >> 1) || if ((client->addr == I2C_ADV7175 >> 1) ||
(client->addr == (I2C_ADV7175 >> 1) + 1)) { (client->addr == (I2C_ADV7175 >> 1) + 1)) {
dname = adv7175_name; dname = adv7175_name;

View File

@ -535,7 +535,6 @@ bt819_detect_client (struct i2c_adapter *adapter,
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_bt819; client->driver = &i2c_driver_bt819;
client->flags = I2C_CLIENT_ALLOW_USE;
decoder = kmalloc(sizeof(struct bt819), GFP_KERNEL); decoder = kmalloc(sizeof(struct bt819), GFP_KERNEL);
if (decoder == NULL) { if (decoder == NULL) {

View File

@ -240,7 +240,6 @@ static struct i2c_driver driver = {
static struct i2c_client client_template = static struct i2c_client client_template =
{ {
.name = "bt832", .name = "bt832",
.flags = I2C_CLIENT_ALLOW_USE,
.driver = &driver, .driver = &driver,
}; };

View File

@ -323,7 +323,6 @@ bt856_detect_client (struct i2c_adapter *adapter,
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_bt856; client->driver = &i2c_driver_bt856;
client->flags = I2C_CLIENT_ALLOW_USE;
strlcpy(I2C_NAME(client), "bt856", sizeof(I2C_NAME(client))); strlcpy(I2C_NAME(client), "bt856", sizeof(I2C_NAME(client)));
encoder = kmalloc(sizeof(struct bt856), GFP_KERNEL); encoder = kmalloc(sizeof(struct bt856), GFP_KERNEL);

View File

@ -154,7 +154,6 @@ static int cs53l32a_attach(struct i2c_adapter *adapter, int address, int kind)
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver; client->driver = &i2c_driver;
client->flags = I2C_CLIENT_ALLOW_USE;
snprintf(client->name, sizeof(client->name) - 1, "cs53l32a"); snprintf(client->name, sizeof(client->name) - 1, "cs53l32a");
cs53l32a_info("chip found @ 0x%x (%s)\n", address << 1, adapter->name); cs53l32a_info("chip found @ 0x%x (%s)\n", address << 1, adapter->name);

View File

@ -773,7 +773,6 @@ static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_cx25840; client->driver = &i2c_driver_cx25840;
client->flags = I2C_CLIENT_ALLOW_USE;
snprintf(client->name, sizeof(client->name) - 1, "cx25840"); snprintf(client->name, sizeof(client->name) - 1, "cx25840");
cx25840_dbg("detecting cx25840 client on address 0x%x\n", address << 1); cx25840_dbg("detecting cx25840 client on address 0x%x\n", address << 1);

View File

@ -497,7 +497,6 @@ static struct i2c_adapter em28xx_adap_template = {
static struct i2c_client em28xx_client_template = { static struct i2c_client em28xx_client_template = {
.name = "em28xx internal", .name = "em28xx internal",
.flags = I2C_CLIENT_ALLOW_USE,
}; };
/* ----------------------------------------------------------- */ /* ----------------------------------------------------------- */

View File

@ -1576,7 +1576,6 @@ static struct i2c_driver driver = {
static struct i2c_client client_template = static struct i2c_client client_template =
{ {
.name = "(unset)", .name = "(unset)",
.flags = I2C_CLIENT_ALLOW_USE,
.driver = &driver, .driver = &driver,
}; };

View File

@ -505,7 +505,6 @@ static struct i2c_driver driver = {
static struct i2c_client client_template = { static struct i2c_client client_template = {
.name = "saa6588", .name = "saa6588",
.flags = I2C_CLIENT_ALLOW_USE,
.driver = &driver, .driver = &driver,
}; };

View File

@ -501,7 +501,6 @@ saa7110_detect_client (struct i2c_adapter *adapter,
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_saa7110; client->driver = &i2c_driver_saa7110;
client->flags = I2C_CLIENT_ALLOW_USE;
strlcpy(I2C_NAME(client), "saa7110", sizeof(I2C_NAME(client))); strlcpy(I2C_NAME(client), "saa7110", sizeof(I2C_NAME(client)));
decoder = kmalloc(sizeof(struct saa7110), GFP_KERNEL); decoder = kmalloc(sizeof(struct saa7110), GFP_KERNEL);

View File

@ -518,7 +518,6 @@ saa7111_detect_client (struct i2c_adapter *adapter,
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_saa7111; client->driver = &i2c_driver_saa7111;
client->flags = I2C_CLIENT_ALLOW_USE;
strlcpy(I2C_NAME(client), "saa7111", sizeof(I2C_NAME(client))); strlcpy(I2C_NAME(client), "saa7111", sizeof(I2C_NAME(client)));
decoder = kmalloc(sizeof(struct saa7111), GFP_KERNEL); decoder = kmalloc(sizeof(struct saa7111), GFP_KERNEL);

View File

@ -859,7 +859,6 @@ saa7114_detect_client (struct i2c_adapter *adapter,
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_saa7114; client->driver = &i2c_driver_saa7114;
client->flags = I2C_CLIENT_ALLOW_USE;
strlcpy(I2C_NAME(client), "saa7114", sizeof(I2C_NAME(client))); strlcpy(I2C_NAME(client), "saa7114", sizeof(I2C_NAME(client)));
decoder = kmalloc(sizeof(struct saa7114), GFP_KERNEL); decoder = kmalloc(sizeof(struct saa7114), GFP_KERNEL);

View File

@ -1270,7 +1270,6 @@ static int saa7115_attach(struct i2c_adapter *adapter, int address, int kind)
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_saa7115; client->driver = &i2c_driver_saa7115;
client->flags = I2C_CLIENT_ALLOW_USE;
snprintf(client->name, sizeof(client->name) - 1, "saa7115"); snprintf(client->name, sizeof(client->name) - 1, "saa7115");
saa7115_dbg("detecting saa7115 client on address 0x%x\n", address << 1); saa7115_dbg("detecting saa7115 client on address 0x%x\n", address << 1);

View File

@ -494,7 +494,6 @@ saa711x_detect_client (struct i2c_adapter *adapter,
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_saa711x; client->driver = &i2c_driver_saa711x;
client->flags = I2C_CLIENT_ALLOW_USE;
strlcpy(I2C_NAME(client), "saa711x", sizeof(I2C_NAME(client))); strlcpy(I2C_NAME(client), "saa711x", sizeof(I2C_NAME(client)));
decoder = kmalloc(sizeof(struct saa711x), GFP_KERNEL); decoder = kmalloc(sizeof(struct saa711x), GFP_KERNEL);
if (decoder == NULL) { if (decoder == NULL) {

View File

@ -719,7 +719,6 @@ static int saa7127_attach(struct i2c_adapter *adapter, int address, int kind)
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_saa7127; client->driver = &i2c_driver_saa7127;
client->flags = I2C_CLIENT_ALLOW_USE;
snprintf(client->name, sizeof(client->name) - 1, "saa7127"); snprintf(client->name, sizeof(client->name) - 1, "saa7127");
saa7127_dbg("detecting saa7127 client on address 0x%x\n", address << 1); saa7127_dbg("detecting saa7127 client on address 0x%x\n", address << 1);

View File

@ -608,7 +608,6 @@ static struct i2c_driver driver = {
static struct i2c_client client_template = static struct i2c_client client_template =
{ {
.name = "saa6752hs", .name = "saa6752hs",
.flags = I2C_CLIENT_ALLOW_USE,
.driver = &driver, .driver = &driver,
}; };

View File

@ -415,7 +415,6 @@ saa7185_detect_client (struct i2c_adapter *adapter,
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_saa7185; client->driver = &i2c_driver_saa7185;
client->flags = I2C_CLIENT_ALLOW_USE;
strlcpy(I2C_NAME(client), "saa7185", sizeof(I2C_NAME(client))); strlcpy(I2C_NAME(client), "saa7185", sizeof(I2C_NAME(client)));
encoder = kmalloc(sizeof(struct saa7185), GFP_KERNEL); encoder = kmalloc(sizeof(struct saa7185), GFP_KERNEL);

View File

@ -833,7 +833,6 @@ static struct i2c_driver driver = {
static struct i2c_client client_template = static struct i2c_client client_template =
{ {
.name = "tda9887", .name = "tda9887",
.flags = I2C_CLIENT_ALLOW_USE,
.driver = &driver, .driver = &driver,
}; };

View File

@ -755,7 +755,6 @@ static struct i2c_driver driver = {
}; };
static struct i2c_client client_template = { static struct i2c_client client_template = {
.name = "(tuner unset)", .name = "(tuner unset)",
.flags = I2C_CLIENT_ALLOW_USE,
.driver = &driver, .driver = &driver,
}; };

View File

@ -1713,7 +1713,6 @@ static struct i2c_driver driver = {
static struct i2c_client client_template = static struct i2c_client client_template =
{ {
.name = "(unset)", .name = "(unset)",
.flags = I2C_CLIENT_ALLOW_USE,
.driver = &driver, .driver = &driver,
}; };

View File

@ -751,7 +751,6 @@ tveeprom_detect_client(struct i2c_adapter *adapter,
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver_tveeprom; client->driver = &i2c_driver_tveeprom;
client->flags = I2C_CLIENT_ALLOW_USE;
snprintf(client->name, sizeof(client->name), "tveeprom"); snprintf(client->name, sizeof(client->name), "tveeprom");
i2c_attach_client(client); i2c_attach_client(client);

View File

@ -714,7 +714,6 @@ static struct i2c_driver driver;
static struct i2c_client client_template = { static struct i2c_client client_template = {
.name = "(unset)", .name = "(unset)",
.flags = I2C_CLIENT_ALLOW_USE,
.driver = &driver, .driver = &driver,
}; };

View File

@ -631,7 +631,6 @@ vpx3220_detect_client (struct i2c_adapter *adapter,
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &vpx3220_i2c_driver; client->driver = &vpx3220_i2c_driver;
client->flags = I2C_CLIENT_ALLOW_USE;
/* Check for manufacture ID and part number */ /* Check for manufacture ID and part number */
if (kind < 0) { if (kind < 0) {

View File

@ -168,7 +168,6 @@ static int wm8775_attach(struct i2c_adapter *adapter, int address, int kind)
client->addr = address; client->addr = address;
client->adapter = adapter; client->adapter = adapter;
client->driver = &i2c_driver; client->driver = &i2c_driver;
client->flags = I2C_CLIENT_ALLOW_USE;
snprintf(client->name, sizeof(client->name) - 1, "wm8775"); snprintf(client->name, sizeof(client->name) - 1, "wm8775");
wm8775_info("chip found @ 0x%x (%s)\n", address << 1, adapter->name); wm8775_info("chip found @ 0x%x (%s)\n", address << 1, adapter->name);

View File

@ -250,7 +250,6 @@ static inline void i2c_set_adapdata (struct i2c_adapter *dev, void *data)
} }
/*flags for the client struct: */ /*flags for the client struct: */
#define I2C_CLIENT_ALLOW_USE 0x01 /* Client allows access */
#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ #define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */ #define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */
/* Must equal I2C_M_TEN below */ /* Must equal I2C_M_TEN below */