staging: comedi: don't hijack hardware device private data
comedi_auto_config() associates a Comedi minor device number with an auto-configured hardware device and comedi_auto_unconfig() disassociates it. Currently, these use the hardware device's private data pointer to point to some allocated storage holding the minor device number. This is a bit of a waste of the hardware device's private data pointer, preventing it from being used for something more useful by the low-level comedi device drivers. For example, it would make more sense if comedi_usb_auto_config() was passed a pointer to the struct usb_interface instead of the struct usb_device, but this cannot be done currently because the low-level comedi drivers already use the private data pointer in the struct usb_interface for something more useful. This patch stops the comedi core hijacking the hardware device's private data pointer. Instead, comedi_auto_config() stores a pointer to the hardware device's struct device in the struct comedi_device_file_info associated with the minor device number, and comedi_auto_unconfig() calls new function comedi_find_board_minor() to recover the minor device number associated with the hardware device. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
7cbd8f3dca
commit
c43435d772
4 changed files with 30 additions and 24 deletions
|
@ -2205,6 +2205,7 @@ int comedi_alloc_board_minor(struct device *hardware_device)
|
||||||
kfree(info);
|
kfree(info);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
info->hardware_device = hardware_device;
|
||||||
comedi_device_init(info->device);
|
comedi_device_init(info->device);
|
||||||
spin_lock(&comedi_file_info_table_lock);
|
spin_lock(&comedi_file_info_table_lock);
|
||||||
for (i = 0; i < COMEDI_NUM_BOARD_MINORS; ++i) {
|
for (i = 0; i < COMEDI_NUM_BOARD_MINORS; ++i) {
|
||||||
|
@ -2292,6 +2293,23 @@ void comedi_free_board_minor(unsigned minor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int comedi_find_board_minor(struct device *hardware_device)
|
||||||
|
{
|
||||||
|
int minor;
|
||||||
|
struct comedi_device_file_info *info;
|
||||||
|
|
||||||
|
for (minor = 0; minor < COMEDI_NUM_BOARD_MINORS; minor++) {
|
||||||
|
spin_lock(&comedi_file_info_table_lock);
|
||||||
|
info = comedi_file_info_table[minor];
|
||||||
|
if (info && info->hardware_device == hardware_device) {
|
||||||
|
spin_unlock(&comedi_file_info_table_lock);
|
||||||
|
return minor;
|
||||||
|
}
|
||||||
|
spin_unlock(&comedi_file_info_table_lock);
|
||||||
|
}
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
int comedi_alloc_subdevice_minor(struct comedi_device *dev,
|
int comedi_alloc_subdevice_minor(struct comedi_device *dev,
|
||||||
struct comedi_subdevice *s)
|
struct comedi_subdevice *s)
|
||||||
{
|
{
|
||||||
|
|
|
@ -234,6 +234,7 @@ struct comedi_device_file_info {
|
||||||
struct comedi_device *device;
|
struct comedi_device *device;
|
||||||
struct comedi_subdevice *read_subdevice;
|
struct comedi_subdevice *read_subdevice;
|
||||||
struct comedi_subdevice *write_subdevice;
|
struct comedi_subdevice *write_subdevice;
|
||||||
|
struct device *hardware_device;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CONFIG_COMEDI_DEBUG
|
#ifdef CONFIG_COMEDI_DEBUG
|
||||||
|
|
|
@ -822,25 +822,14 @@ static int comedi_auto_config(struct device *hardware_device,
|
||||||
int minor;
|
int minor;
|
||||||
struct comedi_device_file_info *dev_file_info;
|
struct comedi_device_file_info *dev_file_info;
|
||||||
int retval;
|
int retval;
|
||||||
unsigned *private_data = NULL;
|
|
||||||
|
|
||||||
if (!comedi_autoconfig) {
|
if (!comedi_autoconfig)
|
||||||
dev_set_drvdata(hardware_device, NULL);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
minor = comedi_alloc_board_minor(hardware_device);
|
minor = comedi_alloc_board_minor(hardware_device);
|
||||||
if (minor < 0)
|
if (minor < 0)
|
||||||
return minor;
|
return 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);
|
dev_file_info = comedi_get_device_file_info(minor);
|
||||||
|
|
||||||
memset(&it, 0, sizeof(it));
|
memset(&it, 0, sizeof(it));
|
||||||
|
@ -853,25 +842,22 @@ static int comedi_auto_config(struct device *hardware_device,
|
||||||
retval = comedi_device_attach(dev_file_info->device, &it);
|
retval = comedi_device_attach(dev_file_info->device, &it);
|
||||||
mutex_unlock(&dev_file_info->device->mutex);
|
mutex_unlock(&dev_file_info->device->mutex);
|
||||||
|
|
||||||
cleanup:
|
if (retval < 0)
|
||||||
if (retval < 0) {
|
|
||||||
kfree(private_data);
|
|
||||||
comedi_free_board_minor(minor);
|
comedi_free_board_minor(minor);
|
||||||
}
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void comedi_auto_unconfig(struct device *hardware_device)
|
static void comedi_auto_unconfig(struct device *hardware_device)
|
||||||
{
|
{
|
||||||
unsigned *minor = (unsigned *)dev_get_drvdata(hardware_device);
|
int minor;
|
||||||
if (minor == NULL)
|
|
||||||
|
if (hardware_device == NULL)
|
||||||
return;
|
return;
|
||||||
|
minor = comedi_find_board_minor(hardware_device);
|
||||||
BUG_ON(*minor >= COMEDI_NUM_BOARD_MINORS);
|
if (minor < 0)
|
||||||
|
return;
|
||||||
comedi_free_board_minor(*minor);
|
BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
|
||||||
dev_set_drvdata(hardware_device, NULL);
|
comedi_free_board_minor(minor);
|
||||||
kfree(minor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int comedi_pci_auto_config(struct pci_dev *pcidev, struct comedi_driver *driver)
|
int comedi_pci_auto_config(struct pci_dev *pcidev, struct comedi_driver *driver)
|
||||||
|
|
|
@ -7,6 +7,7 @@ int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
|
||||||
struct comedi_insn *insn, unsigned int *data);
|
struct comedi_insn *insn, unsigned int *data);
|
||||||
int comedi_alloc_board_minor(struct device *hardware_device);
|
int comedi_alloc_board_minor(struct device *hardware_device);
|
||||||
void comedi_free_board_minor(unsigned minor);
|
void comedi_free_board_minor(unsigned minor);
|
||||||
|
int comedi_find_board_minor(struct device *hardware_device);
|
||||||
void comedi_reset_async_buf(struct comedi_async *async);
|
void comedi_reset_async_buf(struct comedi_async *async);
|
||||||
int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
|
int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
|
||||||
unsigned long new_size);
|
unsigned long new_size);
|
||||||
|
|
Loading…
Add table
Reference in a new issue