Skip to contentSkip to conversation

fix usb_devfs_handle abuse

PATCH In review Christoph Hellwig 2 participants 2 messages Mar 24, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix usb_devfs_handle abuse

Many usb drivers use the usb_devfs_handle variable instead of just adding the usb/ prefix directly to their devfs_register calls. Fix that and make usb_devfs_handle static and unexported.

drivers/usb/class/usblp.c +3 -5
diff -Nru a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
@@ -186,8 +186,6 @@
 }
 #endif
 
-extern devfs_handle_t usb_devfs_handle;			/* /dev/usb dir. */
-
 /* Quirks: various printer quirks are handled by this table & its flags. */
 
 struct quirk_printer_struct {
@@ -820,7 +818,7 @@
 	struct usblp *usblp = 0;
 	int protocol;
 	int retval;
-	char name[6];
+	char name[10];
 
 	/* Malloc and start initializing usblp structure so we can use it
 	 * directly. */
@@ -909,8 +907,8 @@
 #endif
 
 	/* If we have devfs, create with perms=660. */
-	sprintf(name, "lp%d", usblp->minor);
-	usblp->devfs = devfs_register(usb_devfs_handle, name,
+	sprintf(name, "usb/lp%d", usblp->minor);
+	usblp->devfs = devfs_register(NULL, name,
 				      DEVFS_FL_DEFAULT, USB_MAJOR,
 				      usblp->minor,
 				      S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP |
drivers/usb/core/file.c +1 -2
diff -Nru a/drivers/usb/core/file.c b/drivers/usb/core/file.c
@@ -28,8 +28,7 @@
 #endif
 #include <linux/usb.h>
 
-devfs_handle_t usb_devfs_handle;	/* /dev/usb dir. */
-EXPORT_SYMBOL(usb_devfs_handle);
+static devfs_handle_t usb_devfs_handle;	/* /dev/usb dir. */
 
 #define MAX_USB_MINORS	256
 static struct file_operations *usb_minors[MAX_USB_MINORS];
drivers/usb/image/scanner.c +3 -3
diff -Nru a/drivers/usb/image/scanner.c b/drivers/usb/image/scanner.c
@@ -878,7 +878,7 @@
 
 	char valid_device = 0;
 	char have_bulk_in, have_bulk_out, have_intr;
-	char name[10];
+	char name[14];
 
 	dbg("probe_scanner: USB dev address:%p", dev);
 
@@ -1099,9 +1099,9 @@
 	scn->scn_minor = scn_minor;
 	scn->isopen = 0;
 
-	sprintf(name, "scanner%d", scn->scn_minor - SCN_BASE_MNR);
+	sprintf(name, "usb/scanner%d", scn->scn_minor - SCN_BASE_MNR);
 	
-	scn->devfs = devfs_register(usb_devfs_handle, name,
+	scn->devfs = devfs_register(NULL, name,
 				    DEVFS_FL_DEFAULT, USB_MAJOR,
 				    scn->scn_minor,
 				    S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP |
drivers/usb/image/scanner.h +0 -2
diff -Nru a/drivers/usb/image/scanner.h b/drivers/usb/image/scanner.h
@@ -352,6 +352,4 @@
 };
 #define to_scanner(d) container_of(d, struct scn_usb_data, kobj)
 
-extern devfs_handle_t usb_devfs_handle;
-
 static struct usb_driver scanner_driver;
drivers/usb/misc/auerswald.c +5 -12
diff -Nru a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
@@ -72,9 +72,6 @@
 #endif
 
 
-/* prefix for the device descriptors in /dev/usb */
-#define AU_PREFIX	"auer"
-
 /* Number of read buffers for each device */
 #define AU_RBUFFERS     10
 
@@ -243,7 +240,7 @@
 typedef struct
 {
 	struct semaphore 	mutex;         	    /* protection in user context */
-	char 			name[16];	    /* name of the /dev/usb entry */
+	char 			name[20];	    /* name of the /dev/usb entry */
 	unsigned int		dtindex;	    /* index in the device table */
 	devfs_handle_t 		devfs;	 	    /* devfs device node */
 	struct usb_device *	usbdev;      	    /* USB device handle */
@@ -260,9 +257,6 @@
 	wait_queue_head_t 	bufferwait;         /* wait for a control buffer */
 } auerswald_t,*pauerswald_t;
 
-/* the global usb devfs handle */
-extern devfs_handle_t usb_devfs_handle;
-
 /* array of pointers to our devices that are currently connected */
 static pauerswald_t dev_table[AUER_MAX_DEVICES];
 
@@ -1440,7 +1434,7 @@
 
 	cp->open_count++;
 	ccp->auerdev = cp;
-	dbg("open %s as /dev/usb/%s", cp->dev_desc, cp->name);
+	dbg("open %s as /dev/%s", cp->dev_desc, cp->name);
 	up (&cp->mutex);
 
 	/* file IO stuff */
@@ -1970,7 +1964,7 @@
 	}
 
 	/* Give the device a name */
-	sprintf (cp->name, AU_PREFIX "%d", dtindex);
+	sprintf (cp->name, "usb/auer%d", dtindex);
 
 	/* Store the index */
 	cp->dtindex = dtindex;
@@ -1978,8 +1972,7 @@
 	up (&dev_table_mutex);
 
 	/* initialize the devfs node for this device and register it */
-	cp->devfs = devfs_register (usb_devfs_handle, cp->name,
-				    DEVFS_FL_DEFAULT, USB_MAJOR,
+	cp->devfs = devfs_register(NULL, cp->name, 0, USB_MAJOR,
 				    AUER_MINOR_BASE + dtindex,
 				    S_IFCHR | S_IRUGO | S_IWUGO,
 				    &auerswald_fops, NULL);
@@ -2089,7 +2082,7 @@
 		return;
 
 	down (&cp->mutex);
-	info ("device /dev/usb/%s now disconnecting", cp->name);
+	info ("device /dev/%s now disconnecting", cp->name);
 
 	/* remove from device table */
 	/* Nobody can open() this device any more */
drivers/usb/misc/brlvger.c +3 -5
diff -Nru a/drivers/usb/misc/brlvger.c b/drivers/usb/misc/brlvger.c
@@ -144,8 +144,6 @@
 #define rcvcontrolmsg(priv,a,b,c,d,e,f) \
     controlmsg(priv, USB_DIR_IN, a,b,c,d,e,f)
 
-extern devfs_handle_t usb_devfs_handle; /* /dev/usb dir. */
-
 /* ----------------------------------------------------------------------- */
 
 /* Data */
@@ -294,7 +292,7 @@
 	/* protects against reentrance: once we've found a free slot
 	   we reserve it.*/
 	static DECLARE_MUTEX(reserve_sem);
-        char devfs_name[16];
+        char devfs_name[20];
 
 	actifsettings = dev->actconfig->interface->altsetting;
 
@@ -375,8 +373,8 @@
 	};
 	dbg("Display length: %d", priv->plength);
 
-	sprintf(devfs_name, "brlvger%d", priv->subminor);
-	priv->devfs = devfs_register(usb_devfs_handle, devfs_name,
+	sprintf(devfs_name, "usb/brlvger%d", priv->subminor);
+	priv->devfs = devfs_register(NULL, devfs_name,
 				     DEVFS_FL_DEFAULT, USB_MAJOR,
 				     BRLVGER_MINOR+priv->subminor,
 				     S_IFCHR |S_IRUSR|S_IWUSR |S_IRGRP|S_IWGRP,
drivers/usb/misc/rio500.c +1 -3
diff -Nru a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
@@ -76,8 +76,6 @@
 	struct semaphore lock;          /* general race avoidance */
 };
 
-extern devfs_handle_t usb_devfs_handle;	/* /dev/usb dir. */
-
 static struct rio_usb_data rio_instance;
 
 static int open_rio(struct inode *inode, struct file *file)
@@ -478,7 +476,7 @@
 	}
 	dbg("probe_rio: ibuf address:%p", rio->ibuf);
 
-	rio->devfs = devfs_register(usb_devfs_handle, "rio500",
+	rio->devfs = devfs_register(NULL, "usb/rio500",
 				    DEVFS_FL_DEFAULT, USB_MAJOR,
 				    RIO_MINOR,
 				    S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP |
drivers/usb/net/rtl8150.c +0 -1
diff -Nru a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c
@@ -107,7 +107,6 @@
 typedef struct rtl8150 rtl8150_t;
 
 /* the global usb devfs handle */
-extern devfs_handle_t usb_devfs_handle;
 unsigned long multicast_filter_limit = 32;
 
 static void fill_skb_pool(rtl8150_t *);
drivers/usb/usb-skeleton.c +3 -6
diff -Nru a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
@@ -119,9 +119,6 @@
 };
 
 
-/* the global usb devfs handle */
-extern devfs_handle_t usb_devfs_handle;
-
 /* prevent races between open() and disconnect() */
 static DECLARE_MUTEX (disconnect_sem);
 
@@ -514,7 +511,7 @@
 	size_t buffer_size;
 	int i;
 	int retval;
-	char name[10];
+	char name[14];
 
 
 	/* See if the device offered us matches what we can accept */
@@ -609,9 +606,9 @@
 	}
 
 	/* initialize the devfs node for this device and register it */
-	sprintf(name, "skel%d", dev->minor);
+	sprintf(name, "usb/skel%d", dev->minor);
 
-	dev->devfs = devfs_register (usb_devfs_handle, name,
+	dev->devfs = devfs_register(NULL, name,
 				     DEVFS_FL_DEFAULT, USB_MAJOR,
 				     dev->minor,
 				     S_IFCHR | S_IRUSR | S_IWUSR |

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#1 lore raw
Quoted 3 lines · Christoph Hellwig

Many usb drivers use the usb_devfs_handle variable instead of just adding the usb/ prefix directly to their devfs_register calls. Fix that and make usb_devfs_handle static and unexported.

Looks good to me. If Linus doesn't add it to his tree, I'll add it to mine, and send it to him in the next round of USB updates.

thanks,

greg k-h