Index: mm/drivers/hwmon/ams/ams-core.c
===================================================================
--- mm.orig/drivers/hwmon/ams/ams-core.c	2006-09-20 21:04:57.000000000 -0300
+++ mm/drivers/hwmon/ams/ams-core.c	2006-09-23 20:23:12.000000000 -0300
@@ -163,28 +163,37 @@
 	result = pmf_register_irq_client(ams_info.of_node,
 			"accel-int-2",
 			&ams_shock_client);
-	if (result < 0) {
-		pmf_unregister_irq_client(&ams_freefall_client);
-		return -ENODEV;
-	}
+	if (result < 0)
+		goto release_freefall;
 
 	/* Create device */
 	ams_info.of_dev = of_platform_device_create(ams_info.of_node, "ams", NULL);
-	if (!ams_info.of_dev) {
-		pmf_unregister_irq_client(&ams_shock_client);
-		pmf_unregister_irq_client(&ams_freefall_client);
-		return -ENODEV;
-	}
+	if (!ams_info.of_dev)
+		goto release_shock;
 
 	/* Create attributes */
-	device_create_file(&ams_info.of_dev->dev, &dev_attr_current);
+	result = device_create_file(&ams_info.of_dev->dev, &dev_attr_current);
+	if (result)
+		goto release_of;
 
 	ams_info.vflag = !!(ams_info.get_vendor() & 0x10);
 
 	/* Init mouse device */
-	ams_mouse_init();
-
-	return 0;
+	result = ams_mouse_init();
+	if (result)
+		goto release_device_file;
+
+out:
+	return result;
+release_device_file:
+	device_remove_file(&ams_info.of_dev->dev, &dev_attr_current);
+release_of:
+	of_device_unregister(ams_info.of_dev);
+release_shock:
+	pmf_unregister_irq_client(&ams_shock_client);
+release_freefall:
+	pmf_unregister_irq_client(&ams_freefall_client);
+	goto out;
 }
 
 int __init ams_init(void)
Index: mm/drivers/hwmon/ams/ams-mouse.c
===================================================================
--- mm.orig/drivers/hwmon/ams/ams-mouse.c	2006-09-20 21:07:26.000000000 -0300
+++ mm/drivers/hwmon/ams/ams-mouse.c	2006-09-20 21:08:50.000000000 -0300
@@ -127,12 +127,15 @@
 	ams_mouse_show_mouse, ams_mouse_store_mouse);
 
 /* Call with ams_info.lock held! */
-void ams_mouse_init()
+int ams_mouse_init(void)
 {
-	device_create_file(&ams_info.of_dev->dev, &dev_attr_mouse);
+	int result;
 
-	if (mouse)
+	result = device_create_file(&ams_info.of_dev->dev, &dev_attr_mouse);
+
+	if (!result && mouse)
 		ams_mouse_enable();
+	return result;
 }
 
 /* Call with ams_info.lock held! */
Index: mm/drivers/hwmon/ams/ams.h
===================================================================
--- mm.orig/drivers/hwmon/ams/ams.h	2006-09-20 21:13:23.000000000 -0300
+++ mm/drivers/hwmon/ams/ams.h	2006-09-20 21:13:28.000000000 -0300
@@ -68,5 +68,5 @@
 extern int ams_pmu_init(struct device_node *np);
 extern int ams_i2c_init(struct device_node *np);
 
-extern void ams_mouse_init(void);
+extern int ams_mouse_init(void);
 extern void ams_mouse_exit(void);

