[ALSA] unregister platform devices

Call platform_device_unregister() for all platform devices that we've
registered.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
diff --git a/sound/isa/sgalaxy.c b/sound/isa/sgalaxy.c
index 2e1d467..0dbbb35 100644
--- a/sound/isa/sgalaxy.c
+++ b/sound/isa/sgalaxy.c
@@ -64,6 +64,8 @@
 module_param_array(dma1, int, NULL, 0444);
 MODULE_PARM_DESC(dma1, "DMA1 # for Sound Galaxy driver.");
 
+static struct platform_device *devices[SNDRV_CARDS];
+
 #define SGALAXY_AUXC_LEFT 18
 #define SGALAXY_AUXC_RIGHT 19
 
@@ -340,6 +342,15 @@
 	},
 };
 
+static void __init_or_module snd_sgalaxy_unregister_all(void)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(devices); ++i)
+		platform_device_unregister(devices[i]);
+	platform_driver_unregister(&snd_sgalaxy_driver);
+}
+
 static int __init alsa_card_sgalaxy_init(void)
 {
 	int i, cards, err;
@@ -357,6 +368,7 @@
 			err = PTR_ERR(device);
 			goto errout;
 		}
+		devices[i] = device;
 		cards++;
 	}
 	if (!cards) {
@@ -369,13 +381,13 @@
 	return 0;
 
  errout:
-	platform_driver_unregister(&snd_sgalaxy_driver);
+	snd_sgalaxy_unregister_all();
 	return err;
 }
 
 static void __exit alsa_card_sgalaxy_exit(void)
 {
-	platform_driver_unregister(&snd_sgalaxy_driver);
+	snd_sgalaxy_unregister_all();
 }
 
 module_init(alsa_card_sgalaxy_init)