From 4e6fcb41d40e51624eca5e2b9179efd4070f6598 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 9 May 2004 11:00:59 +0000 Subject: [PATCH] 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 --- kernel/chips/w83781d.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/kernel/chips/w83781d.c b/kernel/chips/w83781d.c index 4e6d9439..f68f51e2 100644 --- a/kernel/chips/w83781d.c +++ b/kernel/chips/w83781d.c @@ -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 allocated. */ struct w83781d_data { + struct i2c_client client; struct semaphore lock; int sysctl_id; 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. But it allows us to access w83781d_{read,write}_value. */ - if (!(new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct w83781d_data), - GFP_KERNEL))) { + if (!(data = kmalloc(sizeof(struct w83781d_data), GFP_KERNEL))) { err = -ENOMEM; goto ERROR0; } - data = (struct w83781d_data *) (new_client + 1); + new_client = &data->client; new_client->addr = address; init_MUTEX(&data->lock); new_client->data = data; @@ -1089,7 +1088,7 @@ static int w83781d_detect(struct i2c_adapter *adapter, int address, if (is_isa) release_region(address, W83781D_EXTENT); ERROR1: - kfree(new_client); + kfree(data); ERROR0: 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) { int err; + struct w83781d_data *data = client->data; - i2c_deregister_entry(((struct w83781d_data *) (client->data))-> - sysctl_id); + i2c_deregister_entry(data->sysctl_id); if ((err = i2c_detach_client(client))) { printk @@ -1110,18 +1109,12 @@ static int w83781d_detach_client(struct i2c_client *client) if(i2c_is_isa_client(client)) { release_region(client->addr, W83781D_EXTENT); } else { - i2c_detach_client(& - (((struct - w83781d_data *) (client->data))-> - lm75[0])); - 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); + i2c_detach_client(&(data->lm75[0])); + if (data->type != w83783s) + i2c_detach_client(&(data->lm75[1])); + kfree(data->lm75); } - kfree(client); + kfree(data); return 0; }