From 52b2ce8f52c1bd4b321b04e9848ec62ab3c02f3f Mon Sep 17 00:00:00 2001 From: Frodo Looijaard Date: Tue, 30 Nov 1999 20:48:43 +0000 Subject: [PATCH] Patches to make it compatible with kernel 2.3.27 and newer * Improved monitoring of /proc directories Instead of doing: proc_bus_i2c->fill_inode = &monitor_bus_i2c; void monitor_bus_i2c(struct inode *inode, int fill) { if (fill) MOD_INC_USE_COUNT; else MOD_DEC_USE_COUNT; } you can now simply set: proc_bus_i2c->owner = THIS_MODULE; and this is just as good! * An old 2.3 problem seemingly never was resolved yet: instead of using a *wait_queue directly, you have to use a wait_queue_head_t and initialize it properly: #if (LINUX_VERSION_CODE < 0x020301) static struct wait_queue *pcf_wait = NULL; #else static wait_queue_head_t pcf_wait; #endif #if (LINUX_VERSION_CODE >= 0x020301) init_waitqueue_head(&pcf_wait); #endif except for this, semantics remain the same (but using a plain wait_queue_head_t instead of a pointer to a wait_queue) * I had to change the semantics of sensors_register_entry slightly, to make the monitoring of /proc/sys/dev/* files possible for kernels 2.3.27 and newer. It now takes an additional parameter, which you can specify as THIS_MODULE. * THIS_MODULE is only defined in kernels 2.3.13 and later; added it to compat.h and the compatibility section of mkpatch. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@640 7894878c-1315-0410-8ee3-d5d059ff63e0 --- kernel/chips/adm1021.c | 3 ++- kernel/chips/adm9240.c | 3 ++- kernel/chips/bt869.c | 3 ++- kernel/chips/eeprom.c | 3 ++- kernel/chips/gl518sm.c | 18 +++++++++++++++--- kernel/chips/gl520sm.c | 3 ++- kernel/chips/icspll.c | 3 ++- kernel/chips/lm75.c | 3 ++- kernel/chips/lm78.c | 3 ++- kernel/chips/lm80.c | 3 ++- kernel/chips/ltc1710.c | 3 ++- kernel/chips/matorb.c | 3 ++- kernel/chips/maxilife.c | 3 ++- kernel/chips/sis5595.c | 3 ++- kernel/chips/thmc50.c | 3 ++- kernel/chips/w83781d.c | 3 ++- kernel/include/sensors.h | 7 +++++-- kernel/sensors.c | 21 +++++++++++++++++---- 18 files changed, 67 insertions(+), 24 deletions(-) diff --git a/kernel/chips/adm1021.c b/kernel/chips/adm1021.c index 7d829991..1e3e2438 100644 --- a/kernel/chips/adm1021.c +++ b/kernel/chips/adm1021.c @@ -295,7 +295,8 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, if ((i = sensors_register_entry(new_client, type_name, data->type==adm1021?adm1021_dir_table_template: - adm1021_max_dir_table_template)) < 0) { + adm1021_max_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/chips/adm9240.c b/kernel/chips/adm9240.c index ec0ba589..c3cda05d 100644 --- a/kernel/chips/adm9240.c +++ b/kernel/chips/adm9240.c @@ -443,7 +443,8 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, /* Register a new directory entry with module sensors */ if ((i = sensors_register_entry(new_client, type_name, - adm9240_dir_table_template)) < 0) { + adm9240_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/chips/bt869.c b/kernel/chips/bt869.c index 9887a538..32f431f6 100644 --- a/kernel/chips/bt869.c +++ b/kernel/chips/bt869.c @@ -237,7 +237,8 @@ printk("bt869.o: probing address %d .\n",address); /* Register a new directory entry with module sensors */ if ((i = sensors_register_entry(new_client,type_name, - bt869_dir_table_template)) < 0) { + bt869_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/chips/eeprom.c b/kernel/chips/eeprom.c index 5e05623d..6da24aa7 100644 --- a/kernel/chips/eeprom.c +++ b/kernel/chips/eeprom.c @@ -237,7 +237,8 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, /* Register a new directory entry with module sensors */ if ((i = sensors_register_entry(new_client,type_name, - eeprom_dir_table_template)) < 0) { + eeprom_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/chips/gl518sm.c b/kernel/chips/gl518sm.c index e9665f93..aea3b916 100644 --- a/kernel/chips/gl518sm.c +++ b/kernel/chips/gl518sm.c @@ -155,8 +155,11 @@ struct gl518_data { int quit_thread; struct task_struct *thread; #endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1) + wait_queue_head_t wq; +#else struct wait_queue *wq; - +#endif char valid; /* !=0 if following fields are valid */ unsigned long last_updated; /* In jiffies */ unsigned long last_updated_v00; @@ -391,7 +394,8 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, /* Register a new directory entry with module sensors */ if ((i = sensors_register_entry((struct i2c_client *) new_client, type_name, - gl518_dir_table_template)) < 0) { + gl518_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } @@ -661,7 +665,11 @@ int gl518_update_thread(void *c) current->fs->umask = 0; strcpy(current->comm,"gl518sm"); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1) + init_waitqueue_head(&(data->wq)); +#else data->wq = NULL; +#endif data->thread = current; #ifdef __SMP__ @@ -1002,7 +1010,11 @@ void gl518_iterate(struct i2c_client *client, int operation, int ctl_name, data->quit_thread = 1; wake_up_interruptible(&data->wq); } else if ((data->iterate==2) && (! data->thread)) { - data->wq = NULL; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1) + init_waitqueue_head(&(data->wq)); +#else + data->wq = NULL; +#endif kernel_thread(gl518_update_thread, (void*) client, 0); } #endif diff --git a/kernel/chips/gl520sm.c b/kernel/chips/gl520sm.c index 1ec62cc9..2b04627a 100644 --- a/kernel/chips/gl520sm.c +++ b/kernel/chips/gl520sm.c @@ -368,7 +368,8 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, /* Register a new directory entry with module sensors */ if ((i = sensors_register_entry(new_client, type_name, - gl520_dir_table_template)) < 0) { + gl520_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/chips/icspll.c b/kernel/chips/icspll.c index d9548741..fa324e5f 100644 --- a/kernel/chips/icspll.c +++ b/kernel/chips/icspll.c @@ -182,7 +182,8 @@ int icspll_attach_adapter(struct i2c_adapter *adapter) /* Register a new directory entry with module sensors */ if ((err = sensors_register_entry(new_client,"icspll", - icspll_dir_table_template)) < 0) + icspll_dir_table_template + THIS_MODULE)) < 0) goto ERROR3; data->sysctl_id = err; err = 0; diff --git a/kernel/chips/lm75.c b/kernel/chips/lm75.c index b8e0635e..2eb9a427 100644 --- a/kernel/chips/lm75.c +++ b/kernel/chips/lm75.c @@ -216,7 +216,8 @@ int lm75_detect(struct i2c_adapter *adapter, int address, /* Register a new directory entry with module sensors */ if ((i = sensors_register_entry(new_client,type_name, - lm75_dir_table_template)) < 0) { + lm75_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/chips/lm78.c b/kernel/chips/lm78.c index 172fb16d..4bf0a681 100644 --- a/kernel/chips/lm78.c +++ b/kernel/chips/lm78.c @@ -433,7 +433,8 @@ int lm78_detect(struct i2c_adapter *adapter, int address, /* Register a new directory entry with module sensors */ if ((i = sensors_register_entry(new_client, type_name, - lm78_dir_table_template)) < 0) { + lm78_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/chips/lm80.c b/kernel/chips/lm80.c index 1c855fd0..729e2f4d 100644 --- a/kernel/chips/lm80.c +++ b/kernel/chips/lm80.c @@ -362,7 +362,8 @@ int lm80_detect(struct i2c_adapter *adapter, int address, /* Register a new directory entry with module sensors */ if ((i = sensors_register_entry(new_client,type_name, - lm80_dir_table_template)) < 0) { + lm80_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/chips/ltc1710.c b/kernel/chips/ltc1710.c index 1b7f46a3..782bb135 100644 --- a/kernel/chips/ltc1710.c +++ b/kernel/chips/ltc1710.c @@ -221,7 +221,8 @@ int ltc1710_detect(struct i2c_adapter *adapter, int address, /* Register a new directory entry with module sensors */ if ((i = sensors_register_entry(new_client,type_name, - ltc1710_dir_table_template)) < 0) { + ltc1710_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/chips/matorb.c b/kernel/chips/matorb.c index 4a52a22c..2d4ed051 100644 --- a/kernel/chips/matorb.c +++ b/kernel/chips/matorb.c @@ -183,7 +183,8 @@ int matorb_detect(struct i2c_adapter *adapter, int address, /* Register a new directory entry with module sensors */ if ((i = sensors_register_entry(new_client,type_name, - matorb_dir_table_template)) < 0) { + matorb_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/chips/maxilife.c b/kernel/chips/maxilife.c index fc0f90e0..38f45b54 100644 --- a/kernel/chips/maxilife.c +++ b/kernel/chips/maxilife.c @@ -367,7 +367,8 @@ int maxi_detect_smbus(struct i2c_adapter *adapter) /* Register a new directory entry with module sensors */ if ((err = sensors_register_entry(new_client, type_name, - maxi_dir_table_template)) < 0) + maxi_dir_table_template, + THIS_MODULE)) < 0) goto ERROR4; ((struct maxi_data *) (new_client->data))->sysctl_id = err; err = 0; diff --git a/kernel/chips/sis5595.c b/kernel/chips/sis5595.c index 4a339417..bf468433 100644 --- a/kernel/chips/sis5595.c +++ b/kernel/chips/sis5595.c @@ -408,7 +408,8 @@ int sis5595_detect(struct i2c_adapter *adapter, int address, /* Register a new directory entry with module sensors */ if ((i = sensors_register_entry((struct i2c_client *) new_client, type_name, - sis5595_dir_table_template)) < 0) { + sis5595_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/chips/thmc50.c b/kernel/chips/thmc50.c index b680e813..899f65d6 100644 --- a/kernel/chips/thmc50.c +++ b/kernel/chips/thmc50.c @@ -259,7 +259,8 @@ int thmc50_detect(struct i2c_adapter *adapter, int address, /* Register a new directory entry with module sensors */ if ((i = sensors_register_entry(new_client,type_name, - thmc50_dir_table_template)) < 0) { + thmc50_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/chips/w83781d.c b/kernel/chips/w83781d.c index 20dacac8..5e00181d 100644 --- a/kernel/chips/w83781d.c +++ b/kernel/chips/w83781d.c @@ -808,7 +808,8 @@ int w83781d_detect(struct i2c_adapter *adapter, int address, kind == w83781d?w83781d_dir_table_template: kind == w83783s?w83783s_dir_table_template: is_isa?w83782d_i2c_dir_table_template: - w83782d_isa_dir_table_template)) < 0) { + w83782d_isa_dir_table_template, + THIS_MODULE)) < 0) { err = i; goto ERROR4; } diff --git a/kernel/include/sensors.h b/kernel/include/sensors.h index 35dc2218..0add55d8 100644 --- a/kernel/include/sensors.h +++ b/kernel/include/sensors.h @@ -70,8 +70,11 @@ extern int sensors_proc_real(ctl_table *ctl, int write, struct file * filp, copied in memory. The extra2 field of each file is set to point to client. If any driver wants subdirectories within the newly created directory, these functions must be updated! */ -extern int sensors_register_entry(struct i2c_client *client, - const char *prefix, ctl_table *ctl_template); +extern int sensors_register_entry(struct i2c_client *client , + const char *prefix, + ctl_table *ctl_template, + struct module *controlling_mod); + extern void sensors_deregister_entry(int id); diff --git a/kernel/sensors.c b/kernel/sensors.c index 2e65a32d..8eefbca8 100644 --- a/kernel/sensors.c +++ b/kernel/sensors.c @@ -63,8 +63,10 @@ static struct ctl_table_header *sensors_entries[SENSORS_ENTRY_MAX]; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) static struct i2c_client *sensors_clients[SENSORS_ENTRY_MAX]; static unsigned short sensors_inodes[SENSORS_ENTRY_MAX]; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) static void sensors_fill_inode(struct inode *inode, int fill); static void sensors_dir_fill_inode(struct inode *inode, int fill); +#endif #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */ static ctl_table sysctl_table[] = { @@ -124,9 +126,14 @@ int sensors_create_name(char **name, const char *prefix, ctl_template should be a template of the newly created directory. It is copied in memory. The extra2 field of each file is set to point to client. If any driver wants subdirectories within the newly created directory, - this function must be updated! */ + this function must be updated! + controlling_mod is the controlling module. It should usually be + THIS_MODULE when calling. Note that this symbol is not defined in + kernels before 2.3.13; define it to NULL in that case. We will not use it + for anything older than 2.3.27 anyway. */ int sensors_register_entry(struct i2c_client *client ,const char *prefix, - ctl_table *ctl_template) + ctl_table *ctl_template, + struct module *controlling_mod) { int i,res,len,id; ctl_table *new_table; @@ -186,7 +193,11 @@ int sensors_register_entry(struct i2c_client *client ,const char *prefix, } #endif /* DEBUG */ sensors_inodes[id-256] = new_header->ctl_table->child->child->de->low_ino; +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) + new_header->ctl_table->child->child->de->owner = controlling_mod; +#else new_header->ctl_table->child->child->de->fill_inode = &sensors_dir_fill_inode; +#endif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) #endif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) return id; @@ -759,9 +770,11 @@ int __init sensors_init(void) sensors_initialized = 0; if (! (sensors_proc_header = register_sysctl_table(sensors_proc,0))) return -ENOMEM; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) + sensors_proc_header->ctl_table->child->de->owner = THIS_MODULE; +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) sensors_proc_header->ctl_table->child->de->fill_inode = &sensors_fill_inode; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */ +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) */ sensors_initialized ++; return 0; }