2
0
mirror of https://github.com/lm-sensors/lm-sensors synced 2025-08-31 06:15:15 +00:00

Backport memory allocation reworking from Linux 2.6.

git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2512 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare
2004-05-08 13:37:41 +00:00
parent 16628b5165
commit 3f690ffac2

View File

@@ -187,6 +187,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;
int sysctl_id; int sysctl_id;
enum chips type; enum chips type;
@@ -464,14 +465,13 @@ static int asb100_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 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;
} }
data = (struct asb100_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;
@@ -562,7 +562,7 @@ ERROR3:
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;
} }
@@ -582,7 +582,13 @@ static int asb100_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(client); if (data) {
/* primary client */
kfree(data);
} else {
/* subclients */
kfree(client);
}
return 0; return 0;
} }