aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/file_storage.c
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2007-08-08 17:10:11 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:55:10 -0400
commit79a7d9ee1a2e8b8dc44dd217f07496911850ec0e (patch)
tree030bb85f4e098fce987dd7ec3ce3c879eb9ac459 /drivers/usb/gadget/file_storage.c
parentd74d4a69dc1cc7ddc0eabb9c9f1e45005e2984eb (diff)
USB: cleanups for g_file_storage
This patch (as957) makes some minor cleanups to the g_file_storage driver: Update the copyright date and version string; Uniformize the logging macros for the gadget and the LUNs; Remove "inline" markers -- nowadays we rely on the compiler to decide which routines are best inlined; Use the print_hex_dump() library routines; Remove some unnecessary assignments within conditionals and fix some close-brace indenting levels; Fix some column-80 violations. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget/file_storage.c')
-rw-r--r--drivers/usb/gadget/file_storage.c129
1 files changed, 62 insertions, 67 deletions
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 0019116ee411..9998cd7af418 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * file_storage.c -- File-backed USB Storage Gadget, for USB development 2 * file_storage.c -- File-backed USB Storage Gadget, for USB development
3 * 3 *
4 * Copyright (C) 2003-2005 Alan Stern 4 * Copyright (C) 2003-2007 Alan Stern
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
@@ -218,7 +218,7 @@
218 218
219 219
220/* #define VERBOSE_DEBUG */ 220/* #define VERBOSE_DEBUG */
221#undef DUMP_MSGS 221/* #define DUMP_MSGS */
222 222
223 223
224#include <linux/blkdev.h> 224#include <linux/blkdev.h>
@@ -249,7 +249,7 @@
249 249
250#define DRIVER_DESC "File-backed Storage Gadget" 250#define DRIVER_DESC "File-backed Storage Gadget"
251#define DRIVER_NAME "g_file_storage" 251#define DRIVER_NAME "g_file_storage"
252#define DRIVER_VERSION "28 November 2005" 252#define DRIVER_VERSION "7 August 2007"
253 253
254static const char longname[] = DRIVER_DESC; 254static const char longname[] = DRIVER_DESC;
255static const char shortname[] = DRIVER_NAME; 255static const char shortname[] = DRIVER_NAME;
@@ -275,12 +275,9 @@ MODULE_LICENSE("Dual BSD/GPL");
275 275
276/*-------------------------------------------------------------------------*/ 276/*-------------------------------------------------------------------------*/
277 277
278#define yprintk(l,level,fmt,args...) \
279 dev_printk(level , &(l)->dev , fmt , ## args)
280
281#ifdef DEBUG 278#ifdef DEBUG
282#define LDBG(lun,fmt,args...) \ 279#define LDBG(lun,fmt,args...) \
283 yprintk(lun , KERN_DEBUG , fmt , ## args) 280 dev_dbg(&(lun)->dev , fmt , ## args)
284#define MDBG(fmt,args...) \ 281#define MDBG(fmt,args...) \
285 printk(KERN_DEBUG DRIVER_NAME ": " fmt , ## args) 282 printk(KERN_DEBUG DRIVER_NAME ": " fmt , ## args)
286#else 283#else
@@ -300,11 +297,11 @@ MODULE_LICENSE("Dual BSD/GPL");
300#endif /* VERBOSE_DEBUG */ 297#endif /* VERBOSE_DEBUG */
301 298
302#define LERROR(lun,fmt,args...) \ 299#define LERROR(lun,fmt,args...) \
303 yprintk(lun , KERN_ERR , fmt , ## args) 300 dev_err(&(lun)->dev , fmt , ## args)
304#define LWARN(lun,fmt,args...) \ 301#define LWARN(lun,fmt,args...) \
305 yprintk(lun , KERN_WARNING , fmt , ## args) 302 dev_warn(&(lun)->dev , fmt , ## args)
306#define LINFO(lun,fmt,args...) \ 303#define LINFO(lun,fmt,args...) \
307 yprintk(lun , KERN_INFO , fmt , ## args) 304 dev_info(&(lun)->dev , fmt , ## args)
308 305
309#define MINFO(fmt,args...) \ 306#define MINFO(fmt,args...) \
310 printk(KERN_INFO DRIVER_NAME ": " fmt , ## args) 307 printk(KERN_INFO DRIVER_NAME ": " fmt , ## args)
@@ -558,7 +555,7 @@ struct lun {
558 555
559#define backing_file_is_open(curlun) ((curlun)->filp != NULL) 556#define backing_file_is_open(curlun) ((curlun)->filp != NULL)
560 557
561static inline struct lun *dev_to_lun(struct device *dev) 558static struct lun *dev_to_lun(struct device *dev)
562{ 559{
563 return container_of(dev, struct lun, dev); 560 return container_of(dev, struct lun, dev);
564} 561}
@@ -691,13 +688,13 @@ struct fsg_dev {
691 688
692typedef void (*fsg_routine_t)(struct fsg_dev *); 689typedef void (*fsg_routine_t)(struct fsg_dev *);
693 690
694static int inline exception_in_progress(struct fsg_dev *fsg) 691static int exception_in_progress(struct fsg_dev *fsg)
695{ 692{
696 return (fsg->state > FSG_STATE_IDLE); 693 return (fsg->state > FSG_STATE_IDLE);
697} 694}
698 695
699/* Make bulk-out requests be divisible by the maxpacket size */ 696/* Make bulk-out requests be divisible by the maxpacket size */
700static void inline set_bulk_out_req_length(struct fsg_dev *fsg, 697static void set_bulk_out_req_length(struct fsg_dev *fsg,
701 struct fsg_buffhd *bh, unsigned int length) 698 struct fsg_buffhd *bh, unsigned int length)
702{ 699{
703 unsigned int rem; 700 unsigned int rem;
@@ -723,50 +720,36 @@ static void close_all_backing_files(struct fsg_dev *fsg);
723static void dump_msg(struct fsg_dev *fsg, const char *label, 720static void dump_msg(struct fsg_dev *fsg, const char *label,
724 const u8 *buf, unsigned int length) 721 const u8 *buf, unsigned int length)
725{ 722{
726 unsigned int start, num, i; 723 if (length < 512) {
727 char line[52], *p; 724 DBG(fsg, "%s, length %u:\n", label, length);
728 725 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET,
729 if (length >= 512) 726 16, 1, buf, length, 0);
730 return;
731 DBG(fsg, "%s, length %u:\n", label, length);
732
733 start = 0;
734 while (length > 0) {
735 num = min(length, 16u);
736 p = line;
737 for (i = 0; i < num; ++i) {
738 if (i == 8)
739 *p++ = ' ';
740 sprintf(p, " %02x", buf[i]);
741 p += 3;
742 }
743 *p = 0;
744 printk(KERN_DEBUG "%6x: %s\n", start, line);
745 buf += num;
746 start += num;
747 length -= num;
748 } 727 }
749} 728}
750 729
751static void inline dump_cdb(struct fsg_dev *fsg) 730static void dump_cdb(struct fsg_dev *fsg)
752{} 731{}
753 732
754#else 733#else
755 734
756static void inline dump_msg(struct fsg_dev *fsg, const char *label, 735static void dump_msg(struct fsg_dev *fsg, const char *label,
757 const u8 *buf, unsigned int length) 736 const u8 *buf, unsigned int length)
758{} 737{}
759 738
760static void inline dump_cdb(struct fsg_dev *fsg) 739#ifdef VERBOSE_DEBUG
761{
762 int i;
763 char cmdbuf[3*MAX_COMMAND_SIZE + 1];
764 740
765 for (i = 0; i < fsg->cmnd_size; ++i) 741static void dump_cdb(struct fsg_dev *fsg)
766 sprintf(cmdbuf + i*3, " %02x", fsg->cmnd[i]); 742{
767 VDBG(fsg, "SCSI CDB: %s\n", cmdbuf); 743 print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE,
744 16, 1, fsg->cmnd, fsg->cmnd_size, 0);
768} 745}
769 746
747#else
748
749static void dump_cdb(struct fsg_dev *fsg)
750{}
751
752#endif /* VERBOSE_DEBUG */
770#endif /* DUMP_MSGS */ 753#endif /* DUMP_MSGS */
771 754
772 755
@@ -789,24 +772,24 @@ static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
789 772
790/* Routines for unaligned data access */ 773/* Routines for unaligned data access */
791 774
792static u16 inline get_be16(u8 *buf) 775static u16 get_be16(u8 *buf)
793{ 776{
794 return ((u16) buf[0] << 8) | ((u16) buf[1]); 777 return ((u16) buf[0] << 8) | ((u16) buf[1]);
795} 778}
796 779
797static u32 inline get_be32(u8 *buf) 780static u32 get_be32(u8 *buf)
798{ 781{
799 return ((u32) buf[0] << 24) | ((u32) buf[1] << 16) | 782 return ((u32) buf[0] << 24) | ((u32) buf[1] << 16) |
800 ((u32) buf[2] << 8) | ((u32) buf[3]); 783 ((u32) buf[2] << 8) | ((u32) buf[3]);
801} 784}
802 785
803static void inline put_be16(u8 *buf, u16 val) 786static void put_be16(u8 *buf, u16 val)
804{ 787{
805 buf[0] = val >> 8; 788 buf[0] = val >> 8;
806 buf[1] = val; 789 buf[1] = val;
807} 790}
808 791
809static void inline put_be32(u8 *buf, u32 val) 792static void put_be32(u8 *buf, u32 val)
810{ 793{
811 buf[0] = val >> 24; 794 buf[0] = val >> 24;
812 buf[1] = val >> 16; 795 buf[1] = val >> 16;
@@ -992,7 +975,7 @@ static const struct usb_descriptor_header *hs_function[] = {
992#define HS_FUNCTION_PRE_EP_ENTRIES 2 975#define HS_FUNCTION_PRE_EP_ENTRIES 2
993 976
994/* Maxpacket and other transfer characteristics vary by speed. */ 977/* Maxpacket and other transfer characteristics vary by speed. */
995static inline struct usb_endpoint_descriptor * 978static struct usb_endpoint_descriptor *
996ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, 979ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
997 struct usb_endpoint_descriptor *hs) 980 struct usb_endpoint_descriptor *hs)
998{ 981{
@@ -1616,7 +1599,8 @@ static int do_read(struct fsg_dev *fsg)
1616 /* Wait for the next buffer to become available */ 1599 /* Wait for the next buffer to become available */
1617 bh = fsg->next_buffhd_to_fill; 1600 bh = fsg->next_buffhd_to_fill;
1618 while (bh->state != BUF_STATE_EMPTY) { 1601 while (bh->state != BUF_STATE_EMPTY) {
1619 if ((rc = sleep_thread(fsg)) != 0) 1602 rc = sleep_thread(fsg);
1603 if (rc)
1620 return rc; 1604 return rc;
1621 } 1605 }
1622 1606
@@ -1855,7 +1839,8 @@ static int do_write(struct fsg_dev *fsg)
1855 } 1839 }
1856 1840
1857 /* Wait for something to happen */ 1841 /* Wait for something to happen */
1858 if ((rc = sleep_thread(fsg)) != 0) 1842 rc = sleep_thread(fsg);
1843 if (rc)
1859 return rc; 1844 return rc;
1860 } 1845 }
1861 1846
@@ -2339,7 +2324,8 @@ static int pad_with_zeros(struct fsg_dev *fsg)
2339 2324
2340 /* Wait for the next buffer to be free */ 2325 /* Wait for the next buffer to be free */
2341 while (bh->state != BUF_STATE_EMPTY) { 2326 while (bh->state != BUF_STATE_EMPTY) {
2342 if ((rc = sleep_thread(fsg)) != 0) 2327 rc = sleep_thread(fsg);
2328 if (rc)
2343 return rc; 2329 return rc;
2344 } 2330 }
2345 2331
@@ -2399,7 +2385,8 @@ static int throw_away_data(struct fsg_dev *fsg)
2399 } 2385 }
2400 2386
2401 /* Otherwise wait for something to happen */ 2387 /* Otherwise wait for something to happen */
2402 if ((rc = sleep_thread(fsg)) != 0) 2388 rc = sleep_thread(fsg);
2389 if (rc)
2403 return rc; 2390 return rc;
2404 } 2391 }
2405 return 0; 2392 return 0;
@@ -2521,7 +2508,8 @@ static int send_status(struct fsg_dev *fsg)
2521 /* Wait for the next buffer to become available */ 2508 /* Wait for the next buffer to become available */
2522 bh = fsg->next_buffhd_to_fill; 2509 bh = fsg->next_buffhd_to_fill;
2523 while (bh->state != BUF_STATE_EMPTY) { 2510 while (bh->state != BUF_STATE_EMPTY) {
2524 if ((rc = sleep_thread(fsg)) != 0) 2511 rc = sleep_thread(fsg);
2512 if (rc)
2525 return rc; 2513 return rc;
2526 } 2514 }
2527 2515
@@ -2741,9 +2729,10 @@ static int do_scsi_command(struct fsg_dev *fsg)
2741 /* Wait for the next buffer to become available for data or status */ 2729 /* Wait for the next buffer to become available for data or status */
2742 bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill; 2730 bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
2743 while (bh->state != BUF_STATE_EMPTY) { 2731 while (bh->state != BUF_STATE_EMPTY) {
2744 if ((rc = sleep_thread(fsg)) != 0) 2732 rc = sleep_thread(fsg);
2733 if (rc)
2745 return rc; 2734 return rc;
2746 } 2735 }
2747 fsg->phase_error = 0; 2736 fsg->phase_error = 0;
2748 fsg->short_packet_received = 0; 2737 fsg->short_packet_received = 0;
2749 2738
@@ -3015,9 +3004,10 @@ static int get_next_command(struct fsg_dev *fsg)
3015 /* Wait for the next buffer to become available */ 3004 /* Wait for the next buffer to become available */
3016 bh = fsg->next_buffhd_to_fill; 3005 bh = fsg->next_buffhd_to_fill;
3017 while (bh->state != BUF_STATE_EMPTY) { 3006 while (bh->state != BUF_STATE_EMPTY) {
3018 if ((rc = sleep_thread(fsg)) != 0) 3007 rc = sleep_thread(fsg);
3008 if (rc)
3019 return rc; 3009 return rc;
3020 } 3010 }
3021 3011
3022 /* Queue a request to read a Bulk-only CBW */ 3012 /* Queue a request to read a Bulk-only CBW */
3023 set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN); 3013 set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN);
@@ -3031,9 +3021,10 @@ static int get_next_command(struct fsg_dev *fsg)
3031 3021
3032 /* Wait for the CBW to arrive */ 3022 /* Wait for the CBW to arrive */
3033 while (bh->state != BUF_STATE_FULL) { 3023 while (bh->state != BUF_STATE_FULL) {
3034 if ((rc = sleep_thread(fsg)) != 0) 3024 rc = sleep_thread(fsg);
3025 if (rc)
3035 return rc; 3026 return rc;
3036 } 3027 }
3037 smp_rmb(); 3028 smp_rmb();
3038 rc = received_cbw(fsg, bh); 3029 rc = received_cbw(fsg, bh);
3039 bh->state = BUF_STATE_EMPTY; 3030 bh->state = BUF_STATE_EMPTY;
@@ -3042,9 +3033,10 @@ static int get_next_command(struct fsg_dev *fsg)
3042 3033
3043 /* Wait for the next command to arrive */ 3034 /* Wait for the next command to arrive */
3044 while (fsg->cbbuf_cmnd_size == 0) { 3035 while (fsg->cbbuf_cmnd_size == 0) {
3045 if ((rc = sleep_thread(fsg)) != 0) 3036 rc = sleep_thread(fsg);
3037 if (rc)
3046 return rc; 3038 return rc;
3047 } 3039 }
3048 3040
3049 /* Is the previous status interrupt request still busy? 3041 /* Is the previous status interrupt request still busy?
3050 * The host is allowed to skip reading the status, 3042 * The host is allowed to skip reading the status,
@@ -3565,7 +3557,8 @@ static ssize_t show_ro(struct device *dev, struct device_attribute *attr, char *
3565 return sprintf(buf, "%d\n", curlun->ro); 3557 return sprintf(buf, "%d\n", curlun->ro);
3566} 3558}
3567 3559
3568static ssize_t show_file(struct device *dev, struct device_attribute *attr, char *buf) 3560static ssize_t show_file(struct device *dev, struct device_attribute *attr,
3561 char *buf)
3569{ 3562{
3570 struct lun *curlun = dev_to_lun(dev); 3563 struct lun *curlun = dev_to_lun(dev);
3571 struct fsg_dev *fsg = dev_get_drvdata(dev); 3564 struct fsg_dev *fsg = dev_get_drvdata(dev);
@@ -3574,8 +3567,8 @@ static ssize_t show_file(struct device *dev, struct device_attribute *attr, char
3574 3567
3575 down_read(&fsg->filesem); 3568 down_read(&fsg->filesem);
3576 if (backing_file_is_open(curlun)) { // Get the complete pathname 3569 if (backing_file_is_open(curlun)) { // Get the complete pathname
3577 p = d_path(curlun->filp->f_path.dentry, curlun->filp->f_path.mnt, 3570 p = d_path(curlun->filp->f_path.dentry,
3578 buf, PAGE_SIZE - 1); 3571 curlun->filp->f_path.mnt, buf, PAGE_SIZE - 1);
3579 if (IS_ERR(p)) 3572 if (IS_ERR(p))
3580 rc = PTR_ERR(p); 3573 rc = PTR_ERR(p);
3581 else { 3574 else {
@@ -3593,7 +3586,8 @@ static ssize_t show_file(struct device *dev, struct device_attribute *attr, char
3593} 3586}
3594 3587
3595 3588
3596static ssize_t store_ro(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 3589static ssize_t store_ro(struct device *dev, struct device_attribute *attr,
3590 const char *buf, size_t count)
3597{ 3591{
3598 ssize_t rc = count; 3592 ssize_t rc = count;
3599 struct lun *curlun = dev_to_lun(dev); 3593 struct lun *curlun = dev_to_lun(dev);
@@ -3617,7 +3611,8 @@ static ssize_t store_ro(struct device *dev, struct device_attribute *attr, const
3617 return rc; 3611 return rc;
3618} 3612}
3619 3613
3620static ssize_t store_file(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 3614static ssize_t store_file(struct device *dev, struct device_attribute *attr,
3615 const char *buf, size_t count)
3621{ 3616{
3622 struct lun *curlun = dev_to_lun(dev); 3617 struct lun *curlun = dev_to_lun(dev);
3623 struct fsg_dev *fsg = dev_get_drvdata(dev); 3618 struct fsg_dev *fsg = dev_get_drvdata(dev);