ide: add ide_host_free() helper (take 2)

* Add ide_host_free() helper and convert ide_host_remove() to use it.

* Fix handling of ide_host_register() failure in ide_host_add(),
  icside.c, ide-generic.c, falconide.c and sgiioc4.c.

While at it:

* Fix handling of ide_host_alloc_all() failure in ide-generic.c.

* Fix handling of ide_host_alloc() failure in falconide.c
  (also return the correct error value if no device is found).

v2:
* falconide build fix. (From Stephen Rothwell)

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 6d57b7c..0ead453 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1729,12 +1729,17 @@
 		 struct ide_host **hostp)
 {
 	struct ide_host *host;
+	int rc;
 
 	host = ide_host_alloc(d, hws);
 	if (host == NULL)
 		return -ENOMEM;
 
-	ide_host_register(host, d, hws);
+	rc = ide_host_register(host, d, hws);
+	if (rc) {
+		ide_host_free(host);
+		return rc;
+	}
 
 	if (hostp)
 		*hostp = host;
@@ -1743,7 +1748,7 @@
 }
 EXPORT_SYMBOL_GPL(ide_host_add);
 
-void ide_host_remove(struct ide_host *host)
+void ide_host_free(struct ide_host *host)
 {
 	ide_hwif_t *hwif;
 	int i;
@@ -1754,13 +1759,25 @@
 		if (hwif == NULL)
 			continue;
 
-		ide_unregister(hwif);
 		ide_free_port_slot(hwif->index);
 		kfree(hwif);
 	}
 
 	kfree(host);
 }
+EXPORT_SYMBOL_GPL(ide_host_free);
+
+void ide_host_remove(struct ide_host *host)
+{
+	int i;
+
+	for (i = 0; i < MAX_HWIFS; i++) {
+		if (host->ports[i])
+			ide_unregister(host->ports[i]);
+	}
+
+	ide_host_free(host);
+}
 EXPORT_SYMBOL_GPL(ide_host_remove);
 
 void ide_port_scan(ide_hwif_t *hwif)