Skip to contentSkip to conversation

staging: comedi: usbduxsigma: don't clobber ai_timer in command test

PATCH In review Jiri Slaby 3 participants 9 messages Sep 16, 2015 – Sep 23, 2015 Stable branch

lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

PATCH 1/1 staging: comedi: usbduxsigma: don't clobber ai_timer in command test

From: Ian Abbott <[email protected]>

This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.

===============

commit 423b24c37dd5794a674c74b0ed56392003a69891 upstream

devpriv->ai_timer is used while an asynchronous command is running on the AI subdevice. It also gets modified by the subdevice's cmdtest handler for checking new asynchronous commands (usbduxsigma_ai_cmdtest()), which is not correct as it's allowed to check new commands while an old command is still running. Fix it by moving the code which sets up devpriv->ai_timer and devpriv->ai_interval into the subdevice's cmd handler, usbduxsigma_ai_cmd().

** This backported patch also moves the code that sets up devpriv->ai_sample_count and devpriv->ai_continuous from usbduxsigma_ai_cmdtest() to usbduxsigma_ai_cmd() for the same reason as above. (This was not needed in the upstream commit.) **

Note that the removed code in usbduxsigma_ai_cmdtest() checked that devpriv->ai_timer did not end up less than than 1, but that could not happen because cmd->scan_begin_arg had already been checked to be at least the minimum required value (at least when cmd->scan_begin_src == TRIG_TIMER, which had also been checked to be the case).

Fixes b986be8527c7 ("staging: comedi: usbduxsigma: tidy up analog input command support)
---
 drivers/staging/comedi/drivers/usbduxsigma.c | 58 +++++++++++++---------------
 1 file changed, 27 insertions(+), 31 deletions(-)
drivers/staging/comedi/drivers/usbduxsigma.c +27 -31
index c47f4087568f..c61a1b9d7cd8 100644
@@ -575,37 +575,6 @@ static int usbduxsigma_ai_cmdtest(struct comedi_device *dev,
 	if (err)
 		return 3;
 
-	/* Step 4: fix up any arguments */
-
-	if (high_speed) {
-		/*
-		 * every 2 channels get a time window of 125us. Thus, if we
-		 * sample all 16 channels we need 1ms. If we sample only one
-		 * channel we need only 125us
-		 */
-		devpriv->ai_interval = interval;
-		devpriv->ai_timer = cmd->scan_begin_arg / (125000 * interval);
-	} else {
-		/* interval always 1ms */
-		devpriv->ai_interval = 1;
-		devpriv->ai_timer = cmd->scan_begin_arg / 1000000;
-	}
-	if (devpriv->ai_timer < 1)
-		err |= -EINVAL;
-
-	if (cmd->stop_src == TRIG_COUNT) {
-		/* data arrives as one packet */
-		devpriv->ai_sample_count = cmd->stop_arg;
-		devpriv->ai_continuous = 0;
-	} else {
-		/* continuous acquisition */
-		devpriv->ai_continuous = 1;
-		devpriv->ai_sample_count = 0;
-	}
-
-	if (err)
-		return 4;
-
 	return 0;
 }
 
@@ -704,6 +673,33 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev,
 
 	/* set current channel of the running acquisition to zero */
 	s->async->cur_chan = 0;
+
+	if (devpriv->high_speed) {
+		/*
+		 * every 2 channels get a time window of 125us. Thus, if we
+		 * sample all 16 channels we need 1ms. If we sample only one
+		 * channel we need only 125us
+		 */
+		unsigned int interval = usbduxsigma_chans_to_interval(len);
+
+		devpriv->ai_interval = interval;
+		devpriv->ai_timer = cmd->scan_begin_arg / (125000 * interval);
+	} else {
+		/* interval always 1ms */
+		devpriv->ai_interval = 1;
+		devpriv->ai_timer = cmd->scan_begin_arg / 1000000;
+	}
+
+	if (cmd->stop_src == TRIG_COUNT) {
+		/* data arrives as one packet */
+		devpriv->ai_sample_count = cmd->stop_arg;
+		devpriv->ai_continuous = 0;
+	} else {
+		/* continuous acquisition */
+		devpriv->ai_continuous = 1;
+		devpriv->ai_sample_count = 0;
+	}
+
 	for (i = 0; i < len; i++) {
 		unsigned int chan  = CR_CHAN(cmd->chanlist[i]);
 
Signature · 1 line
2.5.2
author
#1 lore raw

PATCH 1/1 staging: comedi: usbduxsigma: don't clobber ao_timer in command test

From: Ian Abbott <[email protected]>

This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.

===============

commit c04a1f17803e0d3eeada586ca34a6b436959bc20 upstream

devpriv->ao_timer is used while an asynchronous command is running on the AO subdevice. It also gets modified by the subdevice's cmdtest handler for checking new asynchronous commands, usbduxsigma_ao_cmdtest(), which is not correct as it's allowed to check new commands while an old command is still running. Fix it by moving the code which sets up devpriv->ao_timer into the subdevice's cmd handler, usbduxsigma_ao_cmd().

** This backported patch also moves the code that sets up devpriv->ao_sample_count and devpriv->ao_continuous from usbduxsigma_ao_cmdtest() to usbduxsigma_ao_cmd() for the same reason as above. (This was not needed in the upstream commit.) **

Note that the removed code in usbduxsigma_ao_cmdtest() checked that devpriv->ao_timer did not end up less that 1, but that could not happen due because cmd->scan_begin_arg or cmd->convert_arg had already been range-checked.

Also note that we tested the high_speed variable in the old code, but that is currently always 0 and means that we always use "scan" timing (cmd->scan_begin_src == TRIG_TIMER and cmd->convert_src == TRIG_NOW) and never "convert" (individual sample) timing (cmd->scan_begin_src == TRIG_FOLLOW and cmd->convert_src == TRIG_TIMER). The moved code tests cmd->convert_src instead to decide whether "scan" or "convert" timing is being used, although currently only "scan" timing is supported.

Fixes fb1ef622e7a3 ("staging: comedi: usbduxsigma: tidy up analog output command support")
---
 drivers/staging/comedi/drivers/usbduxsigma.c | 41 ++++++++++++----------------
 1 file changed, 17 insertions(+), 24 deletions(-)
drivers/staging/comedi/drivers/usbduxsigma.c +17 -24
index c61a1b9d7cd8..580c1358eb84 100644
@@ -950,10 +950,24 @@ static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
 	if (err)
 		return 3;
 
-	/* Step 4: fix up any arguments */
+	return 0;
+}
+
+static int usbduxsigma_ao_cmd(struct comedi_device *dev,
+			      struct comedi_subdevice *s)
+{
+	struct usbduxsigma_private *devpriv = dev->private;
+	struct comedi_cmd *cmd = &s->async->cmd;
+	int ret;
+	int i;
+
+	down(&devpriv->sem);
+
+	/* set current channel of the running acquisition to zero */
+	s->async->cur_chan = 0;
 
 	/* we count in timer steps */
-	if (high_speed) {
+	if (cmd->convert_src == TRIG_TIMER) {
 		/* timing of the conversion itself: every 125 us */
 		devpriv->ao_timer = cmd->convert_arg / 125000;
 	} else {
@@ -963,12 +977,9 @@ static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
 		 */
 		devpriv->ao_timer = cmd->scan_begin_arg / 1000000;
 	}
-	if (devpriv->ao_timer < 1)
-		err |= -EINVAL;
-
 	if (cmd->stop_src == TRIG_COUNT) {
 		/* not continuous, use counter */
-		if (high_speed) {
+		if (cmd->convert_src == TRIG_TIMER) {
 			/* high speed also scans everything at once */
 			devpriv->ao_sample_count = cmd->stop_arg *
 						   cmd->scan_end_arg;
@@ -987,24 +998,6 @@ static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
 		devpriv->ao_sample_count = 0;
 	}
 
-	if (err)
-		return 4;
-
-	return 0;
-}
-
-static int usbduxsigma_ao_cmd(struct comedi_device *dev,
-			      struct comedi_subdevice *s)
-{
-	struct usbduxsigma_private *devpriv = dev->private;
-	struct comedi_cmd *cmd = &s->async->cmd;
-	int ret;
-	int i;
-
-	down(&devpriv->sem);
-
-	/* set current channel of the running acquisition to zero */
-	s->async->cur_chan = 0;
 	for (i = 0; i < cmd->chanlist_len; ++i)
 		devpriv->ao_chanlist[i] = CR_CHAN(cmd->chanlist[i]);
 
Signature · 1 line
2.5.2
author
#2 lore raw

PATCH 1/1 ext4: move check under lock scope to close a race.

In reply to Jiri Slaby

From: Davide Italiano <[email protected]>

This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.

===============

commit 280227a75b56ab5d35854f3a77ef74a7ad56a203 upstream

fallocate() checks that the file is extent-based and returns EOPNOTSUPP in case is not. Other tasks can convert from and to indirect and extent so it's safe to check only after grabbing the inode mutex.

[Nikolay Borisov: Bakported to 3.12.47
- Adjusted context
- Add the 'out' label]

---
 fs/ext4/extents.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
fs/ext4/extents.c +11 -6
index c9830686cbd5..a9d23daa0d6f 100644
@@ -4634,12 +4634,6 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	if (ret)
 		return ret;
 
-	/*
-	 * currently supporting (pre)allocate mode for extent-based
-	 * files _only_
-	 */
-	if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
-		return -EOPNOTSUPP;
 
 	trace_ext4_fallocate_enter(inode, offset, len, mode);
 	map.m_lblk = offset >> blkbits;
@@ -4654,6 +4648,16 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	 */
 	credits = ext4_chunk_trans_blocks(inode, max_blocks);
 	mutex_lock(&inode->i_mutex);
+
+	/*
+	 * currently supporting (pre)allocate mode for extent-based
+	 * files _only_
+	 */
+	if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
+		ret = -EOPNOTSUPP;
+		goto out;
+	}
+
 	ret = inode_newsize_ok(inode, (len + offset));
 	if (ret) {
 		mutex_unlock(&inode->i_mutex);
@@ -4714,6 +4718,7 @@ retry:
 		ret = 0;
 		goto retry;
 	}
+out:
 	mutex_unlock(&inode->i_mutex);
 	trace_ext4_fallocate_exit(inode, offset, max_blocks,
 				ret > 0 ? ret2 : ret);
Signature · 1 line
2.5.2
author
#3 lore raw

PATCH 1/1 staging: comedi: adl_pci7x3x: fix digital output on PCI-7230

In reply to Jiri Slaby

From: Ian Abbott <[email protected]>

This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.

===============

commit ad83dbd974feb2e2a8cc071a1d28782bd4d2c70e upstream

The "adl_pci7x3x" driver replaced the "adl_pci7230" and "adl_pci7432" drivers in commits 8f567c373c4b ("staging: comedi: new adl_pci7x3x driver") and 657f77d173d3 ("staging: comedi: remove adl_pci7230 and adl_pci7432 drivers"). Although the new driver code agrees with the user manuals for the respective boards, digital outputs stopped working on the PCI-7230. This has 16 digital output channels and the previous adl_pci7230 driver shifted the 16 bit output state left by 16 bits before writing to the hardware register. The new adl_pci7x3x driver doesn't do that. Fix it in adl_pci7x3x_do_insn_bits() by checking for the special case of the subdevice having only 16 channels and duplicating the 16 bit output state into both halves of the 32-bit register. That should work both for what the board actually does and for what the user manual says it should do.

Fixes 8f567c373c4b ("staging: comedi: new adl_pci7x3x driver")
---
 drivers/staging/comedi/drivers/adl_pci7x3x.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/staging/comedi/drivers/adl_pci7x3x.c +13 -2
index 81b7203f824f..c570ede07e94 100644
@@ -116,10 +116,21 @@ static int adl_pci7x3x_do_insn_bits(struct comedi_device *dev,
 	unsigned int bits = data[1];
 
 	if (mask) {
+		unsigned int val;
+
 		s->state &= ~mask;
 		s->state |= (bits & mask);
-
-		outl(s->state, dev->iobase + reg);
+		val = s->state;
+		if (s->n_chan == 16) {
+			/*
+			 * It seems the PCI-7230 needs the 16-bit DO state
+			 * to be shifted left by 16 bits before being written
+			 * to the 32-bit register.  Set the value in both
+			 * halves of the register to be sure.
+			 */
+			val |= val << 16;
+		}
+		outl(val, dev->iobase + reg);
 	}
 
 	/*
Signature · 1 line
2.5.2
#4 lore raw
In reply to Jiri Slaby
Quoted 5 lines · Jiri Slaby

From: Ian Abbott <[email protected]>

This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.

Please note that this commit (and the next one) were tagged for kernels >= 3.19.

Cheers,
--
Lu�s

Quoted 114 lines

===============

commit 423b24c37dd5794a674c74b0ed56392003a69891 upstream

devpriv->ai_timer is used while an asynchronous command is running on the AI subdevice. It also gets modified by the subdevice's cmdtest handler for checking new asynchronous commands (usbduxsigma_ai_cmdtest()), which is not correct as it's allowed to check new commands while an old command is still running. Fix it by moving the code which sets up devpriv->ai_timer and devpriv->ai_interval into the subdevice's cmd handler, usbduxsigma_ai_cmd().

** This backported patch also moves the code that sets up devpriv->ai_sample_count and devpriv->ai_continuous from usbduxsigma_ai_cmdtest() to usbduxsigma_ai_cmd() for the same reason as above. (This was not needed in the upstream commit.) **

Note that the removed code in usbduxsigma_ai_cmdtest() checked that devpriv->ai_timer did not end up less than than 1, but that could not happen because cmd->scan_begin_arg had already been checked to be at least the minimum required value (at least when cmd->scan_begin_src == TRIG_TIMER, which had also been checked to be the case).

Fixes b986be8527c7 ("staging: comedi: usbduxsigma: tidy up analog input command support)
---
 drivers/staging/comedi/drivers/usbduxsigma.c | 58 +++++++++++++---------------
 1 file changed, 27 insertions(+), 31 deletions(-)
drivers/staging/comedi/drivers/usbduxsigma.c +27 -31
index c47f4087568f..c61a1b9d7cd8 100644
@@ -575,37 +575,6 @@ static int usbduxsigma_ai_cmdtest(struct comedi_device *dev,
 	if (err)
 		return 3;
 
-	/* Step 4: fix up any arguments */
-
-	if (high_speed) {
-		/*
-		 * every 2 channels get a time window of 125us. Thus, if we
-		 * sample all 16 channels we need 1ms. If we sample only one
-		 * channel we need only 125us
-		 */
-		devpriv->ai_interval = interval;
-		devpriv->ai_timer = cmd->scan_begin_arg / (125000 * interval);
-	} else {
-		/* interval always 1ms */
-		devpriv->ai_interval = 1;
-		devpriv->ai_timer = cmd->scan_begin_arg / 1000000;
-	}
-	if (devpriv->ai_timer < 1)
-		err |= -EINVAL;
-
-	if (cmd->stop_src == TRIG_COUNT) {
-		/* data arrives as one packet */
-		devpriv->ai_sample_count = cmd->stop_arg;
-		devpriv->ai_continuous = 0;
-	} else {
-		/* continuous acquisition */
-		devpriv->ai_continuous = 1;
-		devpriv->ai_sample_count = 0;
-	}
-
-	if (err)
-		return 4;
-
 	return 0;
 }
 
@@ -704,6 +673,33 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev,
 
 	/* set current channel of the running acquisition to zero */
 	s->async->cur_chan = 0;
+
+	if (devpriv->high_speed) {
+		/*
+		 * every 2 channels get a time window of 125us. Thus, if we
+		 * sample all 16 channels we need 1ms. If we sample only one
+		 * channel we need only 125us
+		 */
+		unsigned int interval = usbduxsigma_chans_to_interval(len);
+
+		devpriv->ai_interval = interval;
+		devpriv->ai_timer = cmd->scan_begin_arg / (125000 * interval);
+	} else {
+		/* interval always 1ms */
+		devpriv->ai_interval = 1;
+		devpriv->ai_timer = cmd->scan_begin_arg / 1000000;
+	}
+
+	if (cmd->stop_src == TRIG_COUNT) {
+		/* data arrives as one packet */
+		devpriv->ai_sample_count = cmd->stop_arg;
+		devpriv->ai_continuous = 0;
+	} else {
+		/* continuous acquisition */
+		devpriv->ai_continuous = 1;
+		devpriv->ai_sample_count = 0;
+	}
+
 	for (i = 0; i < len; i++) {
 		unsigned int chan  = CR_CHAN(cmd->chanlist[i]);
 
Signature · 6 lines
2.5.2

--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#5 lore raw
Quoted 9 lines · Luis Henriques
Quoted 5 lines · Jiri Slaby

From: Ian Abbott <[email protected]>

This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.

Please note that this commit (and the next one) were tagged for kernels >= 3.19.

What are you referring to?

Given:
http://www.spinics.net/lists/stable/msg103455.html
and:

Quoted 1 line
Quoted 1 line
Fixes b986be8527c7 ("staging: comedi: usbduxsigma: tidy up analog input command support)

I doubt so?

Quoted 2 lines
Quoted 2 lines

thanks,

Signature · 2 lines
js
suse labs
#6 lore raw
Quoted 13 lines · Jiri Slaby
Quoted 9 lines · Luis Henriques
Quoted 5 lines · Jiri Slaby

From: Ian Abbott <[email protected]>

This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.

Please note that this commit (and the next one) were tagged for kernels >= 3.19.

What are you referring to?

Quoted 8 lines

Given:
http://www.spinics.net/lists/stable/msg103455.html
and:

Quoted 1 line
Quoted 1 line
Fixes b986be8527c7 ("staging: comedi: usbduxsigma: tidy up analog input command support)

I doubt so?

Right, I did saw the 'Fixes:' tag (and confirmed that commit was in 3.12). What I was referring to was to the fact that the original commit contained:

Cc <[email protected]> # 3.19 onwards

But I didn't saw Ian's request in the stable mailing-list yet (actually, I've a huge backlog regarding mailing-lists...). So, I guess that what was wrong was the stable tag. Sorry for the noise...

Cheers,
--
Lu�s

Quoted 11 lines
Quoted 2 lines
Quoted 2 lines

thanks,

Signature · 6 lines
js
suse labs
--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#7 lore raw
Quoted 27 lines · Luis Henriques
Quoted 13 lines · Jiri Slaby
Quoted 9 lines · Luis Henriques
Quoted 5 lines · Jiri Slaby

From: Ian Abbott <[email protected]>

This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.

Please note that this commit (and the next one) were tagged for kernels >= 3.19.

What are you referring to?

Quoted 8 lines

Given:
http://www.spinics.net/lists/stable/msg103455.html
and:

Quoted 1 line
Quoted 1 line
Fixes b986be8527c7 ("staging: comedi: usbduxsigma: tidy up analog input command support)

I doubt so?

Right, I did saw the 'Fixes:' tag (and confirmed that commit was in 3.12). What I was referring to was to the fact that the original commit contained:

Quoted 5 lines
Cc <[email protected]> # 3.19 onwards

But I didn't saw Ian's request in the stable mailing-list yet (actually, I've a huge backlog regarding mailing-lists...). So, I guess that what was wrong was the stable tag. Sorry for the noise...

I see, thanks for the heads-up anyway.

Signature · 2 lines
js
suse labs
#8 lore raw
In reply to Luis Henriques
Quoted 27 lines · Luis Henriques
Quoted 13 lines · Jiri Slaby
Quoted 9 lines · Luis Henriques
Quoted 5 lines · Jiri Slaby

From: Ian Abbott <[email protected]>

This patch has been added to the 3.12 stable tree. If you have any objections, please let us know.

Please note that this commit (and the next one) were tagged for kernels >= 3.19.

What are you referring to?

Quoted 8 lines

Given:
http://www.spinics.net/lists/stable/msg103455.html
and:

Quoted 1 line
Quoted 1 line
Fixes b986be8527c7 ("staging: comedi: usbduxsigma: tidy up analog input command support)

I doubt so?

Right, I did saw the 'Fixes:' tag (and confirmed that commit was in 3.12). What I was referring to was to the fact that the original commit contained:

Quoted 5 lines
   Cc: <[email protected]> # 3.19 onwards

But I didn't saw Ian's request in the stable mailing-list yet (actually, I've a huge backlog regarding mailing-lists...). So, I guess that what was wrong was the stable tag. Sorry for the noise...

I tagged it as 3.19 onwards because it wouldn't apply as-is to earlier kernels. I probably should have mentioned in the original upstream patch that it could be back-ported down to 3.12.

Signature · 2 lines
-=( Ian Abbott @ MEV Ltd.    E-mail: <[email protected]> )=-
-=(                          Web: http://www.mev.co.uk/  )=-