Commit d4a06a8b authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] i2c cleanup

	switched to devfs_remove(), killed gratitious devfs_handle_t array,
	cleaned up the failure exit path in init().
parent 24cade1f
...@@ -37,9 +37,7 @@ ...@@ -37,9 +37,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/version.h> #include <linux/version.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#ifdef CONFIG_DEVFS_FS
#include <linux/devfs_fs_kernel.h> #include <linux/devfs_fs_kernel.h>
#endif
/* If you want debugging uncomment: */ /* If you want debugging uncomment: */
...@@ -80,10 +78,6 @@ static struct file_operations i2cdev_fops = { ...@@ -80,10 +78,6 @@ static struct file_operations i2cdev_fops = {
#define I2CDEV_ADAPS_MAX I2C_ADAP_MAX #define I2CDEV_ADAPS_MAX I2C_ADAP_MAX
static struct i2c_adapter *i2cdev_adaps[I2CDEV_ADAPS_MAX]; static struct i2c_adapter *i2cdev_adaps[I2CDEV_ADAPS_MAX];
#ifdef CONFIG_DEVFS_FS
static devfs_handle_t devfs_i2c[I2CDEV_ADAPS_MAX];
static devfs_handle_t devfs_handle = NULL;
#endif
static struct i2c_driver i2cdev_driver = { static struct i2c_driver i2cdev_driver = {
.name = "i2c-dev dummy driver", .name = "i2c-dev dummy driver",
...@@ -101,8 +95,6 @@ static struct i2c_client i2cdev_client_template = { ...@@ -101,8 +95,6 @@ static struct i2c_client i2cdev_client_template = {
.driver = &i2cdev_driver, .driver = &i2cdev_driver,
}; };
static int i2cdev_initialized;
static ssize_t i2cdev_read (struct file *file, char *buf, size_t count, static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
loff_t *offset) loff_t *offset)
{ {
...@@ -399,7 +391,7 @@ static int i2cdev_release (struct inode *inode, struct file *file) ...@@ -399,7 +391,7 @@ static int i2cdev_release (struct inode *inode, struct file *file)
int i2cdev_attach_adapter(struct i2c_adapter *adap) int i2cdev_attach_adapter(struct i2c_adapter *adap)
{ {
int i; int i;
char name[8]; char name[12];
if ((i = i2c_adapter_id(adap)) < 0) { if ((i = i2c_adapter_id(adap)) < 0) {
printk(KERN_DEBUG "i2c-dev.o: Unknown adapter ?!?\n"); printk(KERN_DEBUG "i2c-dev.o: Unknown adapter ?!?\n");
...@@ -410,21 +402,17 @@ int i2cdev_attach_adapter(struct i2c_adapter *adap) ...@@ -410,21 +402,17 @@ int i2cdev_attach_adapter(struct i2c_adapter *adap)
return -ENODEV; return -ENODEV;
} }
sprintf (name, "%d", i); sprintf (name, "i2c/%d", i);
if (! i2cdev_adaps[i]) { if (! i2cdev_adaps[i]) {
i2cdev_adaps[i] = adap; i2cdev_adaps[i] = adap;
#ifdef CONFIG_DEVFS_FS devfs_register (NULL, name,
devfs_i2c[i] = devfs_register (devfs_handle, name,
DEVFS_FL_DEFAULT, I2C_MAJOR, i, DEVFS_FL_DEFAULT, I2C_MAJOR, i,
S_IFCHR | S_IRUSR | S_IWUSR, S_IFCHR | S_IRUSR | S_IWUSR,
&i2cdev_fops, NULL); &i2cdev_fops, NULL);
#endif
printk(KERN_DEBUG "i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i); printk(KERN_DEBUG "i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i);
} else { } else {
/* This is actually a detach_adapter call! */ /* This is actually a detach_adapter call! */
#ifdef CONFIG_DEVFS_FS devfs_remove("i2c/%d", i);
devfs_unregister(devfs_i2c[i]);
#endif
i2cdev_adaps[i] = NULL; i2cdev_adaps[i] = NULL;
#ifdef DEBUG #ifdef DEBUG
printk(KERN_DEBUG "i2c-dev.o: Adapter unregistered: %s\n",adap->name); printk(KERN_DEBUG "i2c-dev.o: Adapter unregistered: %s\n",adap->name);
...@@ -449,24 +437,13 @@ static void i2cdev_cleanup(void) ...@@ -449,24 +437,13 @@ static void i2cdev_cleanup(void)
{ {
int res; int res;
if (i2cdev_initialized >= 2) { if ((res = i2c_del_driver(&i2cdev_driver))) {
if ((res = i2c_del_driver(&i2cdev_driver))) { printk(KERN_ERR "i2c-dev.o: Driver deregistration failed, "
printk(KERN_ERR "i2c-dev.o: Driver deregistration failed, " "module not removed.\n");
"module not removed.\n");
}
i2cdev_initialized --;
} }
if (i2cdev_initialized >= 1) { devfs_remove("i2c");
#ifdef CONFIG_DEVFS_FS unregister_chrdev(I2C_MAJOR,"i2c");
devfs_unregister(devfs_handle);
#endif
if ((res = unregister_chrdev(I2C_MAJOR,"i2c"))) {
printk(KERN_ERR "i2c-dev.o: unable to release major %d for i2c bus\n",
I2C_MAJOR);
}
i2cdev_initialized --;
}
} }
int __init i2c_dev_init(void) int __init i2c_dev_init(void)
...@@ -475,23 +452,18 @@ int __init i2c_dev_init(void) ...@@ -475,23 +452,18 @@ int __init i2c_dev_init(void)
printk(KERN_INFO "i2c-dev.o: i2c /dev entries driver module version %s (%s)\n", I2C_VERSION, I2C_DATE); printk(KERN_INFO "i2c-dev.o: i2c /dev entries driver module version %s (%s)\n", I2C_VERSION, I2C_DATE);
i2cdev_initialized = 0;
if (register_chrdev(I2C_MAJOR,"i2c",&i2cdev_fops)) { if (register_chrdev(I2C_MAJOR,"i2c",&i2cdev_fops)) {
printk(KERN_ERR "i2c-dev.o: unable to get major %d for i2c bus\n", printk(KERN_ERR "i2c-dev.o: unable to get major %d for i2c bus\n",
I2C_MAJOR); I2C_MAJOR);
return -EIO; return -EIO;
} }
#ifdef CONFIG_DEVFS_FS devfs_mk_dir(NULL, "i2c", NULL);
devfs_handle = devfs_mk_dir(NULL, "i2c", NULL);
#endif
i2cdev_initialized ++;
if ((res = i2c_add_driver(&i2cdev_driver))) { if ((res = i2c_add_driver(&i2cdev_driver))) {
printk(KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n"); printk(KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n");
i2cdev_cleanup(); devfs_remove("i2c");
unregister_chrdev(I2C_MAJOR,"i2c");
return res; return res;
} }
i2cdev_initialized ++;
return 0; return 0;
} }
......
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