From: Bernd Porr Date: Mon, 8 Dec 2008 23:30:13 +0000 (+0000) Subject: Staging: comedi: add comedi_usb_auto_[un]config functions X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=c28264dac4348b1514a9a0abcf0014c6b460637f;p=openwrt%2Fstaging%2Fblogic.git Staging: comedi: add comedi_usb_auto_[un]config functions This will be used by the usbdux and usbduxfast drivers. From: Bernd Porr Cc: Ian Abbott Cc: Frank Mori Hess Cc: David Schleef Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/comedi_ksyms.c b/drivers/staging/comedi/comedi_ksyms.c index 90d57282efb8..7d0db3bb680f 100644 --- a/drivers/staging/comedi/comedi_ksyms.c +++ b/drivers/staging/comedi/comedi_ksyms.c @@ -60,6 +60,8 @@ EXPORT_SYMBOL_GPL(comedi_alloc_board_minor); EXPORT_SYMBOL_GPL(comedi_free_board_minor); EXPORT_SYMBOL_GPL(comedi_pci_auto_config); EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig); +EXPORT_SYMBOL_GPL(comedi_usb_auto_config); +EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig); /* for kcomedilib */ EXPORT_SYMBOL(check_chanlist); diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 4679911171de..6d67c48754c5 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -530,6 +530,9 @@ int comedi_alloc_subdevice_minor(comedi_device *dev, comedi_subdevice *s); void comedi_free_subdevice_minor(comedi_subdevice *s); int comedi_pci_auto_config(struct pci_dev *pcidev, const char *board_name); void comedi_pci_auto_unconfig(struct pci_dev *pcidev); +struct usb_device; /* forward declaration */ +int comedi_usb_auto_config(struct usb_device *usbdev, const char *board_name); +void comedi_usb_auto_unconfig(struct usb_device *usbdev); #include "comedi_rt.h" diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 5579aa0a9331..7322eb8e2ba9 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -796,13 +797,21 @@ int comedi_auto_config(struct device *hardware_device, const char *board_name, c int minor; struct comedi_device_file_info *dev_file_info; int retval; + unsigned *private_data = NULL; if (!comedi_autoconfig) return -ENODEV; minor = comedi_alloc_board_minor(hardware_device); if(minor < 0) return minor; - dev_set_drvdata(hardware_device, (void*)(unsigned long)minor); + + private_data = kmalloc(sizeof(unsigned), GFP_KERNEL); + if (private_data == NULL) { + retval = -ENOMEM; + goto cleanup; + } + *private_data = minor; + dev_set_drvdata(hardware_device, private_data); dev_file_info = comedi_get_device_file_info(minor); @@ -815,8 +824,11 @@ int comedi_auto_config(struct device *hardware_device, const char *board_name, c mutex_lock(&dev_file_info->device->mutex); retval = comedi_device_attach(dev_file_info->device, &it); mutex_unlock(&dev_file_info->device->mutex); + +cleanup: if(retval < 0) { + kfree(private_data); comedi_free_board_minor(minor); } return retval; @@ -824,11 +836,14 @@ int comedi_auto_config(struct device *hardware_device, const char *board_name, c void comedi_auto_unconfig(struct device *hardware_device) { - unsigned long minor = (unsigned long)dev_get_drvdata(hardware_device); + unsigned *minor = (unsigned *)dev_get_drvdata(hardware_device); + if(minor == NULL) return; - BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS); + BUG_ON(*minor >= COMEDI_NUM_BOARD_MINORS); - comedi_free_board_minor(minor); + comedi_free_board_minor(*minor); + dev_set_drvdata(hardware_device, NULL); + kfree(minor); } int comedi_pci_auto_config(struct pci_dev *pcidev, const char *board_name) @@ -847,3 +862,16 @@ void comedi_pci_auto_unconfig(struct pci_dev *pcidev) { comedi_auto_unconfig(&pcidev->dev); } + +int comedi_usb_auto_config(struct usb_device *usbdev, + const char *board_name) +{ + BUG_ON(usbdev == NULL); + return comedi_auto_config(&usbdev->dev, board_name, NULL, 0); +} + +void comedi_usb_auto_unconfig(struct usb_device *usbdev) +{ + BUG_ON(usbdev == NULL); + comedi_auto_unconfig(&usbdev->dev); +}