Skip to content

Commit

Permalink
staging: comedi: set hw_dev in comedi_alloc_board_minor()
Browse files Browse the repository at this point in the history
Call `comedi_set_hw_dev()` to set the `hw_dev` member of `struct
comedi_device` in `comedi_alloc_board_minor()` instead of in
`comedi_auto_config()`.  Don't bother to check for an error returned by
`comedi_set_hw_dev()` here; it only fails when changing a non-NULL
pointer to a different non-NULL pointer and since the `struct
comedi_device` has just been allocated and initialized, its `hw_dev`
will be NULL already.  Calling `comedi_set_hw_dev()` with a non-NULL
hardware device pointer increments the kref counter for the hardware
device.

If `comedi_alloc_board_minor()` fails further down the function, we rely
on its call to `comedi_device_cleanup()` to call `comedi_clear_hw_dev()`
(via `comedi_device_detach()` and `cleanup_device()`) to clear `hw_dev`
and decrement its kref counter.  (That's the "beneficial side-effect"
mentioned in the patch that replaced `__comedi_device_detach()`.)

Remove the call to `comedi_set_hw_dev()` from `comedi_auto_config()` as
the call to `comedi_alloc_board_minor()` does it for us.

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>
  • Loading branch information
Ian Abbott authored and Greg Kroah-Hartman committed Apr 5, 2013
1 parent 74ece10 commit db2e348
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 1 deletion.
1 change: 1 addition & 0 deletions drivers/staging/comedi/comedi_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -2326,6 +2326,7 @@ struct comedi_device *comedi_alloc_board_minor(struct device *hardware_device)
info->device = dev;
info->hardware_device = hardware_device;
comedi_device_init(dev);
comedi_set_hw_dev(dev, hardware_device);
mutex_lock(&dev->mutex);
spin_lock(&comedi_file_info_table_lock);
for (i = hardware_device ? comedi_num_legacy_minors : 0;
Expand Down
1 change: 0 additions & 1 deletion drivers/staging/comedi/drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ int comedi_auto_config(struct device *hardware_device,
return PTR_ERR(comedi_dev);
/* Note: comedi_alloc_board_minor() locked comedi_dev->mutex. */

comedi_set_hw_dev(comedi_dev, hardware_device);
comedi_dev->driver = driver;
ret = driver->auto_attach(comedi_dev, context);
if (ret >= 0)
Expand Down

0 comments on commit db2e348

Please sign in to comment.