`comedi_alloc_board_minor()` allocates and initializes a `struct
comedi_file_info` and a `struct comedi_device`, and assigns a board
minor device number (if there are any available), storing a pointer to
the allocated `struct comedi_file_info` in
`comedi_board_minor_table[minor]` where `minor` is the board minor
device number.
There is no longer anything useful in the `struct comedi_file_info`
apart from the pointer to the `struct comedi_device` that was allocated,
so the `struct comedi_file_info` is superfluous.
Change `comedi_board_minor_table[]` to hold pointers to the actual
`struct comedi_device`'s. `comedi_alloc_board_minor()` no longer needs
to allocate a `struct comedi_file_info`. Replace
`comedi_free_board_file_info()` with `comedi_free_board_dev()` with its
parameter pointing to the `struct comedi_device` to be freed (there is
no longer a `struct comedi_file_info` to be freed).
There are consequential changes to `comedi_dev_from_board_minor()`,
`comedi_clear_board_minor()` (which now returns a `struct comedi_device
*`), `comedi_free_board_minor()`, `comedi_release_hardware_device()` and
`comedi_unlocked_ioctl()` (when dealing with detachment of a dynamically
allocated comedi device by the `COMEDI_DEVCONFIG` ioctl).
`comedi_dev_from_file_info()` is no longer used as a result of the above
changes so remove it.
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
};
static DEFINE_MUTEX(comedi_board_minor_table_lock);
};
static DEFINE_MUTEX(comedi_board_minor_table_lock);
-static struct comedi_file_info
+static struct comedi_device
*comedi_board_minor_table[COMEDI_NUM_BOARD_MINORS];
static DEFINE_MUTEX(comedi_subdevice_minor_table_lock);
*comedi_board_minor_table[COMEDI_NUM_BOARD_MINORS];
static DEFINE_MUTEX(comedi_subdevice_minor_table_lock);
mutex_destroy(&dev->mutex);
}
mutex_destroy(&dev->mutex);
}
-static struct comedi_file_info *comedi_clear_board_minor(unsigned minor)
+static struct comedi_device *comedi_clear_board_minor(unsigned minor)
- struct comedi_file_info *info;
+ struct comedi_device *dev;
mutex_lock(&comedi_board_minor_table_lock);
mutex_lock(&comedi_board_minor_table_lock);
- info = comedi_board_minor_table[minor];
+ dev = comedi_board_minor_table[minor];
comedi_board_minor_table[minor] = NULL;
mutex_unlock(&comedi_board_minor_table_lock);
comedi_board_minor_table[minor] = NULL;
mutex_unlock(&comedi_board_minor_table_lock);
-static void comedi_free_board_file_info(struct comedi_file_info *info)
+static void comedi_free_board_dev(struct comedi_device *dev)
- if (info) {
- struct comedi_device *dev = info->device;
- if (dev) {
- if (dev->class_dev) {
- device_destroy(comedi_class,
- MKDEV(COMEDI_MAJOR, dev->minor));
- }
- comedi_device_cleanup(dev);
- kfree(dev);
+ if (dev) {
+ if (dev->class_dev) {
+ device_destroy(comedi_class,
+ MKDEV(COMEDI_MAJOR, dev->minor));
+ comedi_device_cleanup(dev);
+ kfree(dev);
-static struct comedi_device *
-comedi_dev_from_file_info(struct comedi_file_info *info)
-{
- return info ? info->device : NULL;
-}
-
static struct comedi_device *comedi_dev_from_board_minor(unsigned minor)
{
static struct comedi_device *comedi_dev_from_board_minor(unsigned minor)
{
- struct comedi_file_info *info;
+ struct comedi_device *dev;
BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
mutex_lock(&comedi_board_minor_table_lock);
BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
mutex_lock(&comedi_board_minor_table_lock);
- info = comedi_board_minor_table[minor];
+ dev = comedi_board_minor_table[minor];
mutex_unlock(&comedi_board_minor_table_lock);
mutex_unlock(&comedi_board_minor_table_lock);
- return comedi_dev_from_file_info(info);
}
static struct comedi_device *comedi_dev_from_subdevice_minor(unsigned minor)
}
static struct comedi_device *comedi_dev_from_subdevice_minor(unsigned minor)
dev->minor >= comedi_num_legacy_minors) {
/* Successfully unconfigured a dynamically
* allocated device. Try and remove it. */
dev->minor >= comedi_num_legacy_minors) {
/* Successfully unconfigured a dynamically
* allocated device. Try and remove it. */
- struct comedi_file_info *info;
- info = comedi_clear_board_minor(dev->minor);
- if (info) {
+ struct comedi_device *devr;
+ devr = comedi_clear_board_minor(dev->minor);
+ if (dev == devr) {
mutex_unlock(&dev->mutex);
mutex_unlock(&dev->mutex);
- comedi_free_board_file_info(info);
+ comedi_free_board_dev(dev);
/* Note: the ->mutex is pre-locked on successful return */
struct comedi_device *comedi_alloc_board_minor(struct device *hardware_device)
{
/* Note: the ->mutex is pre-locked on successful return */
struct comedi_device *comedi_alloc_board_minor(struct device *hardware_device)
{
- struct comedi_file_info *info;
struct comedi_device *dev;
struct device *csdev;
unsigned i;
struct comedi_device *dev;
struct device *csdev;
unsigned i;
- info = kzalloc(sizeof(*info), GFP_KERNEL);
- if (info == NULL)
- return ERR_PTR(-ENOMEM);
dev = kzalloc(sizeof(struct comedi_device), GFP_KERNEL);
dev = kzalloc(sizeof(struct comedi_device), GFP_KERNEL);
- if (dev == NULL) {
- kfree(info);
- }
- info->device = dev;
comedi_device_init(dev);
comedi_set_hw_dev(dev, hardware_device);
mutex_lock(&dev->mutex);
comedi_device_init(dev);
comedi_set_hw_dev(dev, hardware_device);
mutex_lock(&dev->mutex);
for (i = hardware_device ? comedi_num_legacy_minors : 0;
i < COMEDI_NUM_BOARD_MINORS; ++i) {
if (comedi_board_minor_table[i] == NULL) {
for (i = hardware_device ? comedi_num_legacy_minors : 0;
i < COMEDI_NUM_BOARD_MINORS; ++i) {
if (comedi_board_minor_table[i] == NULL) {
- comedi_board_minor_table[i] = info;
+ comedi_board_minor_table[i] = dev;
mutex_unlock(&dev->mutex);
comedi_device_cleanup(dev);
kfree(dev);
mutex_unlock(&dev->mutex);
comedi_device_cleanup(dev);
kfree(dev);
pr_err("comedi: error: ran out of minor numbers for board device files.\n");
return ERR_PTR(-EBUSY);
}
pr_err("comedi: error: ran out of minor numbers for board device files.\n");
return ERR_PTR(-EBUSY);
}
static void comedi_free_board_minor(unsigned minor)
{
BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
static void comedi_free_board_minor(unsigned minor)
{
BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
- comedi_free_board_file_info(comedi_clear_board_minor(minor));
+ comedi_free_board_dev(comedi_clear_board_minor(minor));
}
void comedi_release_hardware_device(struct device *hardware_device)
{
int minor;
}
void comedi_release_hardware_device(struct device *hardware_device)
{
int minor;
- struct comedi_file_info *info;
+ struct comedi_device *dev;
for (minor = comedi_num_legacy_minors; minor < COMEDI_NUM_BOARD_MINORS;
minor++) {
mutex_lock(&comedi_board_minor_table_lock);
for (minor = comedi_num_legacy_minors; minor < COMEDI_NUM_BOARD_MINORS;
minor++) {
mutex_lock(&comedi_board_minor_table_lock);
- info = comedi_board_minor_table[minor];
- if (info && info->device->hw_dev == hardware_device) {
+ dev = comedi_board_minor_table[minor];
+ if (dev && dev->hw_dev == hardware_device) {
comedi_board_minor_table[minor] = NULL;
mutex_unlock(&comedi_board_minor_table_lock);
comedi_board_minor_table[minor] = NULL;
mutex_unlock(&comedi_board_minor_table_lock);
- comedi_free_board_file_info(info);
+ comedi_free_board_dev(dev);
break;
}
mutex_unlock(&comedi_board_minor_table_lock);
break;
}
mutex_unlock(&comedi_board_minor_table_lock);