Backport memory allocation reworking from Linux 2.6.

Cleanup detach function.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2518 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2004-05-09 11:00:59 +00:00
1 parent 994875c0e4
commit 4e6fcb41d4
1 file changed
+11 -18
+11 -18
View File
@@ -248,6 +248,7 @@ static inline u8 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;
int sysctl_id; int sysctl_id;
enum chips type; enum chips type;
@@ -819,14 +820,12 @@ static int w83781d_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 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 ERROR0; goto ERROR0;
} }
data = (struct w83781d_data *) (new_client + 1); new_client = &data->client;
new_client->addr = address; new_client->addr = address;
init_MUTEX(&data->lock); init_MUTEX(&data->lock);
new_client->data = data; new_client->data = data;
@@ -1089,7 +1088,7 @@ static int w83781d_detect(struct i2c_adapter *adapter, int address,
if (is_isa) if (is_isa)
release_region(address, W83781D_EXTENT); release_region(address, W83781D_EXTENT);
ERROR1: ERROR1:
kfree(new_client); kfree(data);
ERROR0: ERROR0:
return err; return err;
} }
@@ -1097,9 +1096,9 @@ static int w83781d_detect(struct i2c_adapter *adapter, int address,
static int w83781d_detach_client(struct i2c_client *client) static int w83781d_detach_client(struct i2c_client *client)
{ {
int err; int err;
struct w83781d_data *data = client->data;
i2c_deregister_entry(((struct w83781d_data *) (client->data))-> i2c_deregister_entry(data->sysctl_id);
sysctl_id);
if ((err = i2c_detach_client(client))) { if ((err = i2c_detach_client(client))) {
printk printk
@@ -1110,18 +1109,12 @@ static int w83781d_detach_client(struct i2c_client *client)
if(i2c_is_isa_client(client)) { if(i2c_is_isa_client(client)) {
release_region(client->addr, W83781D_EXTENT); release_region(client->addr, W83781D_EXTENT);
} else { } else {
i2c_detach_client(& i2c_detach_client(&(data->lm75[0]));
(((struct if (data->type != w83783s)
w83781d_data *) (client->data))-> i2c_detach_client(&(data->lm75[1]));
lm75[0])); kfree(data->lm75);
if((((struct w83781d_data *) (client->data))->type) != w83783s)
i2c_detach_client(&
(((struct
w83781d_data *) (client->data))->
lm75[1]));
kfree(((struct w83781d_data *) (client->data))->lm75);
} }
kfree(client); kfree(data);
return 0; return 0;
} }