From db2e3487a5fa1f650680c672e0742d943039d2cc Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Thu, 4 Apr 2013 14:59:00 +0100 Subject: staging: comedi: set hw_dev in comedi_alloc_board_minor() 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 Reviewed-by: H Hartley Sweeten Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/comedi_fops.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/staging/comedi/comedi_fops.c') diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 229be419b014..b3e533759174 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -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; -- cgit v1.2.3-55-g7522