
From: "Luiz Fernando N. Capitulino" <lcapitulino@prefeitura.sp.gov.br>

This patch does the following cleanup for
drivers/i2c/i2c-dev.c::i2c_dev_init():

- in a error condition, return the error code of register_chrdev() insted
  of -EIO;

- adds missing audit for class_register();

- in a error condition, only prints "Driver Initialisation Failed",
  insted printing the cause.  (Note that the error will be printed by the
  return of the error code, and the information about what function caused
  the problem need to be done by a debug code).

Signed-off-by: Luiz Capitulino <lcapitulino@prefeitura.sp.gov.br>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/drivers/i2c/i2c-dev.c |   33 +++++++++++++++++++++------------
 1 files changed, 21 insertions(+), 12 deletions(-)

diff -puN drivers/i2c/i2c-dev.c~i2c-i2c-devci2c_dev_init-cleanup drivers/i2c/i2c-dev.c
--- 25/drivers/i2c/i2c-dev.c~i2c-i2c-devci2c_dev_init-cleanup	2004-07-05 13:50:31.611994936 -0700
+++ 25-akpm/drivers/i2c/i2c-dev.c	2004-07-05 13:50:31.615994328 -0700
@@ -518,20 +518,29 @@ static int __init i2c_dev_init(void)
 
 	printk(KERN_INFO "i2c /dev entries driver\n");
 
-	if (register_chrdev(I2C_MAJOR,"i2c",&i2cdev_fops)) {
-		printk(KERN_ERR "i2c-dev.o: unable to get major %d for i2c bus\n",
-		       I2C_MAJOR);
-		return -EIO;
-	}
+	res = register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops);
+	if (res)
+		goto out;
+
+	res = class_register(&i2c_dev_class);
+	if (res)
+		goto out_unreg_chrdev;
+
+	res = i2c_add_driver(&i2cdev_driver);
+	if (res)
+		goto out_unreg_class;
+
 	devfs_mk_dir("i2c");
-	class_register(&i2c_dev_class);
-	if ((res = i2c_add_driver(&i2cdev_driver))) {
-		printk(KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n");
-		devfs_remove("i2c");
-		unregister_chrdev(I2C_MAJOR,"i2c");
-		return res;
-	}
+
 	return 0;
+
+out_unreg_class:
+	class_unregister(&i2c_dev_class);
+out_unreg_chrdev:
+	unregister_chrdev(I2C_MAJOR,"i2c");
+out:
+	printk(KERN_ERR "%s: Driver Initialisation failed", __FILE__);
+	return res;
 }
 
 static void __exit i2c_dev_exit(void)
_
