public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 5.10.y] comedi: Fix some signed shift left operations
  2025-07-24 18:12 [PATCH 5.10.y] comedi: Fail COMEDI_INSNLIST ioctl if n_insns is too large Ian Abbott
@ 2025-07-24 18:12 ` Ian Abbott
  2025-07-25 23:24   ` Sasha Levin
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Abbott @ 2025-07-24 18:12 UTC (permalink / raw)
  To: stable; +Cc: Ian Abbott, Greg Kroah-Hartman

[ Upstream commit ab705c8c35e18652abc6239c07cf3441f03e2cda ]

Correct some left shifts of the signed integer constant 1 by some
unsigned number less than 32.  Change the constant to 1U to avoid
shifting a 1 into the sign bit.

The corrected functions are comedi_dio_insn_config(),
comedi_dio_update_state(), and __comedi_device_postconfig().

Fixes: e523c6c86232 ("staging: comedi: drivers: introduce comedi_dio_insn_config()")
Fixes: 05e60b13a36b ("staging: comedi: drivers: introduce comedi_dio_update_state()")
Fixes: 09567cb4373e ("staging: comedi: initialize subdevice s->io_bits in postconfig")
Cc: stable@vger.kernel.org # 5.13+
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Link: https://lore.kernel.org/r/20250707121555.65424-1-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/staging/comedi/drivers.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 750a6ff3c03c..6bb7b8a1e75d 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -339,10 +339,10 @@ int comedi_dio_insn_config(struct comedi_device *dev,
 			   unsigned int *data,
 			   unsigned int mask)
 {
-	unsigned int chan_mask = 1 << CR_CHAN(insn->chanspec);
+	unsigned int chan = CR_CHAN(insn->chanspec);
 
-	if (!mask)
-		mask = chan_mask;
+	if (!mask && chan < 32)
+		mask = 1U << chan;
 
 	switch (data[0]) {
 	case INSN_CONFIG_DIO_INPUT:
@@ -382,7 +382,7 @@ EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
 unsigned int comedi_dio_update_state(struct comedi_subdevice *s,
 				     unsigned int *data)
 {
-	unsigned int chanmask = (s->n_chan < 32) ? ((1 << s->n_chan) - 1)
+	unsigned int chanmask = (s->n_chan < 32) ? ((1U << s->n_chan) - 1)
 						 : 0xffffffff;
 	unsigned int mask = data[0] & chanmask;
 	unsigned int bits = data[1];
@@ -625,8 +625,8 @@ static int insn_rw_emulate_bits(struct comedi_device *dev,
 	if (insn->insn == INSN_WRITE) {
 		if (!(s->subdev_flags & SDF_WRITABLE))
 			return -EINVAL;
-		_data[0] = 1 << (chan - base_chan);		    /* mask */
-		_data[1] = data[0] ? (1 << (chan - base_chan)) : 0; /* bits */
+		_data[0] = 1U << (chan - base_chan);		     /* mask */
+		_data[1] = data[0] ? (1U << (chan - base_chan)) : 0; /* bits */
 	}
 
 	ret = s->insn_bits(dev, s, &_insn, _data);
@@ -709,7 +709,7 @@ static int __comedi_device_postconfig(struct comedi_device *dev)
 
 		if (s->type == COMEDI_SUBD_DO) {
 			if (s->n_chan < 32)
-				s->io_bits = (1 << s->n_chan) - 1;
+				s->io_bits = (1U << s->n_chan) - 1;
 			else
 				s->io_bits = 0xffffffff;
 		}
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 5.10.y] comedi: Fix some signed shift left operations
@ 2025-07-24 18:16 Ian Abbott
  2025-07-26  0:24 ` Sasha Levin
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Abbott @ 2025-07-24 18:16 UTC (permalink / raw)
  To: stable; +Cc: Ian Abbott, Greg Kroah-Hartman

[ Upstream commit ab705c8c35e18652abc6239c07cf3441f03e2cda ]

Correct some left shifts of the signed integer constant 1 by some
unsigned number less than 32.  Change the constant to 1U to avoid
shifting a 1 into the sign bit.

The corrected functions are comedi_dio_insn_config(),
comedi_dio_update_state(), and __comedi_device_postconfig().

Fixes: e523c6c86232 ("staging: comedi: drivers: introduce comedi_dio_insn_config()")
Fixes: 05e60b13a36b ("staging: comedi: drivers: introduce comedi_dio_update_state()")
Fixes: 09567cb4373e ("staging: comedi: initialize subdevice s->io_bits in postconfig")
Cc: stable@vger.kernel.org # 5.13+
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Link: https://lore.kernel.org/r/20250707121555.65424-1-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/staging/comedi/drivers.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 750a6ff3c03c..6bb7b8a1e75d 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -339,10 +339,10 @@ int comedi_dio_insn_config(struct comedi_device *dev,
 			   unsigned int *data,
 			   unsigned int mask)
 {
-	unsigned int chan_mask = 1 << CR_CHAN(insn->chanspec);
+	unsigned int chan = CR_CHAN(insn->chanspec);
 
-	if (!mask)
-		mask = chan_mask;
+	if (!mask && chan < 32)
+		mask = 1U << chan;
 
 	switch (data[0]) {
 	case INSN_CONFIG_DIO_INPUT:
@@ -382,7 +382,7 @@ EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
 unsigned int comedi_dio_update_state(struct comedi_subdevice *s,
 				     unsigned int *data)
 {
-	unsigned int chanmask = (s->n_chan < 32) ? ((1 << s->n_chan) - 1)
+	unsigned int chanmask = (s->n_chan < 32) ? ((1U << s->n_chan) - 1)
 						 : 0xffffffff;
 	unsigned int mask = data[0] & chanmask;
 	unsigned int bits = data[1];
@@ -625,8 +625,8 @@ static int insn_rw_emulate_bits(struct comedi_device *dev,
 	if (insn->insn == INSN_WRITE) {
 		if (!(s->subdev_flags & SDF_WRITABLE))
 			return -EINVAL;
-		_data[0] = 1 << (chan - base_chan);		    /* mask */
-		_data[1] = data[0] ? (1 << (chan - base_chan)) : 0; /* bits */
+		_data[0] = 1U << (chan - base_chan);		     /* mask */
+		_data[1] = data[0] ? (1U << (chan - base_chan)) : 0; /* bits */
 	}
 
 	ret = s->insn_bits(dev, s, &_insn, _data);
@@ -709,7 +709,7 @@ static int __comedi_device_postconfig(struct comedi_device *dev)
 
 		if (s->type == COMEDI_SUBD_DO) {
 			if (s->n_chan < 32)
-				s->io_bits = (1 << s->n_chan) - 1;
+				s->io_bits = (1U << s->n_chan) - 1;
 			else
 				s->io_bits = 0xffffffff;
 		}
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.10.y] comedi: Fix some signed shift left operations
  2025-07-24 18:12 ` [PATCH 5.10.y] comedi: Fix some signed shift left operations Ian Abbott
@ 2025-07-25 23:24   ` Sasha Levin
  0 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2025-07-25 23:24 UTC (permalink / raw)
  To: stable; +Cc: Sasha Levin

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected.
No action required from the submitter.

The upstream commit SHA1 provided is correct: ab705c8c35e18652abc6239c07cf3441f03e2cda

Status in newer kernel trees:
6.15.y | Not found
6.12.y | Not found
6.6.y | Not found
6.1.y | Not found
5.15.y | Not found

Note: The patch differs from the upstream commit:
---
1:  ab705c8c35e1 ! 1:  e5ccdaa83664 comedi: Fix some signed shift left operations
    @@ Metadata
      ## Commit message ##
         comedi: Fix some signed shift left operations
     
    +    [ Upstream commit ab705c8c35e18652abc6239c07cf3441f03e2cda ]
    +
         Correct some left shifts of the signed integer constant 1 by some
         unsigned number less than 32.  Change the constant to 1U to avoid
         shifting a 1 into the sign bit.
    @@ Commit message
         Link: https://lore.kernel.org/r/20250707121555.65424-1-abbotti@mev.co.uk
         Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
     
    - ## drivers/comedi/drivers.c ##
    -@@ drivers/comedi/drivers.c: int comedi_dio_insn_config(struct comedi_device *dev,
    + ## drivers/staging/comedi/drivers.c ##
    +@@ drivers/staging/comedi/drivers.c: int comedi_dio_insn_config(struct comedi_device *dev,
      			   unsigned int *data,
      			   unsigned int mask)
      {
    @@ drivers/comedi/drivers.c: int comedi_dio_insn_config(struct comedi_device *dev,
      
      	switch (data[0]) {
      	case INSN_CONFIG_DIO_INPUT:
    -@@ drivers/comedi/drivers.c: EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
    +@@ drivers/staging/comedi/drivers.c: EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
      unsigned int comedi_dio_update_state(struct comedi_subdevice *s,
      				     unsigned int *data)
      {
    @@ drivers/comedi/drivers.c: EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
      						 : 0xffffffff;
      	unsigned int mask = data[0] & chanmask;
      	unsigned int bits = data[1];
    -@@ drivers/comedi/drivers.c: static int insn_rw_emulate_bits(struct comedi_device *dev,
    +@@ drivers/staging/comedi/drivers.c: static int insn_rw_emulate_bits(struct comedi_device *dev,
      	if (insn->insn == INSN_WRITE) {
      		if (!(s->subdev_flags & SDF_WRITABLE))
      			return -EINVAL;
    @@ drivers/comedi/drivers.c: static int insn_rw_emulate_bits(struct comedi_device *
      	}
      
      	ret = s->insn_bits(dev, s, &_insn, _data);
    -@@ drivers/comedi/drivers.c: static int __comedi_device_postconfig(struct comedi_device *dev)
    +@@ drivers/staging/comedi/drivers.c: static int __comedi_device_postconfig(struct comedi_device *dev)
      
      		if (s->type == COMEDI_SUBD_DO) {
      			if (s->n_chan < 32)

---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| origin/linux-5.10.y       | Success     | Success    |

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.10.y] comedi: Fix some signed shift left operations
  2025-07-24 18:16 [PATCH 5.10.y] comedi: Fix some signed shift left operations Ian Abbott
@ 2025-07-26  0:24 ` Sasha Levin
  0 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2025-07-26  0:24 UTC (permalink / raw)
  To: stable; +Cc: Sasha Levin

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected.
No action required from the submitter.

The upstream commit SHA1 provided is correct: ab705c8c35e18652abc6239c07cf3441f03e2cda

Status in newer kernel trees:
6.15.y | Not found
6.12.y | Not found
6.6.y | Not found
6.1.y | Not found
5.15.y | Not found

Note: The patch differs from the upstream commit:
---
1:  ab705c8c35e1 ! 1:  0d19deff7ec8 comedi: Fix some signed shift left operations
    @@ Metadata
      ## Commit message ##
         comedi: Fix some signed shift left operations
     
    +    [ Upstream commit ab705c8c35e18652abc6239c07cf3441f03e2cda ]
    +
         Correct some left shifts of the signed integer constant 1 by some
         unsigned number less than 32.  Change the constant to 1U to avoid
         shifting a 1 into the sign bit.
    @@ Commit message
         Link: https://lore.kernel.org/r/20250707121555.65424-1-abbotti@mev.co.uk
         Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
     
    - ## drivers/comedi/drivers.c ##
    -@@ drivers/comedi/drivers.c: int comedi_dio_insn_config(struct comedi_device *dev,
    + ## drivers/staging/comedi/drivers.c ##
    +@@ drivers/staging/comedi/drivers.c: int comedi_dio_insn_config(struct comedi_device *dev,
      			   unsigned int *data,
      			   unsigned int mask)
      {
    @@ drivers/comedi/drivers.c: int comedi_dio_insn_config(struct comedi_device *dev,
      
      	switch (data[0]) {
      	case INSN_CONFIG_DIO_INPUT:
    -@@ drivers/comedi/drivers.c: EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
    +@@ drivers/staging/comedi/drivers.c: EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
      unsigned int comedi_dio_update_state(struct comedi_subdevice *s,
      				     unsigned int *data)
      {
    @@ drivers/comedi/drivers.c: EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
      						 : 0xffffffff;
      	unsigned int mask = data[0] & chanmask;
      	unsigned int bits = data[1];
    -@@ drivers/comedi/drivers.c: static int insn_rw_emulate_bits(struct comedi_device *dev,
    +@@ drivers/staging/comedi/drivers.c: static int insn_rw_emulate_bits(struct comedi_device *dev,
      	if (insn->insn == INSN_WRITE) {
      		if (!(s->subdev_flags & SDF_WRITABLE))
      			return -EINVAL;
    @@ drivers/comedi/drivers.c: static int insn_rw_emulate_bits(struct comedi_device *
      	}
      
      	ret = s->insn_bits(dev, s, &_insn, _data);
    -@@ drivers/comedi/drivers.c: static int __comedi_device_postconfig(struct comedi_device *dev)
    +@@ drivers/staging/comedi/drivers.c: static int __comedi_device_postconfig(struct comedi_device *dev)
      
      		if (s->type == COMEDI_SUBD_DO) {
      			if (s->n_chan < 32)

---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| origin/linux-5.10.y       | Success     | Success    |

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-26  0:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-24 18:16 [PATCH 5.10.y] comedi: Fix some signed shift left operations Ian Abbott
2025-07-26  0:24 ` Sasha Levin
  -- strict thread matches above, loose matches on Subject: below --
2025-07-24 18:12 [PATCH 5.10.y] comedi: Fail COMEDI_INSNLIST ioctl if n_insns is too large Ian Abbott
2025-07-24 18:12 ` [PATCH 5.10.y] comedi: Fix some signed shift left operations Ian Abbott
2025-07-25 23:24   ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox