rio500 devfs support
PATCH 1/1 rio500 devfs support
The attached diff adds devfs support to the rio500 driver, so that /dev/usb/rio500 gets created automagically. It was generated against 2.4.5, but probably applies fine against any recent kernel. Comments are welcome (but be gentle, this is my first attempt at a kernel patch :-).
Cheers!
drivers/usb/rio500.c +9 -0
@@ -38,6 +38,7 @@#include <linux/spinlock.h> #include <linux/usb.h> #include <linux/smp_lock.h> +#include <linux/devfs_fs_kernel.h> #include "rio500_usb.h"
@@ -70,6 +71,7 @@ };static struct rio_usb_data rio_instance; +static devfs_handle_t rio500_devfs_handle;static int open_rio (struct inode *inode,struct file *file) {
@@ -492,6 +494,12 @@if (usb_register (&rio_driver) <0 )return -1 ; + rio500_devfs_handle =devfs_register (NULL ,"usb/rio500" , +DEVFS_FL_DEFAULT , +USB_MAJOR ,RIO_MINOR , +S_IFCHR |S_IRUSR |S_IWUSR |S_IRGRP |S_IWGRP , + &usb_rio_fops,NULL ); +info (DRIVER_VERSION " " DRIVER_AUTHOR );info (DRIVER_DESC );
@@ -506,6 +514,7 @@ rio->present =0 ;usb_deregister (&rio_driver); +devfs_unregister (rio500_devfs_handle); }
Here's an updated version of the patch - the only real difference is that rio500.c will printk an error message if devfs_register() fails. I left that out originally because devfs logs the error, but it's probably a good idea to indicate which driver made the request.
Cheers!
Quoted 7 lines · Gregory T. Norris
The attached diff adds devfs support to the rio500 driver, so that
/dev/usb/rio500gets created automagically. It was generated against 2.4.5, but probably applies fine against any recent kernel. Comments are welcome (but be gentle, this is my first attempt at a kernel patch :-).Cheers!
drivers/usb/rio500.c +12 -0
@@ -38,6 +38,7 @@#include <linux/spinlock.h> #include <linux/usb.h> #include <linux/smp_lock.h> +#include <linux/devfs_fs_kernel.h> #include "rio500_usb.h"
@@ -70,6 +71,7 @@ };static struct rio_usb_data rio_instance; +static devfs_handle_t rio500_devfs_handle;static int open_rio (struct inode *inode,struct file *file) {
@@ -492,6 +494,14 @@if (usb_register (&rio_driver) <0 )return -1 ; + rio500_devfs_handle =devfs_register (NULL ,"usb/rio500" , +DEVFS_FL_DEFAULT , +USB_MAJOR ,RIO_MINOR , +S_IFCHR |S_IRUSR |S_IWUSR |S_IRGRP |S_IWGRP , + &usb_rio_fops,NULL ); +if (rio500_devfs_handle ==NULL ) + printk(KERN_WARNING __FILE__ ": unable to register /dev/usb/rio500 with devfs\n"); +info (DRIVER_VERSION " " DRIVER_AUTHOR );info (DRIVER_DESC );
@@ -506,6 +516,8 @@ rio->present =0 ;usb_deregister (&rio_driver); +if (rio500_devfs_handle !=NULL ) +devfs_unregister (rio500_devfs_handle); }
Quoted 4 lines · Gregory T. Norris
--qlTNgmc+xy1dBmNv
Content-Type: multipart/mixed; boundary="0F1p//8PRICkK4MW"
Content-Disposition: inline
Yuk! MIME!
Quoted 4 lines
--0F1p//8PRICkK4MW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Horrors! Quoted-printables!
Quoted 4 lines
Here's an updated version of the patch - the only real difference is that
rio500.cwill printk an error message ifdevfs_register()fails.=20 I left that out originally because devfs logs the error, but it's probably a good idea to indicate which driver made the request.
No, it's a bad idea to test the error from devfs_register() unless you *really* have a good reason. Most people who think they have a good reason actually don't, they're just confused :-)
The reason you don't want to test the return value is that way the driver works fine with CONFIG_DEVFS=n. Otherwise, you have a driver that doesn't work with devfs, or you have to put ugly #ifdef's in the code.
Regards, Richard.... Permanent: [email protected] Current: [email protected]
Ok, back to the original version then. Thanx!
Quoted 14 lines · Richard Gooch
No, it's a bad idea to test the error from
devfs_register()unless you *really* have a good reason. Most people who think they have a good reason actually don't, they're just confused :-)The reason you don't want to test the return value is that way the driver works fine with
CONFIG_DEVFS=n. Otherwise, you have a driver that doesn't work with devfs, or you have to put ugly #ifdef's in the code.Regards, Richard.... Permanent: [email protected] Current: [email protected]
Quoted 5 lines · Gregory T. Norris
The attached diff adds devfs support to the rio500 driver, so that
/dev/usb/rio500gets created automagically. It was generated against 2.4.5, but probably applies fine against any recent kernel. Comments are welcome (but be gentle, this is my first attempt at a kernel patch :-).
Here's a small change that makes the node a child of the usb devfs entry. It also enables the node to only be present when the device is actually present. The patch is against 2.4.6-pre5.
thanks,
greg k-h
drivers/usb/rio500.c +24 -10
@@ -38,13 +38,14 @@#include <linux/spinlock.h> #include <linux/usb.h> #include <linux/smp_lock.h> +#include <linux/devfs_fs_kernel.h> #include "rio500_usb.h" /* * Version Information */ -#define DRIVER_VERSION "v1.0.0" +#define DRIVER_VERSION "v1.1"#define DRIVER_AUTHOR "Cesar Miquel <[email protected]>"#define DRIVER_DESC "USB Rio 500 driver"
@@ -60,6 +61,7 @@struct rio_usb_data {struct usb_device *rio_dev;/* init: probe_rio */ +devfs_handle_t devfs;/* devfs device */ unsigned int ifnum;/* Interface number of the USB device */ int isopen;/* nz if open */ int present;/* Device is present on the bus */
@@ -69,6 +71,8 @@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)
@@ -416,6 +420,15 @@return read_count; } +static struct +file_operations usb_rio_fops = { + read: read_rio, + write: write_rio, + ioctl: ioctl_rio, + open: open_rio, + release: close_rio, +}; +static void *probe_rio (struct usb_device *dev,unsigned int ifnum,const struct usb_device_id *id) {
@@ -439,6 +452,14 @@ }dbg ("probe_rio: ibuf address:%p" , rio->ibuf); + rio->devfs =devfs_register (usb_devfs_handle,"rio500" , +DEVFS_FL_DEFAULT ,USB_MAJOR , +RIO_MINOR , +S_IFCHR |S_IRUSR |S_IWUSR |S_IRGRP | +S_IWGRP , &usb_rio_fops,NULL ); +if (rio->devfs ==NULL ) +dbg ("probe_rio: device node registration failed" ); +init_MUTEX (&(rio->lock));return rio;
@@ -448,6 +469,8 @@ {struct rio_usb_data *rio = (struct rio_usb_data *) ptr; +devfs_unregister (rio->devfs); +if (rio->isopen) { rio->isopen =0 ;/* better let it finish - the release will do whats needed */
@@ -461,15 +484,6 @@ rio->present =0 ; } - -static struct -file_operations usb_rio_fops = { - read: read_rio, - write: write_rio, - ioctl: ioctl_rio, - open: open_rio, - release: close_rio, -};static struct usb_device_id rio_table [] = { {USB_DEVICE (0x0841 ,1 ) },/* Rio 500 */
I was thinking of doing some similar updates this evening after work. Darn it... now I have to find something else to do! :-)
Going by this morning's comments from Richard Gooch, it sounds like the
if (rio->devfs == NULL)
dbg("probe_rio: device node registration failed");part should probably be removed... it looks good to me otherwise, tho. I'll try it out tonight and post the results.
Cheers!
Quoted 7 lines · Greg KH
Here's a small change that makes the node a child of the usb devfs entry. It also enables the node to only be present when the device is actually present. The patch is against 2.4.6-pre5.
thanks,
greg k-h
Quoted 7 lines · Gregory T. Norris
I was thinking of doing some similar updates this evening after work. Darn it... now I have to find something else to do! :-)
Going by this morning's comments from Richard Gooch, it sounds like the
if (rio->devfs == NULL) dbg("probe_rio: device node registration failed");
Just don't have it be using a call to "err()" like the printer.c file does. Loads of users wondering why they have an error message in their logs, yet their printers still work. That's why I made it dbg().
But yes, I agree that it doesn't have to be there at all.
greg k-h
It's working beautifully here. I'll forward the patch to the maintainer, since I have no idea if he's seen this thread.
Cheers!