Skip to contentSkip to conversation

staging: comedi: comedi_bond: silence a shift wrapping warning

PATCH In review Dan Carpenter 2 participants 6 messages Aug 21, 2013 – Aug 22, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: comedi: comedi_bond: silence a shift wrapping warning

We set this using:

	devs_closed |= (0x1 << bdev->minor)

Since 0x1 is an int then only the lower 32 bits are usable before we hit a shift wrapping bug. There are some static checkers which complain about this. I've silenced the warning by making devs_closed a 32 bit number.

32 bits should be enough for anybody.

drivers/staging/comedi/drivers/comedi_bond.c +1 -1
index 7e20bf0..8f6c942 100644
@@ -335,7 +335,7 @@ static int bonding_attach(struct comedi_device *dev,
 static void bonding_detach(struct comedi_device *dev)
 {
 	struct comedi_bond_private *devpriv = dev->private;
-	unsigned long devs_closed = 0;
+	unsigned int devs_closed = 0;
 
 	if (devpriv) {
 		while (devpriv->ndevs-- && devpriv->devs) {
#1 lore raw
Quoted 10 lines · Dan Carpenter

We set this using:

	devs_closed |= (0x1 << bdev->minor)

Since 0x1 is an int then only the lower 32 bits are usable before we hit a shift wrapping bug. There are some static checkers which complain about this. I've silenced the warning by making devs_closed a 32 bit number.

32 bits should be enough for anybody.

Not really, as bdev->minor will be in the range 0 to 47 inclusive (0 to COMEDI_NUM_BOARD_MINORS-1). Of course, an unsigned long is insufficient too on a 32-bit system.

Quoted 17 lines
drivers/staging/comedi/drivers/comedi_bond.c +1 -1
index 7e20bf0..8f6c942 100644
@@ -335,7 +335,7 @@ static int bonding_attach(struct comedi_device *dev,
  static void bonding_detach(struct comedi_device *dev)
  {
  	struct comedi_bond_private *devpriv = dev->private;
-	unsigned long devs_closed = 0;
+	unsigned int devs_closed = 0;
 
  	if (devpriv) {
  		while (devpriv->ndevs-- && devpriv->devs) {
Signature · 2 lines
-=( Ian Abbott @ MEV Ltd.    E-mail: <[email protected]>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
#2 lore raw
In reply to Dan Carpenter
Quoted 10 lines · Ian Abbott
Quoted 9 lines · Dan Carpenter

We set this using:

	devs_closed |= (0x1 << bdev->minor)

Since 0x1 is an int then only the lower 32 bits are usable before we hit a shift wrapping bug. There are some static checkers which complain about this. I've silenced the warning by making devs_closed a 32 bit number.

Quoted 5 lines
Quoted 1 line

32 bits should be enough for anybody.

Not really, as bdev->minor will be in the range 0 to 47 inclusive (0 to COMEDI_NUM_BOARD_MINORS-1). Of course, an unsigned long is insufficient too on a 32-bit system.

Ok. I'll make it a u64 in a v2 patch.

regards,
dan carpenter

#3 lore raw
In reply to Dan Carpenter
Quoted 11 lines · Dan Carpenter
Quoted 10 lines · Ian Abbott
Quoted 9 lines · Dan Carpenter

We set this using:

	devs_closed |= (0x1 << bdev->minor)

Since 0x1 is an int then only the lower 32 bits are usable before we hit a shift wrapping bug. There are some static checkers which complain about this. I've silenced the warning by making devs_closed a 32 bit number.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

32 bits should be enough for anybody.

Not really, as bdev->minor will be in the range 0 to 47 inclusive (0 to COMEDI_NUM_BOARD_MINORS-1). Of course, an unsigned long is insufficient too on a 32-bit system.

Ok. I'll make it a u64 in a v2 patch.

If you want, we could drop that, and I could rework it to use DECLARE_BITMAP() and the functions in <linux/bitmap.h> to avoid assuming COMEDI_NUM_BOARD_MINORS is <= 64. The devs_opened[] in doDevConfig() could also be replaced by a bitmap (it's currently an array of pointers!).

Signature · 2 lines
-=( Ian Abbott @ MEV Ltd.    E-mail: <[email protected]>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
#4 lore raw
In reply to Dan Carpenter
Quoted 18 lines · Ian Abbott
Quoted 17 lines · Dan Carpenter
Quoted 15 lines · Ian Abbott
Quoted 10 lines · Dan Carpenter

We set this using:

	devs_closed |= (0x1 << bdev->minor)

Since 0x1 is an int then only the lower 32 bits are usable before we hit a shift wrapping bug. There are some static checkers which complain about this. I've silenced the warning by making devs_closed a 32 bit number.

32 bits should be enough for anybody.

Not really, as bdev->minor will be in the range 0 to 47 inclusive (0 to COMEDI_NUM_BOARD_MINORS-1). Of course, an unsigned long is insufficient too on a 32-bit system.

Quoted 8 lines
Quoted 1 line

Ok. I'll make it a u64 in a v2 patch.

If you want, we could drop that, and I could rework it to use DECLARE_BITMAP() and the functions in <linux/bitmap.h> to avoid assuming COMEDI_NUM_BOARD_MINORS is <= 64. The devs_opened[] in doDevConfig() could also be replaced by a bitmap (it's currently an array of pointers!).

Sure. Let's drop it then.

regards,
dan carpenter

#5 lore raw
In reply to Dan Carpenter
Quoted 21 lines · Dan Carpenter
Quoted 20 lines · Ian Abbott
Quoted 18 lines · Dan Carpenter
Quoted 10 lines · Ian Abbott
Quoted 9 lines · Dan Carpenter

We set this using:

	devs_closed |= (0x1 << bdev->minor)

Since 0x1 is an int then only the lower 32 bits are usable before we hit a shift wrapping bug. There are some static checkers which complain about this. I've silenced the warning by making devs_closed a 32 bit number.

Quoted 5 lines
Quoted 1 line

32 bits should be enough for anybody.

Not really, as bdev->minor will be in the range 0 to 47 inclusive (0 to COMEDI_NUM_BOARD_MINORS-1). Of course, an unsigned long is insufficient too on a 32-bit system.

Ok. I'll make it a u64 in a v2 patch.

Quoted 8 lines
Quoted 6 lines

If you want, we could drop that, and I could rework it to use DECLARE_BITMAP() and the functions in <linux/bitmap.h> to avoid assuming COMEDI_NUM_BOARD_MINORS is <= 64. The devs_opened[] in doDevConfig() could also be replaced by a bitmap (it's currently an array of pointers!).

Sure. Let's drop it then.

Okay, let's drop it. I have a series of 13 patches to apply to this driver to tidy it up a bit and fix various bugs. I'll send them tomorrow after a bit of testing.

Signature · 2 lines
-=( Ian Abbott @ MEV Ltd.    E-mail: <[email protected]>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-