Commit 45004d67 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

[PATCH] i2c-core.c procfs updates

Cleanup the i2c procfs code a bit (less ifdef mess), partially based
on the lm_sensors CVS code.
parent e9ec9186
...@@ -68,22 +68,12 @@ static struct i2c_driver *drivers[I2C_DRIVER_MAX]; ...@@ -68,22 +68,12 @@ static struct i2c_driver *drivers[I2C_DRIVER_MAX];
/**** debug level */ /**** debug level */
static int i2c_debug; static int i2c_debug;
/* ---------------------------------------------------
* /proc entry declarations
*----------------------------------------------------
*/
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, static int i2cproc_register(struct i2c_adapter *adap, int bus);
loff_t *ppos); static void i2cproc_remove(int bus);
static int read_bus_i2c(char *buf, char **start, off_t offset, int len, #else
int *eof , void *private); # define i2cproc_register(adap, bus) 0
# define i2cproc_remove(bus) do { } while (0)
/* To implement the dynamic /proc/bus/i2c-? files, we need our own
implementation of the read hook */
static struct file_operations i2cproc_operations = {
.read = i2cproc_bus_read,
};
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
...@@ -109,8 +99,7 @@ int i2c_add_adapter(struct i2c_adapter *adap) ...@@ -109,8 +99,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
printk(KERN_WARNING printk(KERN_WARNING
" i2c-core.o: register_adapter(%s) - enlarge I2C_ADAP_MAX.\n", " i2c-core.o: register_adapter(%s) - enlarge I2C_ADAP_MAX.\n",
adap->name); adap->name);
res = -ENOMEM; goto fail;
goto ERROR0;
} }
adapters[i] = adap; adapters[i] = adap;
...@@ -119,26 +108,9 @@ int i2c_add_adapter(struct i2c_adapter *adap) ...@@ -119,26 +108,9 @@ int i2c_add_adapter(struct i2c_adapter *adap)
/* init data types */ /* init data types */
init_MUTEX(&adap->lock); init_MUTEX(&adap->lock);
#ifdef CONFIG_PROC_FS res = i2cproc_register(adap, i);
{ if (res)
char name[8]; return res;
struct proc_dir_entry *proc_entry;
sprintf(name,"i2c-%d", i);
proc_entry = create_proc_entry(name,0,proc_bus);
if (! proc_entry) {
printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/%s\n",
name);
res = -ENOENT;
goto ERROR1;
}
proc_entry->proc_fops = &i2cproc_operations;
proc_entry->owner = THIS_MODULE;
adap->inode = proc_entry->low_ino;
}
#endif /* def CONFIG_PROC_FS */
/* inform drivers of new adapters */ /* inform drivers of new adapters */
DRV_LOCK(); DRV_LOCK();
...@@ -154,13 +126,9 @@ int i2c_add_adapter(struct i2c_adapter *adap) ...@@ -154,13 +126,9 @@ int i2c_add_adapter(struct i2c_adapter *adap)
return 0; return 0;
fail:
ERROR1:
ADAP_LOCK();
adapters[i] = NULL;
ERROR0:
ADAP_UNLOCK(); ADAP_UNLOCK();
return res; return -ENOMEM;
} }
...@@ -214,13 +182,8 @@ int i2c_del_adapter(struct i2c_adapter *adap) ...@@ -214,13 +182,8 @@ int i2c_del_adapter(struct i2c_adapter *adap)
goto ERROR0; goto ERROR0;
} }
} }
#ifdef CONFIG_PROC_FS
{ i2cproc_remove(i);
char name[8];
sprintf(name,"i2c-%d", i);
remove_proc_entry(name, proc_bus);
}
#endif /* def CONFIG_PROC_FS */
adapters[i] = NULL; adapters[i] = NULL;
...@@ -501,10 +464,9 @@ int i2c_release_client(struct i2c_client *client) ...@@ -501,10 +464,9 @@ int i2c_release_client(struct i2c_client *client)
*/ */
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
/* This function generates the output for /proc/bus/i2c */ /* This function generates the output for /proc/bus/i2c */
int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, static int read_bus_i2c(char *buf, char **start, off_t offset,
void *private) int len, int *eof, void *private)
{ {
int i; int i;
int nr = 0; int nr = 0;
...@@ -529,10 +491,10 @@ int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, ...@@ -529,10 +491,10 @@ int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof,
} }
/* This function generates the output for /proc/bus/i2c-? */ /* This function generates the output for /proc/bus/i2c-? */
ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, static ssize_t i2cproc_bus_read(struct file *file, char *buf,
loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct inode * inode = file->f_dentry->d_inode; struct inode *inode = file->f_dentry->d_inode;
char *kbuf; char *kbuf;
struct i2c_client *client; struct i2c_client *client;
int i,j,k,order_nr,len=0; int i,j,k,order_nr,len=0;
...@@ -593,6 +555,38 @@ ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, ...@@ -593,6 +555,38 @@ ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count,
return -ENOENT; return -ENOENT;
} }
static struct file_operations i2cproc_operations = {
.read = i2cproc_bus_read,
};
static int i2cproc_register(struct i2c_adapter *adap, int bus)
{
struct proc_dir_entry *proc_entry;
char name[8];
sprintf(name, "i2c-%d", bus);
proc_entry = create_proc_entry(name, 0, proc_bus);
if (!proc_entry)
goto fail;
proc_entry->proc_fops = &i2cproc_operations;
proc_entry->owner = THIS_MODULE;
adap->inode = proc_entry->low_ino;
return 0;
fail:
printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/%s\n", name);
return -ENOENT;
}
static void i2cproc_remove(int bus)
{
char name[8];
sprintf(name,"i2c-%d", bus);
remove_proc_entry(name, proc_bus);
}
static int i2cproc_init(void) static int i2cproc_init(void)
{ {
...@@ -611,7 +605,6 @@ static int i2cproc_init(void) ...@@ -611,7 +605,6 @@ static int i2cproc_init(void)
static void __exit i2cproc_cleanup(void) static void __exit i2cproc_cleanup(void)
{ {
remove_proc_entry("i2c",proc_bus); remove_proc_entry("i2c",proc_bus);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment