From 5ad45ac77b64b94f8ed9c4de6f585a8b2241786b Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Fri, 17 Dec 2010 15:19:05 +0100 Subject: [PATCH] ums: Make it look as similar to kernel driver as possible - finish. Signed-off-by: Andrzej Pietrasiewicz --- drivers/usb/gadget/file_storage.c | 32 +++++++++++++++++--------------- drivers/usb/gadget/storage_common.c | 13 ++++++------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index c514fb6..1ad10be 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c @@ -334,6 +334,11 @@ typedef int spinlock_t; #define device_unregister(...) 0 #define device_create_file(...) 0 #define kref_get(...) do {} while (0) +#define kref_init(...) do {} while (0) +#define module_init(...) +#define module_exit(...) +#define wait_for_completion(...) do {} while (0) +#define dev_get_drvdata(...) NULL struct kref {int;}; struct completion {int;}; @@ -3099,7 +3104,7 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget) /* If the thread isn't already dead, tell it to exit now */ if (fsg->state != FSG_STATE_TERMINATED) { raise_exception(fsg, FSG_STATE_EXIT); - //wait_for_completion(&fsg->thread_notifier); + wait_for_completion(&fsg->thread_notifier); /* The cleanup routine waits for this completion also */ complete(&fsg->thread_notifier); @@ -3367,9 +3372,8 @@ static int __ref fsg_bind(struct usb_gadget *gadget) * the buffer will also work with the bulk-out (and * interrupt-in) endpoint. */ bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL); - if (!bh->buf){ + if (!bh->buf) goto out; - } bh->next = bh + 1; } fsg->buffhds[FSG_NUM_BUFFERS - 1].next = &fsg->buffhds[0]; @@ -3384,11 +3388,10 @@ static int __ref fsg_bind(struct usb_gadget *gadget) fsg->thread_task = kthread_create(fsg_main_thread, fsg, "file-storage-gadget"); - /* if (IS_ERR(fsg->thread_task)) { rc = PTR_ERR(fsg->thread_task); - goto out; - }*/ + //goto out; + } INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); INFO(fsg, "Number of LUNs=%d\n", fsg->nluns); @@ -3417,7 +3420,7 @@ autoconf_fail: out: fsg->state = FSG_STATE_TERMINATED; // The thread is dead fsg_unbind(gadget); - //complete(&fsg->thread_notifier); + complete(&fsg->thread_notifier); return rc; } @@ -3477,8 +3480,8 @@ static int __init fsg_alloc(void) return -ENOMEM; spin_lock_init(&fsg->lock); init_rwsem(&fsg->filesem); - //kref_init(&fsg->ref); - //init_completion(&fsg->thread_notifier); + kref_init(&fsg->ref); + init_completion(&fsg->thread_notifier); the_fsg = fsg; return 0; @@ -3495,13 +3498,12 @@ int __init fsg_init(struct ums_board_info* _ums) return rc; fsg = the_fsg; if ((rc = usb_gadget_register_driver(&fsg_driver)) != 0) - //kref_put(&fsg->ref, fsg_release); - do { } while (0); + kref_put(&fsg->ref, fsg_release); usb_gadget_connect(the_fsg->gadget); return rc; } -//module_init(fsg_init); +module_init(fsg_init); static void __exit fsg_cleanup(void) @@ -3513,8 +3515,8 @@ static void __exit fsg_cleanup(void) usb_gadget_unregister_driver(&fsg_driver); /* Wait for the thread to finish up */ - //wait_for_completion(&fsg->thread_notifier); + wait_for_completion(&fsg->thread_notifier); - //kref_put(&fsg->ref, fsg_release); + kref_put(&fsg->ref, fsg_release); } -//module_exit(fsg_cleanup); +module_exit(fsg_cleanup); diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index 4715d88..04e8760 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c @@ -289,6 +289,7 @@ struct rw_semaphore { int i; }; #define up_write(...) do { } while (0) #define down_read(...) do { } while (0) #define up_read(...) do { } while (0) +#define ETOOSMALL 525 #include extern struct ums_board_info *ums_info; @@ -608,22 +609,22 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) size = ums_info->get_capacity(); if (size < 0) { - //LINFO(curlun, "unable to find file size: %s\n", filename); + LINFO(curlun, "unable to find file size: %s\n", filename); rc = (int) size; goto out; } num_sectors = size >> 9; /* File size in 512-byte blocks */ min_sectors = 1; - /*if (num_sectors < min_sectors) { + if (num_sectors < min_sectors) { LINFO(curlun, "file too small: %s\n", filename); rc = -ETOOSMALL; goto out; - }*/ + } curlun->ro = ro; curlun->file_length = size; curlun->num_sectors = num_sectors; - //LDBG(curlun, "open backing file: %s\n", filename); + LDBG(curlun, "open backing file: %s\n", filename); rc = 0; out: @@ -702,7 +703,6 @@ static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr, struct fsg_lun *curlun = fsg_lun_from_dev(dev); unsigned long ro; - //if (strict_strtoul(buf, 2, &ro)) ro = simple_strtoul(buf, NULL, 2); /* @@ -711,7 +711,7 @@ static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr, */ curlun->ro = ro; curlun->initially_ro = ro; - //LDBG(curlun, "read-only status set to %d\n", curlun->ro); + LDBG(curlun, "read-only status set to %d\n", curlun->ro); return rc; } @@ -722,7 +722,6 @@ static ssize_t fsg_store_nofua(struct device *dev, struct fsg_lun *curlun = fsg_lun_from_dev(dev); unsigned long nofua; - //if (strict_strtoul(buf, 2, &nofua)) nofua = simple_strtoul(buf, NULL, 2); /* Sync data when switching from async mode to sync */ -- 2.7.4