--- file_storage.old	2004-07-27 09:05:38.000000000 -0600
+++ file_storage.c	2004-07-27 09:31:29.000000000 -0600
@@ -371,6 +371,8 @@
 module_param_array(ro, bool, mod_data.num_ros, S_IRUGO);
 MODULE_PARM_DESC(ro, "true to force read-only");
 
+module_param_named(removable, mod_data.removable, bool, S_IRUGO);
+MODULE_PARM_DESC(removable, "true to simulate removable media");
 
 /* In the non-TEST version, only the file and ro module parameters
  * are available. */
@@ -386,9 +388,6 @@
 MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
 		"8070, or SCSI)");
 
-module_param_named(removable, mod_data.removable, bool, S_IRUGO);
-MODULE_PARM_DESC(removable, "true to simulate removable media");
-
 module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
 MODULE_PARM_DESC(vendor, "USB Vendor ID");
 
@@ -517,6 +516,7 @@
 #define ASC(x)		((u8) ((x) >> 8))
 #define ASCQ(x)		((u8) (x))
 
+#define backing_file_is_open(curlun)	((curlun)->filp != NULL)
 
 /*-------------------------------------------------------------------------*/
 
@@ -525,11 +525,6 @@
  * parts of the driver that aren't used in the non-TEST version.  Even gcc
  * can recognize when a test of a constant expression yields a dead code
  * path.
- *
- * Also, in the non-TEST version, open_backing_file() is only used during
- * initialization and the sysfs attribute store_xxx routines aren't used
- * at all.  We will define NORMALLY_INIT to mark them as __init so they
- * don't occupy kernel code space unnecessarily.
  */
 
 #ifdef CONFIG_USB_FILE_STORAGE_TEST
@@ -537,16 +532,12 @@
 #define transport_is_bbb()	(mod_data.transport_type == USB_PR_BULK)
 #define transport_is_cbi()	(mod_data.transport_type == USB_PR_CBI)
 #define protocol_is_scsi()	(mod_data.protocol_type == USB_SC_SCSI)
-#define backing_file_is_open(curlun)	((curlun)->filp != NULL)
-#define NORMALLY_INIT
 
 #else
 
 #define transport_is_bbb()	1
 #define transport_is_cbi()	0
 #define protocol_is_scsi()	1
-#define backing_file_is_open(curlun)	1
-#define NORMALLY_INIT		__init
 
 #endif /* CONFIG_USB_FILE_STORAGE_TEST */
 
@@ -3422,7 +3413,7 @@
 /* If the next two routines are called while the gadget is registered,
  * the caller must own fsg->filesem for writing. */
 
-static int NORMALLY_INIT open_backing_file(struct lun *curlun,
+static int open_backing_file(struct lun *curlun,
 		const char *filename)
 {
 	int				ro;
@@ -3548,7 +3539,7 @@
 }
 
 
-ssize_t NORMALLY_INIT store_ro(struct device *dev, const char *buf,
+ssize_t store_ro(struct device *dev, const char *buf,
 		size_t count)
 {
 	ssize_t		rc = count;
@@ -3573,7 +3564,7 @@
 	return rc;
 }
 
-ssize_t NORMALLY_INIT store_file(struct device *dev, const char *buf,
+ssize_t store_file(struct device *dev, const char *buf,
 		size_t count)
 {
 	struct lun	*curlun = dev_to_lun(dev);
@@ -3780,6 +3771,7 @@
 	char			*pathbuf, *p;
 
 	fsg->gadget = gadget;
+	gadget->dev.driver = &fsg_driver.driver;
 	set_gadget_data(gadget, fsg);
 	fsg->ep0 = gadget->ep0;
 	fsg->ep0->driver_data = fsg;
@@ -3817,12 +3809,22 @@
 	for (i = 0; i < fsg->nluns; ++i) {
 		curlun = &fsg->luns[i];
 		curlun->ro = ro[i];
-		curlun->dev.parent = &gadget->dev;
-		curlun->dev.driver = &fsg_driver.driver;
-		dev_set_drvdata(&curlun->dev, fsg);
+
 		snprintf(curlun->dev.bus_id, BUS_ID_SIZE,
 				"%s-lun%d", gadget->dev.bus_id, i);
 
+                if ((rc = device_register(&curlun->dev)) != 0) {
+                  INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
+                } else {
+                  curlun->registered = 1;
+                  curlun->dev.release = lun_release;
+                  curlun->dev.parent = &gadget->dev;
+                  curlun->dev.driver = &fsg_driver.driver;
+                  device_create_file(&curlun->dev, &dev_attr_ro);
+                  device_create_file(&curlun->dev, &dev_attr_file);
+		  dev_set_drvdata(&curlun->dev, fsg);
+		}  
+
 		if (file[i] && *file[i]) {
 			if ((rc = open_backing_file(curlun, file[i])) != 0)
 				goto out;
@@ -4022,8 +4024,6 @@
 {
 	int		rc;
 	struct fsg_dev	*fsg;
-	int		i;
-	struct lun	*curlun;
 
 	if ((rc = fsg_alloc()) != 0)
 		return rc;
@@ -4034,19 +4034,6 @@
 	}
 	set_bit(REGISTERED, &fsg->atomic_bitflags);
 
-	/* Register the LUN devices and their attribute files */
-	for (i = 0; i < fsg->nluns; ++i) {
-		curlun = &fsg->luns[i];
-		if ((rc = device_register(&curlun->dev)) != 0)
-			INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
-		else {
-			curlun->registered = 1;
-			curlun->dev.release = lun_release;
-			device_create_file(&curlun->dev, &dev_attr_ro);
-			device_create_file(&curlun->dev, &dev_attr_file);
-		}
-	}
-
 	/* Tell the thread to start working */
 	complete(&fsg->thread_notifier);
 	return 0;
