[PATCH 2/2] staging: comedi: restrict comedi_set_hw_dev() usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Don't allow comedi drivers to change `dev->hw_dev` using
`comedi_set_hw_dev()` if it's already been set.  Return `-EEXIST` in
that case.

`dev->hw_dev` needs to be set to NULL by the core during clean-up of the
comedi device, so add a local function `comedi_clear_hw_dev()` to do
that.

Signed-off-by: Ian Abbott <abbotti@xxxxxxxxx>
---
 drivers/staging/comedi/drivers.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 8dfaa56..17d3498 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -45,14 +45,21 @@ struct comedi_driver *comedi_drivers;
 
 int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev)
 {
-	struct device *old_hw_dev = dev->hw_dev;
-
+	if (hw_dev == dev->hw_dev)
+		return 0;
+	if (dev->hw_dev != NULL)
+		return -EEXIST;
 	dev->hw_dev = get_device(hw_dev);
-	put_device(old_hw_dev);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(comedi_set_hw_dev);
 
+static void comedi_clear_hw_dev(struct comedi_device *dev)
+{
+	put_device(dev->hw_dev);
+	dev->hw_dev = NULL;
+}
+
 int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices)
 {
 	struct comedi_subdevice *s;
@@ -108,7 +115,7 @@ static void cleanup_device(struct comedi_device *dev)
 	dev->write_subdev = NULL;
 	dev->open = NULL;
 	dev->close = NULL;
-	comedi_set_hw_dev(dev, NULL);
+	comedi_clear_hw_dev(dev);
 }
 
 static void __comedi_device_detach(struct comedi_device *dev)
-- 
1.8.1.1

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux