Commit 2dbac597 authored by Jean Delvare's avatar Jean Delvare Committed by Greg Kroah-Hartman

[PATCH] I2C: Rework memory allocation in i2c chip drivers

Additional remarks:

1* This patch also removes an unused struct member in via686a and fixes
an error message in ds1621.

2* I discovered error path problems in it87 and via686a detection
functions. For the it87, I think that this patch makes it even more
broken. I will fix both drivers in a later patch (really soon).
parent c3f20125
...@@ -101,6 +101,7 @@ clearing it. Weird, ey? --Phil */ ...@@ -101,6 +101,7 @@ clearing it. Weird, ey? --Phil */
/* Each client has this additional data */ /* Each client has this additional data */
struct adm1021_data { struct adm1021_data {
struct i2c_client client;
enum chips type; enum chips type;
struct semaphore update_lock; struct semaphore update_lock;
...@@ -228,16 +229,13 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -228,16 +229,13 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
client structure, even though we cannot fill it completely yet. client structure, even though we cannot fill it completely yet.
But it allows us to access adm1021_{read,write}_value. */ But it allows us to access adm1021_{read,write}_value. */
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct adm1021_data), GFP_KERNEL))) {
sizeof(struct adm1021_data),
GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto error0; goto error0;
} }
memset(new_client, 0x00, sizeof(struct i2c_client) + memset(data, 0, sizeof(struct adm1021_data));
sizeof(struct adm1021_data));
data = (struct adm1021_data *) (new_client + 1); new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -329,7 +327,7 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -329,7 +327,7 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
return 0; return 0;
error1: error1:
kfree(new_client); kfree(data);
error0: error0:
return err; return err;
} }
...@@ -352,7 +350,7 @@ static int adm1021_detach_client(struct i2c_client *client) ...@@ -352,7 +350,7 @@ static int adm1021_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -193,6 +193,7 @@ static u8 DIV_TO_REG(long val) ...@@ -193,6 +193,7 @@ static u8 DIV_TO_REG(long val)
data is pointed to by client->data. The structure itself is data is pointed to by client->data. The structure itself is
dynamically allocated, at the same time the client itself is allocated. */ dynamically allocated, at the same time the client itself is allocated. */
struct asb100_data { struct asb100_data {
struct i2c_client client;
struct semaphore lock; struct semaphore lock;
enum chips type; enum chips type;
...@@ -722,17 +723,14 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -722,17 +723,14 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
client structure, even though we cannot fill it completely yet. client structure, even though we cannot fill it completely yet.
But it allows us to access asb100_{read,write}_value. */ But it allows us to access asb100_{read,write}_value. */
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct asb100_data), GFP_KERNEL))) {
sizeof(struct asb100_data), GFP_KERNEL))) {
pr_debug("asb100.o: detect failed, kmalloc failed!\n"); pr_debug("asb100.o: detect failed, kmalloc failed!\n");
err = -ENOMEM; err = -ENOMEM;
goto ERROR0; goto ERROR0;
} }
memset(data, 0, sizeof(struct asb100_data));
memset(new_client, 0, new_client = &data->client;
sizeof(struct i2c_client) + sizeof(struct asb100_data));
data = (struct asb100_data *) (new_client + 1);
init_MUTEX(&data->lock); init_MUTEX(&data->lock);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
...@@ -842,7 +840,7 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -842,7 +840,7 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
ERROR2: ERROR2:
i2c_detach_client(new_client); i2c_detach_client(new_client);
ERROR1: ERROR1:
kfree(new_client); kfree(data);
ERROR0: ERROR0:
return err; return err;
} }
...@@ -857,7 +855,7 @@ static int asb100_detach_client(struct i2c_client *client) ...@@ -857,7 +855,7 @@ static int asb100_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -70,6 +70,7 @@ MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low") ...@@ -70,6 +70,7 @@ MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low")
/* Each client has this additional data */ /* Each client has this additional data */
struct ds1621_data { struct ds1621_data {
struct i2c_client client;
struct semaphore update_lock; struct semaphore update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -196,16 +197,13 @@ int ds1621_detect(struct i2c_adapter *adapter, int address, ...@@ -196,16 +197,13 @@ int ds1621_detect(struct i2c_adapter *adapter, int address,
/* OK. For now, we presume we have a valid client. We now create the /* OK. For now, we presume we have a valid client. We now create the
client structure, even though we cannot fill it completely yet. client structure, even though we cannot fill it completely yet.
But it allows us to access ds1621_{read,write}_value. */ But it allows us to access ds1621_{read,write}_value. */
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct ds1621_data), GFP_KERNEL))) {
sizeof(struct ds1621_data),
GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
memset(new_client, 0, sizeof(struct i2c_client) + memset(data, 0, sizeof(struct ds1621_data));
sizeof(struct ds1621_data));
data = (struct ds1621_data *) (new_client + 1); new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -258,7 +256,7 @@ int ds1621_detect(struct i2c_adapter *adapter, int address, ...@@ -258,7 +256,7 @@ int ds1621_detect(struct i2c_adapter *adapter, int address,
/* OK, this is not exactly good programming practice, usually. But it is /* OK, this is not exactly good programming practice, usually. But it is
very code-efficient in this case. */ very code-efficient in this case. */
exit_free: exit_free:
kfree(new_client); kfree(data);
exit: exit:
return err; return err;
} }
...@@ -268,12 +266,12 @@ static int ds1621_detach_client(struct i2c_client *client) ...@@ -268,12 +266,12 @@ static int ds1621_detach_client(struct i2c_client *client)
int err; int err;
if ((err = i2c_detach_client(client))) { if ((err = i2c_detach_client(client))) {
dev_err(&client->dev, dev_err(&client->dev, "Client deregistration failed, "
"ds1621.o: Client deregistration failed, client not detached.\n"); "client not detached.\n");
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -63,6 +63,7 @@ enum eeprom_nature { ...@@ -63,6 +63,7 @@ enum eeprom_nature {
/* Each client has this additional data */ /* Each client has this additional data */
struct eeprom_data { struct eeprom_data {
struct i2c_client client;
struct semaphore update_lock; struct semaphore update_lock;
u8 valid; /* bitfield, bit!=0 if slice is valid */ u8 valid; /* bitfield, bit!=0 if slice is valid */
unsigned long last_updated[8]; /* In jiffies, 8 slices */ unsigned long last_updated[8]; /* In jiffies, 8 slices */
...@@ -187,16 +188,13 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -187,16 +188,13 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
/* OK. For now, we presume we have a valid client. We now create the /* OK. For now, we presume we have a valid client. We now create the
client structure, even though we cannot fill it completely yet. client structure, even though we cannot fill it completely yet.
But it allows us to access eeprom_{read,write}_value. */ But it allows us to access eeprom_{read,write}_value. */
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct eeprom_data), GFP_KERNEL))) {
sizeof(struct eeprom_data),
GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
memset(new_client, 0x00, sizeof(struct i2c_client) + memset(data, 0, sizeof(struct eeprom_data));
sizeof(struct eeprom_data));
data = (struct eeprom_data *) (new_client + 1); new_client = &data->client;
memset(data->data, 0xff, EEPROM_SIZE); memset(data->data, 0xff, EEPROM_SIZE);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
...@@ -244,7 +242,7 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -244,7 +242,7 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
return 0; return 0;
exit_kfree: exit_kfree:
kfree(new_client); kfree(data);
exit: exit:
return err; return err;
} }
...@@ -259,7 +257,7 @@ static int eeprom_detach_client(struct i2c_client *client) ...@@ -259,7 +257,7 @@ static int eeprom_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -133,6 +133,7 @@ static struct i2c_driver fscher_driver = { ...@@ -133,6 +133,7 @@ static struct i2c_driver fscher_driver = {
*/ */
struct fscher_data { struct fscher_data {
struct i2c_client client;
struct semaphore update_lock; struct semaphore update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -309,17 +310,15 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -309,17 +310,15 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
/* OK. For now, we presume we have a valid client. We now create the /* OK. For now, we presume we have a valid client. We now create the
* client structure, even though we cannot fill it completely yet. * client structure, even though we cannot fill it completely yet.
* But it allows us to access i2c_smbus_read_byte_data. */ * But it allows us to access i2c_smbus_read_byte_data. */
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct fscher_data), GFP_KERNEL))) {
sizeof(struct fscher_data), GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
memset(new_client, 0x00, sizeof(struct i2c_client) + memset(data, 0, sizeof(struct fscher_data));
sizeof(struct fscher_data));
/* The Hermes-specific data is placed right after the common I2C /* The common I2C client data is placed right before the
* client data. */ * Hermes-specific data. */
data = (struct fscher_data *) (new_client + 1); new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -371,7 +370,7 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -371,7 +370,7 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
return 0; return 0;
exit_free: exit_free:
kfree(new_client); kfree(data);
exit: exit:
return err; return err;
} }
...@@ -386,7 +385,7 @@ static int fscher_detach_client(struct i2c_client *client) ...@@ -386,7 +385,7 @@ static int fscher_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -118,6 +118,7 @@ static inline u8 FAN_TO_REG(long rpm, int div) ...@@ -118,6 +118,7 @@ static inline u8 FAN_TO_REG(long rpm, int div)
/* Each client has this additional data */ /* Each client has this additional data */
struct gl518_data { struct gl518_data {
struct i2c_client client;
enum chips type; enum chips type;
struct semaphore update_lock; struct semaphore update_lock;
...@@ -354,16 +355,13 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -354,16 +355,13 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
client structure, even though we cannot fill it completely yet. client structure, even though we cannot fill it completely yet.
But it allows us to access gl518_{read,write}_value. */ But it allows us to access gl518_{read,write}_value. */
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct gl518_data), GFP_KERNEL))) {
sizeof(struct gl518_data),
GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
memset(new_client, 0x00, sizeof(struct i2c_client) + memset(data, 0, sizeof(struct gl518_data));
sizeof(struct gl518_data));
data = (struct gl518_data *) (new_client + 1); new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
...@@ -445,7 +443,7 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -445,7 +443,7 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
very code-efficient in this case. */ very code-efficient in this case. */
exit_free: exit_free:
kfree(new_client); kfree(data);
exit: exit:
return err; return err;
} }
...@@ -479,7 +477,7 @@ static int gl518_detach_client(struct i2c_client *client) ...@@ -479,7 +477,7 @@ static int gl518_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -134,6 +134,7 @@ static int DIV_TO_REG(int val) ...@@ -134,6 +134,7 @@ static int DIV_TO_REG(int val)
dynamically allocated, at the same time when a new it87 client is dynamically allocated, at the same time when a new it87 client is
allocated. */ allocated. */
struct it87_data { struct it87_data {
struct i2c_client client;
struct semaphore lock; struct semaphore lock;
enum chips type; enum chips type;
...@@ -508,7 +509,7 @@ static int it87_attach_adapter(struct i2c_adapter *adapter) ...@@ -508,7 +509,7 @@ static int it87_attach_adapter(struct i2c_adapter *adapter)
int it87_detect(struct i2c_adapter *adapter, int address, int kind) int it87_detect(struct i2c_adapter *adapter, int address, int kind)
{ {
int i; int i;
struct i2c_client *new_client = NULL; struct i2c_client *new_client;
struct it87_data *data; struct it87_data *data;
int err = 0; int err = 0;
const char *name = ""; const char *name = "";
...@@ -554,16 +555,13 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -554,16 +555,13 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind)
client structure, even though we cannot fill it completely yet. client structure, even though we cannot fill it completely yet.
But it allows us to access it87_{read,write}_value. */ But it allows us to access it87_{read,write}_value. */
if (!(new_client = kmalloc((sizeof(struct i2c_client)) + if (!(data = kmalloc(sizeof(struct it87_data), GFP_KERNEL))) {
sizeof(struct it87_data),
GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto ERROR1; goto ERROR1;
} }
memset(new_client, 0x00, sizeof(struct i2c_client) + memset(data, 0, sizeof(struct it87_data));
sizeof(struct it87_data));
data = (struct it87_data *) (new_client + 1); new_client = &data->client;
if (is_isa) if (is_isa)
init_MUTEX(&data->lock); init_MUTEX(&data->lock);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
...@@ -670,7 +668,7 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -670,7 +668,7 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind)
return 0; return 0;
ERROR1: ERROR1:
kfree(new_client); kfree(data);
if (is_isa) if (is_isa)
release_region(address, IT87_EXTENT); release_region(address, IT87_EXTENT);
...@@ -690,7 +688,7 @@ static int it87_detach_client(struct i2c_client *client) ...@@ -690,7 +688,7 @@ static int it87_detach_client(struct i2c_client *client)
if(i2c_is_isa_client(client)) if(i2c_is_isa_client(client))
release_region(client->addr, IT87_EXTENT); release_region(client->addr, IT87_EXTENT);
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -46,6 +46,7 @@ SENSORS_INSMOD_1(lm75); ...@@ -46,6 +46,7 @@ SENSORS_INSMOD_1(lm75);
/* Each client has this additional data */ /* Each client has this additional data */
struct lm75_data { struct lm75_data {
struct i2c_client client;
struct semaphore update_lock; struct semaphore update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -135,16 +136,13 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -135,16 +136,13 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
/* OK. For now, we presume we have a valid client. We now create the /* OK. For now, we presume we have a valid client. We now create the
client structure, even though we cannot fill it completely yet. client structure, even though we cannot fill it completely yet.
But it allows us to access lm75_{read,write}_value. */ But it allows us to access lm75_{read,write}_value. */
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct lm75_data), GFP_KERNEL))) {
sizeof(struct lm75_data),
GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
memset(new_client, 0x00, sizeof(struct i2c_client) + memset(data, 0, sizeof(struct lm75_data));
sizeof(struct lm75_data));
data = (struct lm75_data *) (new_client + 1); new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -194,7 +192,7 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -194,7 +192,7 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
return 0; return 0;
exit_free: exit_free:
kfree(new_client); kfree(data);
exit: exit:
return err; return err;
} }
...@@ -202,7 +200,7 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -202,7 +200,7 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
static int lm75_detach_client(struct i2c_client *client) static int lm75_detach_client(struct i2c_client *client)
{ {
i2c_detach_client(client); i2c_detach_client(client);
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -192,6 +192,7 @@ static inline u8 DIV_TO_REG(int val) ...@@ -192,6 +192,7 @@ static inline u8 DIV_TO_REG(int val)
dynamically allocated, at the same time when a new lm78 client is dynamically allocated, at the same time when a new lm78 client is
allocated. */ allocated. */
struct lm78_data { struct lm78_data {
struct i2c_client client;
struct semaphore lock; struct semaphore lock;
enum chips type; enum chips type;
...@@ -552,16 +553,13 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -552,16 +553,13 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
client structure, even though we cannot fill it completely yet. client structure, even though we cannot fill it completely yet.
But it allows us to access lm78_{read,write}_value. */ But it allows us to access lm78_{read,write}_value. */
if (!(new_client = kmalloc((sizeof(struct i2c_client)) + if (!(data = kmalloc(sizeof(struct lm78_data), GFP_KERNEL))) {
sizeof(struct lm78_data),
GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto ERROR1; goto ERROR1;
} }
memset(new_client, 0, sizeof(struct i2c_client) + memset(data, 0, sizeof(struct lm78_data));
sizeof(struct lm78_data));
data = (struct lm78_data *) (new_client + 1); new_client = &data->client;
if (is_isa) if (is_isa)
init_MUTEX(&data->lock); init_MUTEX(&data->lock);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
...@@ -671,7 +669,7 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -671,7 +669,7 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
return 0; return 0;
ERROR2: ERROR2:
kfree(new_client); kfree(data);
ERROR1: ERROR1:
if (is_isa) if (is_isa)
release_region(address, LM78_EXTENT); release_region(address, LM78_EXTENT);
...@@ -694,7 +692,7 @@ static int lm78_detach_client(struct i2c_client *client) ...@@ -694,7 +692,7 @@ static int lm78_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -110,6 +110,7 @@ static inline long TEMP_FROM_REG(u16 temp) ...@@ -110,6 +110,7 @@ static inline long TEMP_FROM_REG(u16 temp)
*/ */
struct lm80_data { struct lm80_data {
struct i2c_client client;
struct semaphore update_lock; struct semaphore update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -394,15 +395,13 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -394,15 +395,13 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
/* OK. For now, we presume we have a valid client. We now create the /* OK. For now, we presume we have a valid client. We now create the
client structure, even though we cannot fill it completely yet. client structure, even though we cannot fill it completely yet.
But it allows us to access lm80_{read,write}_value. */ But it allows us to access lm80_{read,write}_value. */
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct lm80_data), GFP_KERNEL))) {
sizeof(struct lm80_data), GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
memset(new_client, 0x00, sizeof(struct i2c_client) + memset(data, 0, sizeof(struct lm80_data));
sizeof(struct lm80_data));
data = (struct lm80_data *) (new_client + 1); new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -480,7 +479,7 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -480,7 +479,7 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
return 0; return 0;
error_free: error_free:
kfree(new_client); kfree(data);
exit: exit:
return err; return err;
} }
...@@ -495,7 +494,7 @@ static int lm80_detach_client(struct i2c_client *client) ...@@ -495,7 +494,7 @@ static int lm80_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -134,6 +134,7 @@ static struct i2c_driver lm83_driver = { ...@@ -134,6 +134,7 @@ static struct i2c_driver lm83_driver = {
*/ */
struct lm83_data { struct lm83_data {
struct i2c_client client;
struct semaphore update_lock; struct semaphore update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -234,17 +235,15 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -234,17 +235,15 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind)
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
goto exit; goto exit;
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct lm83_data), GFP_KERNEL))) {
sizeof(struct lm83_data), GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
memset(new_client, 0x00, sizeof(struct i2c_client) + memset(data, 0, sizeof(struct lm83_data));
sizeof(struct lm83_data));
/* The LM83-specific data is placed right after the common I2C /* The common I2C client data is placed right after the
* client data. */ * LM83-specific data. */
data = (struct lm83_data *) (new_client + 1); new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -329,7 +328,7 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -329,7 +328,7 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind)
return 0; return 0;
exit_free: exit_free:
kfree(new_client); kfree(data);
exit: exit:
return err; return err;
} }
...@@ -344,7 +343,7 @@ static int lm83_detach_client(struct i2c_client *client) ...@@ -344,7 +343,7 @@ static int lm83_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -351,6 +351,7 @@ struct lm85_autofan { ...@@ -351,6 +351,7 @@ struct lm85_autofan {
}; };
struct lm85_data { struct lm85_data {
struct i2c_client client;
struct semaphore lock; struct semaphore lock;
enum chips type; enum chips type;
...@@ -736,16 +737,13 @@ int lm85_detect(struct i2c_adapter *adapter, int address, ...@@ -736,16 +737,13 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
client structure, even though we cannot fill it completely yet. client structure, even though we cannot fill it completely yet.
But it allows us to access lm85_{read,write}_value. */ But it allows us to access lm85_{read,write}_value. */
if (!(new_client = kmalloc((sizeof(struct i2c_client)) + if (!(data = kmalloc(sizeof(struct lm85_data), GFP_KERNEL))) {
sizeof(struct lm85_data),
GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto ERROR0; goto ERROR0;
} }
memset(data, 0, sizeof(struct lm85_data));
memset(new_client, 0, sizeof(struct i2c_client) + new_client = &data->client;
sizeof(struct lm85_data));
data = (struct lm85_data *) (new_client + 1);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -886,7 +884,7 @@ int lm85_detect(struct i2c_adapter *adapter, int address, ...@@ -886,7 +884,7 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
/* Error out and cleanup code */ /* Error out and cleanup code */
ERROR1: ERROR1:
kfree(new_client); kfree(data);
ERROR0: ERROR0:
return err; return err;
} }
...@@ -894,7 +892,7 @@ int lm85_detect(struct i2c_adapter *adapter, int address, ...@@ -894,7 +892,7 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
int lm85_detach_client(struct i2c_client *client) int lm85_detach_client(struct i2c_client *client)
{ {
i2c_detach_client(client); i2c_detach_client(client);
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -142,6 +142,7 @@ static struct i2c_driver lm90_driver = { ...@@ -142,6 +142,7 @@ static struct i2c_driver lm90_driver = {
*/ */
struct lm90_data { struct lm90_data {
struct i2c_client client;
struct semaphore update_lock; struct semaphore update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -280,17 +281,15 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -280,17 +281,15 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
goto exit; goto exit;
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct lm90_data), GFP_KERNEL))) {
sizeof(struct lm90_data), GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
memset(new_client, 0x00, sizeof(struct i2c_client) + memset(data, 0, sizeof(struct lm90_data));
sizeof(struct lm90_data));
/* The LM90-specific data is placed right after the common I2C /* The common I2C client data is placed right before the
* client data. */ LM90-specific data. */
data = (struct lm90_data *) (new_client + 1); new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -390,7 +389,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -390,7 +389,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
return 0; return 0;
exit_free: exit_free:
kfree(new_client); kfree(data);
exit: exit:
return err; return err;
} }
...@@ -420,7 +419,7 @@ static int lm90_detach_client(struct i2c_client *client) ...@@ -420,7 +419,7 @@ static int lm90_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -55,6 +55,7 @@ SENSORS_INSMOD_2(pcf8574, pcf8574a); ...@@ -55,6 +55,7 @@ SENSORS_INSMOD_2(pcf8574, pcf8574a);
/* Each client has this additional data */ /* Each client has this additional data */
struct pcf8574_data { struct pcf8574_data {
struct i2c_client client;
struct semaphore update_lock; struct semaphore update_lock;
u8 read, write; /* Register values */ u8 read, write; /* Register values */
...@@ -127,17 +128,13 @@ int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -127,17 +128,13 @@ int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
/* OK. For now, we presume we have a valid client. We now create the /* OK. For now, we presume we have a valid client. We now create the
client structure, even though we cannot fill it completely yet. */ client structure, even though we cannot fill it completely yet. */
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) {
sizeof(struct pcf8574_data),
GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
memset(data, 0, sizeof(struct pcf8574_data));
memset(new_client, 0, sizeof(struct i2c_client) + new_client = &data->client;
sizeof(struct pcf8574_data));
data = (struct pcf8574_data *) (new_client + 1);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -182,7 +179,7 @@ int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -182,7 +179,7 @@ int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
very code-efficient in this case. */ very code-efficient in this case. */
exit_free: exit_free:
kfree(new_client); kfree(data);
exit: exit:
return err; return err;
} }
...@@ -197,7 +194,7 @@ static int pcf8574_detach_client(struct i2c_client *client) ...@@ -197,7 +194,7 @@ static int pcf8574_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -76,6 +76,7 @@ MODULE_PARM_DESC(input_mode, ...@@ -76,6 +76,7 @@ MODULE_PARM_DESC(input_mode,
#define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) #define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg))
struct pcf8591_data { struct pcf8591_data {
struct i2c_client client;
struct semaphore update_lock; struct semaphore update_lock;
u8 control; u8 control;
...@@ -177,17 +178,13 @@ int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -177,17 +178,13 @@ int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
/* OK. For now, we presume we have a valid client. We now create the /* OK. For now, we presume we have a valid client. We now create the
client structure, even though we cannot fill it completely yet. */ client structure, even though we cannot fill it completely yet. */
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) {
sizeof(struct pcf8591_data),
GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
memset(data, 0, sizeof(struct pcf8591_data));
memset(new_client, 0, sizeof(struct i2c_client) + new_client = &data->client;
sizeof(struct pcf8591_data));
data = (struct pcf8591_data *) (new_client + 1);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -235,7 +232,7 @@ int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -235,7 +232,7 @@ int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
very code-efficient in this case. */ very code-efficient in this case. */
exit_kfree: exit_kfree:
kfree(new_client); kfree(data);
exit: exit:
return err; return err;
} }
...@@ -250,7 +247,7 @@ static int pcf8591_detach_client(struct i2c_client *client) ...@@ -250,7 +247,7 @@ static int pcf8591_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -369,8 +369,7 @@ static inline long TEMP_FROM_REG10(u16 val) ...@@ -369,8 +369,7 @@ static inline long TEMP_FROM_REG10(u16 val)
dynamically allocated, at the same time when a new via686a client is dynamically allocated, at the same time when a new via686a client is
allocated. */ allocated. */
struct via686a_data { struct via686a_data {
int sysctl_id; struct i2c_client client;
struct semaphore update_lock; struct semaphore update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -687,16 +686,13 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -687,16 +686,13 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind)
return -ENODEV; return -ENODEV;
} }
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) {
sizeof(struct via686a_data),
GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto ERROR0; goto ERROR0;
} }
memset(data, 0, sizeof(struct via686a_data));
memset(new_client,0x00, sizeof(struct i2c_client) + new_client = &data->client;
sizeof(struct via686a_data));
data = (struct via686a_data *) (new_client + 1);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -753,7 +749,7 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -753,7 +749,7 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind)
ERROR3: ERROR3:
release_region(address, VIA686A_EXTENT); release_region(address, VIA686A_EXTENT);
kfree(new_client); kfree(data);
ERROR0: ERROR0:
return err; return err;
} }
...@@ -769,7 +765,7 @@ static int via686a_detach_client(struct i2c_client *client) ...@@ -769,7 +765,7 @@ static int via686a_detach_client(struct i2c_client *client)
} }
release_region(client->addr, VIA686A_EXTENT); release_region(client->addr, VIA686A_EXTENT);
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -277,6 +277,7 @@ static inline u8 DIV_TO_REG(long val) ...@@ -277,6 +277,7 @@ static inline u8 DIV_TO_REG(long val)
data is pointed to by w83627hf_list[NR]->data. The structure itself is data is pointed to by w83627hf_list[NR]->data. The structure itself is
dynamically allocated, at the same time when a new client is allocated. */ dynamically allocated, at the same time when a new client is allocated. */
struct w83627hf_data { struct w83627hf_data {
struct i2c_client client;
struct semaphore lock; struct semaphore lock;
enum chips type; enum chips type;
...@@ -941,17 +942,13 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address, ...@@ -941,17 +942,13 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address,
client structure, even though we cannot fill it completely yet. client structure, even though we cannot fill it completely yet.
But it allows us to access w83627hf_{read,write}_value. */ But it allows us to access w83627hf_{read,write}_value. */
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct w83627hf_data), GFP_KERNEL))) {
sizeof(struct w83627hf_data),
GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto ERROR1; goto ERROR1;
} }
memset(data, 0, sizeof(struct w83627hf_data));
memset(new_client, 0x00, sizeof (struct i2c_client) + new_client = &data->client;
sizeof (struct w83627hf_data));
data = (struct w83627hf_data *) (new_client + 1);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
init_MUTEX(&data->lock); init_MUTEX(&data->lock);
...@@ -1042,7 +1039,7 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address, ...@@ -1042,7 +1039,7 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address,
return 0; return 0;
ERROR2: ERROR2:
kfree(new_client); kfree(data);
ERROR1: ERROR1:
release_region(address, WINB_EXTENT); release_region(address, WINB_EXTENT);
ERROR0: ERROR0:
...@@ -1060,7 +1057,7 @@ static int w83627hf_detach_client(struct i2c_client *client) ...@@ -1060,7 +1057,7 @@ static int w83627hf_detach_client(struct i2c_client *client)
} }
release_region(client->addr, WINB_EXTENT); release_region(client->addr, WINB_EXTENT);
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -226,6 +226,7 @@ DIV_TO_REG(long val, enum chips type) ...@@ -226,6 +226,7 @@ DIV_TO_REG(long val, enum chips type)
dynamically allocated, at the same time when a new w83781d client is dynamically allocated, at the same time when a new w83781d client is
allocated. */ allocated. */
struct w83781d_data { struct w83781d_data {
struct i2c_client client;
struct semaphore lock; struct semaphore lock;
enum chips type; enum chips type;
...@@ -1112,16 +1113,13 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -1112,16 +1113,13 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
client structure, even though we cannot fill it completely yet. client structure, even though we cannot fill it completely yet.
But it allows us to access w83781d_{read,write}_value. */ But it allows us to access w83781d_{read,write}_value. */
if (!(new_client = kmalloc(sizeof (struct i2c_client) + if (!(data = kmalloc(sizeof(struct w83781d_data), GFP_KERNEL))) {
sizeof (struct w83781d_data), GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto ERROR1; goto ERROR1;
} }
memset(data, 0, sizeof(struct w83781d_data));
memset(new_client, 0x00, sizeof (struct i2c_client) + new_client = &data->client;
sizeof (struct w83781d_data));
data = (struct w83781d_data *) (new_client + 1);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
init_MUTEX(&data->lock); init_MUTEX(&data->lock);
...@@ -1321,7 +1319,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -1321,7 +1319,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
ERROR3: ERROR3:
i2c_detach_client(new_client); i2c_detach_client(new_client);
ERROR2: ERROR2:
kfree(new_client); kfree(data);
ERROR1: ERROR1:
if (is_isa) if (is_isa)
release_region(address, W83781D_EXTENT); release_region(address, W83781D_EXTENT);
...@@ -1343,7 +1341,7 @@ w83781d_detach_client(struct i2c_client *client) ...@@ -1343,7 +1341,7 @@ w83781d_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
...@@ -105,7 +105,7 @@ static struct i2c_driver w83l785ts_driver = { ...@@ -105,7 +105,7 @@ static struct i2c_driver w83l785ts_driver = {
*/ */
struct w83l785ts_data { struct w83l785ts_data {
struct i2c_client client;
struct semaphore update_lock; struct semaphore update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -164,18 +164,16 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -164,18 +164,16 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind)
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
goto exit; goto exit;
if (!(new_client = kmalloc(sizeof(struct i2c_client) + if (!(data = kmalloc(sizeof(struct w83l785ts_data), GFP_KERNEL))) {
sizeof(struct w83l785ts_data), GFP_KERNEL))) {
err = -ENOMEM; err = -ENOMEM;
goto exit; goto exit;
} }
memset(new_client, 0x00, sizeof(struct i2c_client) + memset(data, 0, sizeof(struct w83l785ts_data));
sizeof(struct w83l785ts_data));
/* The W83L785TS-specific data is placed right after the common I2C /* The common I2C client data is placed right before the
* client data. */ * W83L785TS-specific data. */
data = (struct w83l785ts_data *) (new_client + 1); new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -255,7 +253,7 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -255,7 +253,7 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind)
return 0; return 0;
exit_free: exit_free:
kfree(new_client); kfree(data);
exit: exit:
return err; return err;
} }
...@@ -270,7 +268,7 @@ static int w83l785ts_detach_client(struct i2c_client *client) ...@@ -270,7 +268,7 @@ static int w83l785ts_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); kfree(i2c_get_clientdata(client));
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment