Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

comedi: Fix some signed shift left operations

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>

authored by

Ian Abbott and committed by
Greg Kroah-Hartman
ab705c8c 08ae4b20

+7 -7
+7 -7
drivers/comedi/drivers.c
··· 339 339 unsigned int *data, 340 340 unsigned int mask) 341 341 { 342 - unsigned int chan_mask = 1 << CR_CHAN(insn->chanspec); 342 + unsigned int chan = CR_CHAN(insn->chanspec); 343 343 344 - if (!mask) 345 - mask = chan_mask; 344 + if (!mask && chan < 32) 345 + mask = 1U << chan; 346 346 347 347 switch (data[0]) { 348 348 case INSN_CONFIG_DIO_INPUT: ··· 382 382 unsigned int comedi_dio_update_state(struct comedi_subdevice *s, 383 383 unsigned int *data) 384 384 { 385 - unsigned int chanmask = (s->n_chan < 32) ? ((1 << s->n_chan) - 1) 385 + unsigned int chanmask = (s->n_chan < 32) ? ((1U << s->n_chan) - 1) 386 386 : 0xffffffff; 387 387 unsigned int mask = data[0] & chanmask; 388 388 unsigned int bits = data[1]; ··· 625 625 if (insn->insn == INSN_WRITE) { 626 626 if (!(s->subdev_flags & SDF_WRITABLE)) 627 627 return -EINVAL; 628 - _data[0] = 1 << (chan - base_chan); /* mask */ 629 - _data[1] = data[0] ? (1 << (chan - base_chan)) : 0; /* bits */ 628 + _data[0] = 1U << (chan - base_chan); /* mask */ 629 + _data[1] = data[0] ? (1U << (chan - base_chan)) : 0; /* bits */ 630 630 } 631 631 632 632 ret = s->insn_bits(dev, s, &_insn, _data); ··· 709 709 710 710 if (s->type == COMEDI_SUBD_DO) { 711 711 if (s->n_chan < 32) 712 - s->io_bits = (1 << s->n_chan) - 1; 712 + s->io_bits = (1U << s->n_chan) - 1; 713 713 else 714 714 s->io_bits = 0xffffffff; 715 715 }