diff --git a/TODO b/TODO index a2fe5f40..711472f9 100644 --- a/TODO +++ b/TODO @@ -10,10 +10,6 @@ I2C CODE CHANGES KERNEL MODULES ============== -* All clients: We can remove the foo_list of registered clients. They are not - used anymore. -* Most clients: Some typecasts to `struct i2c_client' are completely - unnecessary by now. Remove them. * LM78 detection: Tom Webster has proven that the reset bit in the id register can be one (strange!) * maxilife.c: Introduce new insmod variables diff --git a/kernel/chips/adm1021.c b/kernel/chips/adm1021.c index f016dd1a..921fa7f8 100644 --- a/kernel/chips/adm1021.c +++ b/kernel/chips/adm1021.c @@ -182,8 +182,7 @@ static int __initdata adm1021_initialized = 0; /* I choose here for semi-static allocation. Complete dynamic allocation could also be used; the code needed for this would probably take more memory than the datastructure takes now. */ -#define MAX_ADM1021_NR 9 -static struct i2c_client *adm1021_list[MAX_ADM1021_NR]; +static int adm1021_id = 0; int adm1021_attach_adapter(struct i2c_adapter *adapter) { @@ -274,17 +273,7 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) strcpy(new_client->name,client_name); data->type = kind; - for(i = 0; i < MAX_ADM1021_NR; i++) - if (! adm1021_list[i]) - break; - if (i == MAX_ADM1021_NR) { - printk("adm1021.o: No empty slots left, recompile and heighten " - "MAX_ADM1021_NR!\n"); - err = -ENOMEM; - goto ERROR2; - } - adm1021_list[i] = new_client; - new_client->id = i; + new_client->id = adm1021_id++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -293,7 +282,7 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) goto ERROR3; /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry((struct i2c_client *) new_client, + if ((i = sensors_register_entry(new_client, type_name, data->type==adm1021?adm1021_dir_table_template: adm1021_max_dir_table_template)) < 0) { @@ -303,7 +292,7 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) data->sysctl_id = i; /* Initialize the ADM1021 chip */ - adm1021_init_client((struct i2c_client *) new_client); + adm1021_init_client(new_client); return 0; /* OK, this is not exactly good programming practice, usually. But it is @@ -312,10 +301,6 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_ADM1021_NR; i++) - if (new_client == adm1021_list[i]) - adm1021_list[i] = NULL; -ERROR2: ERROR1: kfree(new_client); ERROR0: @@ -342,7 +327,7 @@ void adm1021_init_client(struct i2c_client *client) int adm1021_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct adm1021_data *)(client->data))->sysctl_id); @@ -351,15 +336,6 @@ int adm1021_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_ADM1021_NR; i++) - if (client == adm1021_list[i]) - break; - if ((i == MAX_ADM1021_NR)) { - printk("adm1021.o: Client to detach not found.\n"); - return -ENOENT; - } - adm1021_list[i] = NULL; - kfree(client); return 0; diff --git a/kernel/chips/adm9240.c b/kernel/chips/adm9240.c index 82e28b63..4634895c 100644 --- a/kernel/chips/adm9240.c +++ b/kernel/chips/adm9240.c @@ -286,8 +286,7 @@ static void adm9240_vid(struct i2c_client *client, int operation, int ctl_name, /* I choose here for semi-static ADM9240 allocation. Complete dynamic allocation could also be used; the code needed for this would probably take more memory than the datastructure takes now. */ -#define MAX_ADM9240_NR 4 -static struct i2c_client *adm9240_list[MAX_ADM9240_NR]; +static int adm9240_id = 0; static struct i2c_driver adm9240_driver = { /* name */ "ADM9240 sensor driver", @@ -427,17 +426,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) strcpy(new_client->name,client_name); data->type = kind; - for(i = 0; i < MAX_ADM9240_NR; i++) - if (! adm9240_list[i]) - break; - if (i == MAX_ADM9240_NR) { - printk("adm9240.o: No empty slots left, recompile and heighten " - "MAX_ADM9240_NR!\n"); - err = -ENOMEM; - goto ERROR2; - } - adm9240_list[i] = new_client; - new_client->id = i; + new_client->id = adm9240_id ++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -446,7 +435,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) goto ERROR3; /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry((struct i2c_client *) new_client, + if ((i = sensors_register_entry(new_client, type_name, adm9240_dir_table_template)) < 0) { err = i; @@ -455,7 +444,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) data->sysctl_id = i; /* Initialize the ADM9240 chip */ - adm9240_init_client((struct i2c_client *) new_client); + adm9240_init_client(new_client); return 0; /* OK, this is not exactly good programming practice, usually. But it is @@ -464,10 +453,6 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_ADM9240_NR; i++) - if (new_client == adm9240_list[i]) - adm9240_list[i] = NULL; -ERROR2: ERROR1: kfree(new_client); ERROR0: @@ -476,7 +461,7 @@ ERROR0: int adm9240_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct adm9240_data *)(client->data))->sysctl_id); @@ -485,15 +470,6 @@ int adm9240_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_ADM9240_NR; i++) - if (client == adm9240_list[i]) - break; - if ((i == MAX_ADM9240_NR)) { - printk("adm9240.o: Client to detach not found.\n"); - return -ENOENT; - } - adm9240_list[i] = NULL; - kfree(client); return 0; diff --git a/kernel/chips/bt869.c b/kernel/chips/bt869.c index 84bf9e73..e4deccf0 100644 --- a/kernel/chips/bt869.c +++ b/kernel/chips/bt869.c @@ -151,12 +151,7 @@ static ctl_table bt869_dir_table_template[] = { /* Used by init/cleanup */ static int __initdata bt869_initialized = 0; -/* I choose here for semi-static bt869 allocation. Complete dynamic - allocation could also be used; the code needed for this would probably - take more memory than the datastructure takes now. */ -#define MAX_bt869_NR 16 -static struct i2c_client *bt869_list[MAX_bt869_NR]; - +int bt869_id = 0; int bt869_attach_adapter(struct i2c_adapter *adapter) { @@ -226,18 +221,7 @@ printk("bt869.o: probing address %d .\n",address); /* Fill in the remaining client fields and put it into the global list */ strcpy(new_client->name,client_name); - /* Find a place in our global list */ - for (i = 0; i < MAX_bt869_NR; i++) - if (! bt869_list[i]) - break; - if (i == MAX_bt869_NR) { - err = -ENOMEM; - printk("bt869.o: No empty slots left, recompile and heighten " - "MAX_bt869_NR!\n"); - goto ERROR2; - } - bt869_list[i] = new_client; - new_client->id = i; + new_client->id = bt869_id++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -262,10 +246,6 @@ printk("bt869.o: probing address %d .\n",address); ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_bt869_NR; i++) - if (new_client == bt869_list[i]) - bt869_list[i] = NULL; -ERROR2: ERROR1: kfree(new_client); ERROR0: @@ -274,7 +254,7 @@ ERROR0: int bt869_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct bt869_data *)(client->data))->sysctl_id); @@ -283,15 +263,6 @@ int bt869_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_bt869_NR; i++) - if (client == bt869_list[i]) - break; - if ((i == MAX_bt869_NR)) { - printk("bt869.o: Client to detach not found.\n"); - return -ENOENT; - } - bt869_list[i] = NULL; - kfree(client); return 0; diff --git a/kernel/chips/eeprom.c b/kernel/chips/eeprom.c index 25812ee7..94b56205 100644 --- a/kernel/chips/eeprom.c +++ b/kernel/chips/eeprom.c @@ -148,11 +148,7 @@ static ctl_table eeprom_dir_table_template[] = { /* Used by init/cleanup */ static int __initdata eeprom_initialized = 0; -/* I choose here for semi-static LM78 allocation. Complete dynamic - allocation could also be used; the code needed for this would probably - take more memory than the datastructure takes now. */ -#define MAX_EEPROM_NR 8 -static struct i2c_client *eeprom_list[MAX_EEPROM_NR]; +static int eeprom_id = 0; int eeprom_attach_adapter(struct i2c_adapter *adapter) { @@ -190,7 +186,7 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) goto ERROR0; } - data = (struct eeprom_data *) (((struct i2c_client *) new_client) + 1); + data = (struct eeprom_data *) (new_client + 1); new_client->addr = address; new_client->data = data; new_client->adapter = adapter; @@ -224,18 +220,7 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) /* Fill in the remaining client fields and put it into the global list */ strcpy(new_client->name,client_name); - /* Find a place in our global list */ - for (i = 0; i < MAX_EEPROM_NR; i++) - if (! eeprom_list[i]) - break; - if (i == MAX_EEPROM_NR) { - err = -ENOMEM; - printk("eeprom.o: No empty slots left, recompile and heighten " - "MAX_EEPROM_NR!\n"); - goto ERROR2; - } - eeprom_list[i] = new_client; - new_client->id = i; + new_client->id = eeprom_id++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -259,10 +244,6 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_EEPROM_NR; i++) - if (new_client == eeprom_list[i]) - eeprom_list[i] = NULL; -ERROR2: ERROR1: kfree(new_client); ERROR0: @@ -271,7 +252,7 @@ ERROR0: int eeprom_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct eeprom_data *)(client->data))->sysctl_id); @@ -280,15 +261,6 @@ int eeprom_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_EEPROM_NR; i++) - if (client == eeprom_list[i]) - break; - if ((i == MAX_EEPROM_NR)) { - printk("eeprom.o: Client to detach not found.\n"); - return -ENOENT; - } - eeprom_list[i] = NULL; - kfree(client); return 0; diff --git a/kernel/chips/gl520sm.c b/kernel/chips/gl520sm.c index 9abdecc1..608a76c0 100644 --- a/kernel/chips/gl520sm.c +++ b/kernel/chips/gl520sm.c @@ -280,8 +280,7 @@ static int __initdata gl520_initialized = 0; /* I choose here for semi-static GL520SM allocation. Complete dynamic allocation could also be used; the code needed for this would probably take more memory than the datastructure takes now. */ -#define MAX_GL520_NR 4 -static struct i2c_client *gl520_list[MAX_GL520_NR]; +static int gl520_id = 0; int gl520_attach_adapter(struct i2c_adapter *adapter) { @@ -352,17 +351,7 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) strcpy(new_client->name,client_name); data->type = kind; - for(i = 0; i < MAX_GL520_NR; i++) - if (! gl520_list[i]) - break; - if (i == MAX_GL520_NR) { - printk("gl520sm.o: No empty slots left, recompile and heighten " - "MAX_GL520_NR!\n"); - err = -ENOMEM; - goto ERROR2; - } - gl520_list[i] = new_client; - new_client->id = i; + new_client->id = gl520_id++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -371,7 +360,7 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) goto ERROR3; /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry((struct i2c_client *) new_client, + if ((i = sensors_register_entry(new_client, type_name, gl520_dir_table_template)) < 0) { err = i; @@ -382,7 +371,7 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) /* Initialize the GL520SM chip */ data->two_temps=1; data->alarm_mask=0xff; - gl520_init_client((struct i2c_client *) new_client); + gl520_init_client(new_client); return 0; /* OK, this is not exactly good programming practice, usually. But it is @@ -391,10 +380,6 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_GL520_NR; i++) - if (new_client == gl520_list[i]) - gl520_list[i] = NULL; -ERROR2: ERROR1: kfree(new_client); ERROR0: @@ -452,7 +437,7 @@ void gl520_init_client(struct i2c_client *client) int gl520_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct gl520_data *)(client->data))->sysctl_id); @@ -461,15 +446,6 @@ int gl520_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_GL520_NR; i++) - if (client == gl520_list[i]) - break; - if ((i == MAX_GL520_NR)) { - printk("gl520sm.o: Client to detach not found.\n"); - return -ENOENT; - } - gl520_list[i] = NULL; - kfree(client); return 0; diff --git a/kernel/chips/icspll.c b/kernel/chips/icspll.c index c71b33b7..2cb438d6 100644 --- a/kernel/chips/icspll.c +++ b/kernel/chips/icspll.c @@ -118,13 +118,7 @@ static u8 tempdata[MAXBLOCK_SIZE]; /* Used by init/cleanup */ static int __initdata icspll_initialized = 0; -/* I choose here for semi-static allocation. Complete dynamic - allocation could also be used; the code needed for this would probably - take more memory than the datastructure takes now. */ -#define MAX_ICSPLL_NR 2 -static struct i2c_client *icspll_list[MAX_ICSPLL_NR]; - - +static int icspll_id = 0; int icspll_attach_adapter(struct i2c_adapter *adapter) { int address,err,i; @@ -166,22 +160,10 @@ int icspll_attach_adapter(struct i2c_adapter *adapter) continue; } - /* Find a place in our global list */ - for (i = 0; i < MAX_ICSPLL_NR; i++) - if (! icspll_list[i]) - break; - if (i == MAX_ICSPLL_NR) { - err = -ENOMEM; - printk("icspll.o: No empty slots left, recompile and heighten " - "MAX_ICSPLL_NR!\n"); - goto ERROR1; - } - icspll_list[i] = new_client; - /* Fill the new client structure with data */ data = (struct icspll_data *) (new_client + 1); new_client->data = data; - new_client->id = i; + new_client->id = icspll_id++; new_client->addr = address; new_client->adapter = adapter; new_client->driver = &icspll_driver; @@ -211,7 +193,6 @@ int icspll_attach_adapter(struct i2c_adapter *adapter) ERROR3: i2c_detach_client(new_client); ERROR2: - icspll_list[i] = NULL; ERROR1: kfree(new_client); } @@ -221,13 +202,6 @@ ERROR1: int icspll_detach_client(struct i2c_client *client) { int err,i; - for (i = 0; i < MAX_ICSPLL_NR; i++) - if (client == icspll_list[i]) - break; - if ((i == MAX_ICSPLL_NR)) { - printk("icspll.o: Client to detach not found.\n"); - return -ENOENT; - } sensors_deregister_entry(((struct icspll_data *)(client->data))->sysctl_id); @@ -236,7 +210,6 @@ int icspll_detach_client(struct i2c_client *client) return err; } - icspll_list[i] = NULL; kfree(client); return 0; } diff --git a/kernel/chips/lm75.c b/kernel/chips/lm75.c index 37ebcff3..8a643bc8 100644 --- a/kernel/chips/lm75.c +++ b/kernel/chips/lm75.c @@ -127,12 +127,7 @@ static ctl_table lm75_dir_table_template[] = { /* Used by init/cleanup */ static int __initdata lm75_initialized = 0; -/* I choose here for semi-static LM75 allocation. Complete dynamic - allocation could also be used; the code needed for this would probably - take more memory than the datastructure takes now. */ -#define MAX_LM75_NR 16 -static struct i2c_client *lm75_list[MAX_LM75_NR]; - +static int lm75_id = 0; int lm75_attach_adapter(struct i2c_adapter *adapter) { @@ -170,7 +165,7 @@ int lm75_detect(struct i2c_adapter *adapter, int address, int kind) goto ERROR0; } - data = (struct lm75_data *) (((struct i2c_client *) new_client) + 1); + data = (struct lm75_data *) (new_client + 1); new_client->addr = address; new_client->data = data; new_client->adapter = adapter; @@ -204,18 +199,7 @@ int lm75_detect(struct i2c_adapter *adapter, int address, int kind) /* Fill in the remaining client fields and put it into the global list */ strcpy(new_client->name,client_name); - /* Find a place in our global list */ - for (i = 0; i < MAX_LM75_NR; i++) - if (! lm75_list[i]) - break; - if (i == MAX_LM75_NR) { - err = -ENOMEM; - printk("lm75.o: No empty slots left, recompile and heighten " - "MAX_LM75_NR!\n"); - goto ERROR2; - } - lm75_list[i] = new_client; - new_client->id = i; + new_client->id = lm75_id++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -231,7 +215,7 @@ int lm75_detect(struct i2c_adapter *adapter, int address, int kind) } data->sysctl_id = i; - lm75_init_client((struct i2c_client *) new_client); + lm75_init_client(new_client); return 0; /* OK, this is not exactly good programming practice, usually. But it is @@ -240,10 +224,6 @@ int lm75_detect(struct i2c_adapter *adapter, int address, int kind) ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_LM75_NR; i++) - if (new_client == lm75_list[i]) - lm75_list[i] = NULL; -ERROR2: ERROR1: kfree(new_client); ERROR0: @@ -252,7 +232,7 @@ ERROR0: int lm75_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct lm75_data *)(client->data))->sysctl_id); @@ -261,15 +241,6 @@ int lm75_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_LM75_NR; i++) - if (client == lm75_list[i]) - break; - if ((i == MAX_LM75_NR)) { - printk("lm75.o: Client to detach not found.\n"); - return -ENOENT; - } - lm75_list[i] = NULL; - kfree(client); return 0; diff --git a/kernel/chips/lm78.c b/kernel/chips/lm78.c index 3371ec17..d9199167 100644 --- a/kernel/chips/lm78.c +++ b/kernel/chips/lm78.c @@ -238,12 +238,6 @@ static void lm78_alarms(struct i2c_client *client, int operation, int ctl_name, static void lm78_fan_div(struct i2c_client *client, int operation, int ctl_name, int *nrels_mag, long *results); -/* I choose here for semi-static LM78 allocation. Complete dynamic - allocation could also be used; the code needed for this would probably - take more memory than the datastructure takes now. */ -#define MAX_LM78_NR 8 -static struct i2c_client *lm78_list[MAX_LM78_NR]; - static struct i2c_driver lm78_driver = { /* name */ "LM78(-J) and LM79 sensor driver", /* id */ I2C_DRIVERID_LM78, @@ -258,6 +252,8 @@ static struct i2c_driver lm78_driver = { /* Used by lm78_init/cleanup */ static int __initdata lm78_initialized = 0; +static int lm78_id = 0; + /* The /proc/sys entries */ /* These files are created for each detected LM78. This is just a template; though at first sight, you might think we could use a statically @@ -355,15 +351,14 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) client structure, even though we cannot fill it completely yet. But it allows us to access lm78_{read,write}_value. */ - if (! (new_client = kmalloc((is_isa?sizeof(struct i2c_client): - sizeof(struct i2c_client)) + + if (! (new_client = kmalloc((sizeof(struct i2c_client)) + sizeof(struct lm78_data), GFP_KERNEL))) { err = -ENOMEM; goto ERROR0; } - data = (struct lm78_data *) (((struct i2c_client *) new_client) + 1); + data = (struct lm78_data *) (new_client + 1); if (is_isa) init_MUTEX(&data->lock); new_client->addr = address; @@ -421,17 +416,7 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) strcpy(new_client->name,client_name); data->type = kind; - for(i = 0; i < MAX_LM78_NR; i++) - if (! lm78_list[i]) - break; - if (i == MAX_LM78_NR) { - printk("lm78.o: No empty slots left, recompile and heighten " - "MAX_LM78_NR!\n"); - err = -ENOMEM; - goto ERROR2; - } - lm78_list[i] = new_client; - new_client->id = i; + new_client->id = lm78_id ++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -440,7 +425,7 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) goto ERROR3; /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry((struct i2c_client *) new_client, + if ((i = sensors_register_entry(new_client, type_name, lm78_dir_table_template)) < 0) { err = i; @@ -449,7 +434,7 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) data->sysctl_id = i; /* Initialize the LM78 chip */ - lm78_init_client((struct i2c_client *) new_client); + lm78_init_client(new_client); return 0; /* OK, this is not exactly good programming practice, usually. But it is @@ -458,10 +443,6 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind) ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_LM78_NR; i++) - if (new_client == lm78_list[i]) - lm78_list[i] = NULL; -ERROR2: if (is_isa) release_region(address,LM78_EXTENT); ERROR1: @@ -472,7 +453,7 @@ ERROR0: int lm78_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct lm78_data *)(client->data))->sysctl_id); @@ -481,15 +462,6 @@ int lm78_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_LM78_NR; i++) - if (client == lm78_list[i]) - break; - if ((i == MAX_LM78_NR)) { - printk("lm78.o: Client to detach not found.\n"); - return -ENOENT; - } - lm78_list[i] = NULL; - if i2c_is_isa_client(client) release_region(client->addr,LM78_EXTENT); kfree(client); diff --git a/kernel/chips/lm80.c b/kernel/chips/lm80.c index 34843dc5..c640a883 100644 --- a/kernel/chips/lm80.c +++ b/kernel/chips/lm80.c @@ -227,11 +227,7 @@ static void lm80_alarms(struct i2c_client *client, int operation, int ctl_name, static void lm80_fan_div(struct i2c_client *client, int operation, int ctl_name, int *nrels_mag, long *results); -/* I choose here for semi-static LM80 allocation. Complete dynamic - allocation could also be used; the code needed for this would probably - take more memory than the datastructure takes now. */ -#define MAX_LM80_NR 4 -static struct i2c_client *lm80_list[MAX_LM80_NR]; +static int lm80_id = 0; static struct i2c_driver lm80_driver = { /* name */ "LM80 sensor driver", @@ -316,7 +312,7 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind) goto ERROR0; } - data = (struct lm80_data *) (((struct i2c_client *) new_client) + 1); + data = (struct lm80_data *) (new_client + 1); new_client->addr = address; new_client->data = data; new_client->adapter = adapter; @@ -350,18 +346,7 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind) /* Fill in the remaining client fields and put it into the global list */ strcpy(new_client->name,client_name); - /* Find a place in our global list */ - for (i = 0; i < MAX_LM80_NR; i++) - if (! lm80_list[i]) - break; - if (i == MAX_LM80_NR) { - err = -ENOMEM; - printk("lm80.o: No empty slots left, recompile and heighten " - "MAX_LM80_NR!\n"); - goto ERROR2; - } - lm80_list[i] = new_client; - new_client->id = i; + new_client->id = lm80_id++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -385,10 +370,6 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind) ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_LM80_NR; i++) - if (new_client == lm80_list[i]) - lm80_list[i] = NULL; -ERROR2: ERROR1: kfree(new_client); ERROR0: @@ -397,7 +378,7 @@ ERROR0: int lm80_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct lm80_data *)(client->data))->sysctl_id); @@ -406,15 +387,6 @@ int lm80_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_LM80_NR; i++) - if (client == lm80_list[i]) - break; - if ((i == MAX_LM80_NR)) { - printk("lm80.o: Client to detach not found.\n"); - return -ENOENT; - } - lm80_list[i] = NULL; - kfree(client); return 0; diff --git a/kernel/chips/ltc1710.c b/kernel/chips/ltc1710.c index a8ca1c3a..1ed981d2 100644 --- a/kernel/chips/ltc1710.c +++ b/kernel/chips/ltc1710.c @@ -141,8 +141,7 @@ static int __initdata ltc1710_initialized = 0; /* I choose here for semi-static LTC1710 allocation. Complete dynamic allocation could also be used; the code needed for this would probably take more memory than the datastructure takes now. */ -#define MAX_LTC1710_NR 3 -static struct i2c_client *ltc1710_list[MAX_LTC1710_NR]; +static int ltc1710_id = 0; int ltc1710_attach_adapter(struct i2c_adapter *adapter) { @@ -180,7 +179,7 @@ int ltc1710_detect(struct i2c_adapter *adapter, int address, int kind) goto ERROR0; } - data = (struct ltc1710_data *) (((struct i2c_client *) new_client) + 1); + data = (struct ltc1710_data *) (new_client + 1); new_client->addr = address; new_client->data = data; new_client->adapter = adapter; @@ -206,18 +205,7 @@ int ltc1710_detect(struct i2c_adapter *adapter, int address, int kind) /* Fill in the remaining client fields and put it into the global list */ strcpy(new_client->name,client_name); - /* Find a place in our global list */ - for (i = 0; i < MAX_LTC1710_NR; i++) - if (! ltc1710_list[i]) - break; - if (i == MAX_LTC1710_NR) { - err = -ENOMEM; - printk("ltc1710.o: No empty slots left, recompile and heighten " - "MAX_LTC1710_NR!\n"); - goto ERROR2; - } - ltc1710_list[i] = new_client; - new_client->id = i; + new_client->id = ltc1710_id++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -241,10 +229,6 @@ int ltc1710_detect(struct i2c_adapter *adapter, int address, int kind) ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_LTC1710_NR; i++) - if (new_client == ltc1710_list[i]) - ltc1710_list[i] = NULL; -ERROR2: ERROR1: kfree(new_client); ERROR0: @@ -254,7 +238,7 @@ ERROR0: int ltc1710_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct ltc1710_data *)(client->data))->sysctl_id); @@ -263,15 +247,6 @@ int ltc1710_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_LTC1710_NR; i++) - if (client == ltc1710_list[i]) - break; - if ((i == MAX_LTC1710_NR)) { - printk("ltc1710.o: Client to detach not found.\n"); - return -ENOENT; - } - ltc1710_list[i] = NULL; - kfree(client); return 0; diff --git a/kernel/chips/matorb.c b/kernel/chips/matorb.c index 7473de16..b9e332c4 100644 --- a/kernel/chips/matorb.c +++ b/kernel/chips/matorb.c @@ -112,12 +112,7 @@ static ctl_table matorb_dir_table_template[] = { /* Used by init/cleanup */ static int __initdata matorb_initialized = 0; -/* I choose here for semi-static MATORB allocation. Complete dynamic - allocation could also be used; the code needed for this would probably - take more memory than the datastructure takes now. */ -#define MAX_MATORB_NR 16 -static struct i2c_client *matorb_list[MAX_MATORB_NR]; - +static int matorb_id = 0; int matorb_attach_adapter(struct i2c_adapter *adapter) { @@ -156,7 +151,7 @@ int matorb_detect(struct i2c_adapter *adapter, int address, int kind) goto ERROR0; } - data = (struct matorb_data *) (((struct i2c_client *) new_client) + 1); + data = (struct matorb_data *) (new_client + 1); new_client->addr = address; new_client->data = data; new_client->adapter = adapter; @@ -170,18 +165,7 @@ int matorb_detect(struct i2c_adapter *adapter, int address, int kind) /* Fill in the remaining client fields and put it into the global list */ strcpy(new_client->name,client_name); - /* Find a place in our global list */ - for (i = 0; i < MAX_MATORB_NR; i++) - if (! matorb_list[i]) - break; - if (i == MAX_MATORB_NR) { - err = -ENOMEM; - printk("matorb.o: No empty slots left, recompile and heighten " - "MAX_MATORB_NR!\n"); - goto ERROR2; - } - matorb_list[i] = new_client; - new_client->id = i; + new_client->id = matorb_id ++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -197,7 +181,7 @@ int matorb_detect(struct i2c_adapter *adapter, int address, int kind) } data->sysctl_id = i; - matorb_init_client((struct i2c_client *) new_client); + matorb_init_client(new_client); return 0; /* OK, this is not exactly good programming practice, usually. But it is @@ -206,10 +190,6 @@ int matorb_detect(struct i2c_adapter *adapter, int address, int kind) ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_MATORB_NR; i++) - if (new_client == matorb_list[i]) - matorb_list[i] = NULL; -ERROR2: kfree(new_client); ERROR0: return err; @@ -217,7 +197,7 @@ ERROR0: int matorb_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct matorb_data *)(client->data))->sysctl_id); @@ -226,15 +206,6 @@ int matorb_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_MATORB_NR; i++) - if (client == matorb_list[i]) - break; - if ((i == MAX_MATORB_NR)) { - printk("matorb.o: Client to detach not found.\n"); - return -ENOENT; - } - matorb_list[i] = NULL; - kfree(client); return 0; diff --git a/kernel/chips/maxilife.c b/kernel/chips/maxilife.c index c4a1039f..018b5460 100644 --- a/kernel/chips/maxilife.c +++ b/kernel/chips/maxilife.c @@ -198,11 +198,7 @@ static void maxi_alarms(struct i2c_client *client, int operation, int ctl_name, int *nrels_mag, long *results); -/* I choose here for semi-static MaxiLife allocation. Complete dynamic - allocation could also be used; the code needed for this would probably - take more memory than the datastructure takes now. */ -#define MAX_MAXI_NR 4 -static struct i2c_client *maxi_list[MAX_MAXI_NR]; +static int maxi_id = 0; /* The driver. I choose to use type i2c_driver, as at is identical to the smbus_driver. */ @@ -375,7 +371,7 @@ int maxi_detect_smbus(struct i2c_adapter *adapter) ERROR4: i2c_detach_client(new_client); ERROR3: - maxi_remove_client((struct i2c_client *) new_client); + maxi_remove_client(new_client); ERROR2: kfree(new_client); } @@ -384,14 +380,7 @@ ERROR2: int maxi_detach_smbus(struct i2c_client *client) { - int err,i; - for (i = 0; i < MAX_MAXI_NR; i++) - if (client == maxi_list[i]) - break; - if ((i == MAX_MAXI_NR)) { - printk("maxilife: Client to detach not found.\n"); - return -ENOENT; - } + int err; sensors_deregister_entry(((struct maxi_data *)(client->data))->sysctl_id); @@ -408,21 +397,9 @@ int maxi_detach_smbus(struct i2c_client *client) int maxi_new_client(struct i2c_adapter *adapter, struct i2c_client *new_client) { - int i; struct maxi_data *data; - /* First, seek out an empty slot */ - for (i = 0; i < MAX_MAXI_NR; i++) - if (!maxi_list[i]) - break; - if (i == MAX_MAXI_NR) { - printk("maxilife: No empty slots left, recompile and heighten " - "MAX_MAXI_NR!\n"); - return -ENOMEM; - } - - maxi_list[i] = new_client; - new_client->id = i; + new_client->id = maxi_id++; new_client->adapter = adapter; new_client->driver = &maxi_driver; data = new_client->data; @@ -435,10 +412,6 @@ int maxi_new_client(struct i2c_adapter *adapter, /* Inverse of maxi_new_client */ void maxi_remove_client(struct i2c_client *client) { - int i; - for (i = 0; i < MAX_MAXI_NR; i++) - if (client == maxi_list[i]) - maxi_list[i] = NULL; } /* No commands defined yet */ diff --git a/kernel/chips/sis5595.c b/kernel/chips/sis5595.c index a816d122..28851c0f 100644 --- a/kernel/chips/sis5595.c +++ b/kernel/chips/sis5595.c @@ -217,11 +217,7 @@ static void sis5595_alarms(struct i2c_client *client, int operation, int ctl_nam static void sis5595_fan_div(struct i2c_client *client, int operation, int ctl_name, int *nrels_mag, long *results); -/* I choose here for semi-static SIS5595 allocation. Complete dynamic - allocation could also be used; the code needed for this would probably - take more memory than the datastructure takes now. */ -#define MAX_SIS5595_NR 4 -static struct i2c_client *sis5595_list[MAX_SIS5595_NR]; +static int sis5595_id = 0; /* The driver. I choose to use type i2c_driver, as at is identical to both smbus_driver and isa_driver, and clients could be of either kind */ @@ -401,17 +397,7 @@ int sis5595_detect(struct i2c_adapter *adapter, int address, int kind) /* Fill in the remaining client fields and put it into the global list */ strcpy(new_client->name,client_name); - for(i = 0; i < MAX_SIS5595_NR; i++) - if (! sis5595_list[i]) - break; - if (i == MAX_SIS5595_NR) { - printk("sis5595.o: No empty slots left, recompile and heighten " - "MAX_SIS5595_NR!\n"); - err = -ENOMEM; - goto ERROR2; - } - sis5595_list[i] = new_client; - new_client->id = i; + new_client->id = sis5595_id++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -438,10 +424,6 @@ int sis5595_detect(struct i2c_adapter *adapter, int address, int kind) ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_SIS5595_NR; i++) - if (new_client == sis5595_list[i]) - sis5595_list[i] = NULL; -ERROR2: release_region(address,SIS5595_EXTENT); ERROR1: kfree(new_client); @@ -451,7 +433,7 @@ ERROR0: int sis5595_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct sis5595_data *)(client->data))->sysctl_id); @@ -460,15 +442,6 @@ int sis5595_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_SIS5595_NR; i++) - if (client == sis5595_list[i]) - break; - if ((i == MAX_SIS5595_NR)) { - printk("sis5595.o: Client to detach not found.\n"); - return -ENOENT; - } - sis5595_list[i] = NULL; - release_region(client->addr,SIS5595_EXTENT); kfree(client); diff --git a/kernel/chips/thmc50.c b/kernel/chips/thmc50.c index a0e9444a..9c91ac8b 100644 --- a/kernel/chips/thmc50.c +++ b/kernel/chips/thmc50.c @@ -169,12 +169,7 @@ static ctl_table thmc50_dir_table_template[] = { /* Used by init/cleanup */ static int __initdata thmc50_initialized = 0; -/* I choose here for semi-static THMC50 allocation. Complete dynamic - allocation could also be used; the code needed for this would probably - take more memory than the datastructure takes now. */ -#define MAX_THMC50_NR 16 -static struct i2c_client *thmc50_list[MAX_THMC50_NR]; - +static int thmc50_id = 0; int thmc50_attach_adapter(struct i2c_adapter *adapter) { @@ -248,18 +243,7 @@ int thmc50_detect(struct i2c_adapter *adapter, int address, int kind) /* Fill in the remaining client fields and put it into the global list */ strcpy(new_client->name,client_name); - /* Find a place in our global list */ - for (i = 0; i < MAX_THMC50_NR; i++) - if (! thmc50_list[i]) - break; - if (i == MAX_THMC50_NR) { - err = -ENOMEM; - printk("thmc50.o: No empty slots left, recompile and heighten " - "MAX_THMC50_NR!\n"); - goto ERROR2; - } - thmc50_list[i] = new_client; - new_client->id = i; + new_client->id = thmc50_id++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -275,7 +259,7 @@ int thmc50_detect(struct i2c_adapter *adapter, int address, int kind) } data->sysctl_id = i; - thmc50_init_client((struct i2c_client *) new_client); + thmc50_init_client(new_client); return 0; /* OK, this is not exactly good programming practice, usually. But it is @@ -284,10 +268,6 @@ int thmc50_detect(struct i2c_adapter *adapter, int address, int kind) ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_THMC50_NR; i++) - if (new_client == thmc50_list[i]) - thmc50_list[i] = NULL; -ERROR2: ERROR1: kfree(new_client); ERROR0: @@ -296,7 +276,7 @@ ERROR0: int thmc50_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct thmc50_data *)(client->data))->sysctl_id); @@ -305,15 +285,6 @@ int thmc50_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_THMC50_NR; i++) - if (client == thmc50_list[i]) - break; - if ((i == MAX_THMC50_NR)) { - printk("thmc50.o: Client to detach not found.\n"); - return -ENOENT; - } - thmc50_list[i] = NULL; - kfree(client); return 0; diff --git a/kernel/chips/w83781d.c b/kernel/chips/w83781d.c index d7d8cc08..556a6b4c 100644 --- a/kernel/chips/w83781d.c +++ b/kernel/chips/w83781d.c @@ -404,11 +404,7 @@ static void w83781d_rt(struct i2c_client *client, int operation, int ctl_name, int *nrels_mag, long *results); #endif -/* I choose here for semi-static W83781D allocation. Complete dynamic - allocation could also be used; the code needed for this would probably - take more memory than the datastructure takes now. */ -#define MAX_W83781D_NR 8 -static struct i2c_client *w83781d_list[MAX_W83781D_NR]; +static int w83781d_id = 0; static struct i2c_driver w83781d_driver = { /* name */ "W83781D sensor driver", @@ -694,7 +690,7 @@ int w83781d_detect(struct i2c_adapter *adapter, int address, int kind) goto ERROR0; } - data = (struct w83781d_data *) (((struct i2c_client *) new_client) + 1); + data = (struct w83781d_data *) (new_client + 1); new_client->addr = address; init_MUTEX(&data->lock); new_client->data = data; @@ -773,17 +769,7 @@ int w83781d_detect(struct i2c_adapter *adapter, int address, int kind) strcpy(new_client->name,client_name); data->type = kind; - for(i = 0; i < MAX_W83781D_NR; i++) - if (! w83781d_list[i]) - break; - if (i == MAX_W83781D_NR) { - printk("w83781d.o: No empty slots left, recompile and heighten " - "MAX_W83781D_NR!\n"); - err = -ENOMEM; - goto ERROR2; - } - w83781d_list[i] = new_client; - new_client->id = i; + new_client->id = w83781d_id++; data->valid = 0; init_MUTEX(&data->update_lock); @@ -792,7 +778,7 @@ int w83781d_detect(struct i2c_adapter *adapter, int address, int kind) goto ERROR3; /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry((struct i2c_client *) new_client, + if ((i = sensors_register_entry(new_client, type_name, kind == w83781d?w83781d_dir_table_template: kind == w83783s?w83783s_dir_table_template: @@ -813,10 +799,6 @@ int w83781d_detect(struct i2c_adapter *adapter, int address, int kind) ERROR4: i2c_detach_client(new_client); ERROR3: - for (i = 0; i < MAX_W83781D_NR; i++) - if (new_client == w83781d_list[i]) - w83781d_list[i] = NULL; -ERROR2: if (is_isa) release_region(address,W83781D_EXTENT); ERROR1: @@ -827,7 +809,7 @@ ERROR0: int w83781d_detach_client(struct i2c_client *client) { - int err,i; + int err; sensors_deregister_entry(((struct w83781d_data *)(client->data))->sysctl_id); @@ -836,15 +818,6 @@ int w83781d_detach_client(struct i2c_client *client) return err; } - for (i = 0; i < MAX_W83781D_NR; i++) - if (client == w83781d_list[i]) - break; - if (i == MAX_W83781D_NR) { - printk("w83781d.o: Client to detach not found.\n"); - return -ENOENT; - } - w83781d_list[i] = NULL; - if i2c_is_isa_client(client) release_region(client->addr,W83781D_EXTENT); kfree(client); diff --git a/kernel/include/Module.mk b/kernel/include/Module.mk index d6831d94..abbea4d7 100644 --- a/kernel/include/Module.mk +++ b/kernel/include/Module.mk @@ -26,7 +26,7 @@ ifneq ($(shell if grep -q '^CONFIG_SENSORS=y' $(LINUX)/.config; then echo 1; fi) KERNELINCLUDEFILES += $(MODULE_DIR)/sensors.h endif ifneq ($(shell if grep -q '^CONFIG_I2C_ISA=y' $(LINUX)/.config; then echo 1; fi),1) -KERNELINCLUDEFILES += $(MODULE_DIR)/isa.h +KERNELINCLUDEFILES += $(MODULE_DIR)/i2c-isa.h endif install-all-kernel-include: diff --git a/lib/Module.mk b/lib/Module.mk index 7de0cdb6..63ea7da7 100644 --- a/lib/Module.mk +++ b/lib/Module.mk @@ -19,7 +19,7 @@ # 'simply expanded variable'. That means that its value is substituted # verbatim in the rules, until it is redefined. MODULE_DIR := lib -LIBDIR := $(MODULE_DIR) +LIB_DIR := $(MODULE_DIR) # The manual dirs and files LIBMAN3DIR := $(MANDIR)/man3 @@ -97,7 +97,7 @@ install-lib: all-lib install :: install-lib clean-lib: - $(RM) $(LIBDIR)/*.ld $(LIBDIR)/*.ad - $(RM) $(LIBDIR)/*.lo $(LIBDIR)/*.ao + $(RM) $(LIB_DIR)/*.ld $(LIB_DIR)/*.ad + $(RM) $(LIB_DIR)/*.lo $(LIB_DIR)/*.ao $(RM) $(LIBTARGETS) $(LIBEXTRACLEAN) clean :: clean-lib