Commit eb5a0a8c authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: dt9812: move the sempaphore used by the comedi_driver

The semaphore in the struct slot_dt9812 is used by the comedi_driver
when reading and writing to the usb device. It has no real association
with the 'slot'. The 'slot' is protected with a static semaphore in
the driver.

Move the semaphore into the comedi_device private data and initialize
it after the private data is allocated.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fad1c320
...@@ -280,11 +280,11 @@ struct usb_dt9812 { ...@@ -280,11 +280,11 @@ struct usb_dt9812 {
}; };
struct dt9812_private { struct dt9812_private {
struct semaphore sem;
struct slot_dt9812 *slot; struct slot_dt9812 *slot;
}; };
struct slot_dt9812 { struct slot_dt9812 {
struct semaphore mutex;
struct usb_dt9812 *usb; struct usb_dt9812 *usb;
struct dt9812_private *devpriv; struct dt9812_private *devpriv;
}; };
...@@ -391,7 +391,7 @@ static int dt9812_digital_in(struct comedi_device *dev, u8 *bits) ...@@ -391,7 +391,7 @@ static int dt9812_digital_in(struct comedi_device *dev, u8 *bits)
struct slot_dt9812 *slot = devpriv->slot; struct slot_dt9812 *slot = devpriv->slot;
int ret = -ENODEV; int ret = -ENODEV;
down(&slot->mutex); down(&devpriv->sem);
if (slot->usb) { if (slot->usb) {
u8 reg[2] = { F020_SFR_P3, F020_SFR_P1 }; u8 reg[2] = { F020_SFR_P3, F020_SFR_P1 };
u8 value[2]; u8 value[2];
...@@ -406,7 +406,7 @@ static int dt9812_digital_in(struct comedi_device *dev, u8 *bits) ...@@ -406,7 +406,7 @@ static int dt9812_digital_in(struct comedi_device *dev, u8 *bits)
*bits = (value[0] & 0x7f) | ((value[1] & 0x08) << 4); *bits = (value[0] & 0x7f) | ((value[1] & 0x08) << 4);
} }
} }
up(&slot->mutex); up(&devpriv->sem);
return ret; return ret;
} }
...@@ -417,7 +417,7 @@ static int dt9812_digital_out(struct comedi_device *dev, u8 bits) ...@@ -417,7 +417,7 @@ static int dt9812_digital_out(struct comedi_device *dev, u8 bits)
struct slot_dt9812 *slot = devpriv->slot; struct slot_dt9812 *slot = devpriv->slot;
int ret = -ENODEV; int ret = -ENODEV;
down(&slot->mutex); down(&devpriv->sem);
if (slot->usb) { if (slot->usb) {
u8 reg[1] = { F020_SFR_P2 }; u8 reg[1] = { F020_SFR_P2 };
u8 value[1] = { bits }; u8 value[1] = { bits };
...@@ -425,7 +425,7 @@ static int dt9812_digital_out(struct comedi_device *dev, u8 bits) ...@@ -425,7 +425,7 @@ static int dt9812_digital_out(struct comedi_device *dev, u8 bits)
ret = dt9812_write_multiple_registers(slot->usb, 1, reg, value); ret = dt9812_write_multiple_registers(slot->usb, 1, reg, value);
slot->usb->digital_out_shadow = bits; slot->usb->digital_out_shadow = bits;
} }
up(&slot->mutex); up(&devpriv->sem);
return ret; return ret;
} }
...@@ -436,12 +436,12 @@ static int dt9812_digital_out_shadow(struct comedi_device *dev, u8 *bits) ...@@ -436,12 +436,12 @@ static int dt9812_digital_out_shadow(struct comedi_device *dev, u8 *bits)
struct slot_dt9812 *slot = devpriv->slot; struct slot_dt9812 *slot = devpriv->slot;
int ret = -ENODEV; int ret = -ENODEV;
down(&slot->mutex); down(&devpriv->sem);
if (slot->usb) { if (slot->usb) {
*bits = slot->usb->digital_out_shadow; *bits = slot->usb->digital_out_shadow;
ret = 0; ret = 0;
} }
up(&slot->mutex); up(&devpriv->sem);
return ret; return ret;
} }
...@@ -532,7 +532,7 @@ static int dt9812_analog_in(struct comedi_device *dev, ...@@ -532,7 +532,7 @@ static int dt9812_analog_in(struct comedi_device *dev,
u8 val[3]; u8 val[3];
int ret = -ENODEV; int ret = -ENODEV;
down(&slot->mutex); down(&devpriv->sem);
if (!slot->usb) if (!slot->usb)
goto exit; goto exit;
...@@ -583,7 +583,7 @@ static int dt9812_analog_in(struct comedi_device *dev, ...@@ -583,7 +583,7 @@ static int dt9812_analog_in(struct comedi_device *dev,
} }
exit: exit:
up(&slot->mutex); up(&devpriv->sem);
return ret; return ret;
} }
...@@ -595,12 +595,12 @@ static int dt9812_analog_out_shadow(struct comedi_device *dev, ...@@ -595,12 +595,12 @@ static int dt9812_analog_out_shadow(struct comedi_device *dev,
struct slot_dt9812 *slot = devpriv->slot; struct slot_dt9812 *slot = devpriv->slot;
int ret = -ENODEV; int ret = -ENODEV;
down(&slot->mutex); down(&devpriv->sem);
if (slot->usb) { if (slot->usb) {
*value = slot->usb->analog_out_shadow[channel]; *value = slot->usb->analog_out_shadow[channel];
ret = 0; ret = 0;
} }
up(&slot->mutex); up(&devpriv->sem);
return ret; return ret;
} }
...@@ -611,7 +611,7 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value) ...@@ -611,7 +611,7 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value)
struct slot_dt9812 *slot = devpriv->slot; struct slot_dt9812 *slot = devpriv->slot;
int ret = -ENODEV; int ret = -ENODEV;
down(&slot->mutex); down(&devpriv->sem);
if (slot->usb) { if (slot->usb) {
struct dt9812_rmw_byte rmw[3]; struct dt9812_rmw_byte rmw[3];
...@@ -655,7 +655,7 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value) ...@@ -655,7 +655,7 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value)
ret = dt9812_rmw_multiple_registers(slot->usb, 3, rmw); ret = dt9812_rmw_multiple_registers(slot->usb, 3, rmw);
slot->usb->analog_out_shadow[channel] = value; slot->usb->analog_out_shadow[channel] = value;
} }
up(&slot->mutex); up(&devpriv->sem);
return ret; return ret;
} }
...@@ -751,6 +751,7 @@ static int dt9812_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -751,6 +751,7 @@ static int dt9812_attach(struct comedi_device *dev, struct comedi_devconfig *it)
if (!devpriv) if (!devpriv)
return -ENOMEM; return -ENOMEM;
dev->private = devpriv; dev->private = devpriv;
sema_init(&devpriv->sem, 1);
down(&dt9812_mutex); down(&dt9812_mutex);
...@@ -769,11 +770,9 @@ static int dt9812_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -769,11 +770,9 @@ static int dt9812_attach(struct comedi_device *dev, struct comedi_devconfig *it)
return -ENODEV; return -ENODEV;
} }
down(&slot->mutex);
slot->devpriv = devpriv; slot->devpriv = devpriv;
devpriv->slot = slot; devpriv->slot = slot;
range_2_5 = (slot->usb->device == DT9812_DEVID_DT9812_2PT5); range_2_5 = (slot->usb->device == DT9812_DEVID_DT9812_2PT5);
up(&slot->mutex);
up(&dt9812_mutex); up(&dt9812_mutex);
...@@ -871,10 +870,8 @@ static int dt9812_probe(struct usb_interface *interface, ...@@ -871,10 +870,8 @@ static int dt9812_probe(struct usb_interface *interface,
goto error; goto error;
} }
down(&slot->mutex);
slot->usb = dev; slot->usb = dev;
dev->slot = slot; dev->slot = slot;
up(&slot->mutex);
up(&dt9812_mutex); up(&dt9812_mutex);
...@@ -1001,9 +998,7 @@ static void dt9812_disconnect(struct usb_interface *interface) ...@@ -1001,9 +998,7 @@ static void dt9812_disconnect(struct usb_interface *interface)
down(&dt9812_mutex); down(&dt9812_mutex);
dev = usb_get_intfdata(interface); dev = usb_get_intfdata(interface);
if (dev->slot) { if (dev->slot) {
down(&dev->slot->mutex);
dev->slot->usb = NULL; dev->slot->usb = NULL;
up(&dev->slot->mutex);
dev->slot = NULL; dev->slot = NULL;
} }
usb_set_intfdata(interface, NULL); usb_set_intfdata(interface, NULL);
...@@ -1034,7 +1029,6 @@ static int __init usb_dt9812_init(void) ...@@ -1034,7 +1029,6 @@ static int __init usb_dt9812_init(void)
/* Initialize all driver slots */ /* Initialize all driver slots */
for (i = 0; i < DT9812_NUM_SLOTS; i++) { for (i = 0; i < DT9812_NUM_SLOTS; i++) {
sema_init(&dt9812[i].mutex, 1);
dt9812[i].usb = NULL; dt9812[i].usb = NULL;
dt9812[i].devpriv = NULL; dt9812[i].devpriv = NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment