staging: comedi: dt2811: fix a precedence bug
Subsystems (2)
PATCH 1/1 staging: comedi: dt2811: fix a precedence bug
Bitwise | has higher precedence than ?: so we need to add some parenthesis for this to work as intended.
drivers/staging/comedi/drivers/dt2811.c +2 -2
@@ -588,8 +588,8 @@ static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it) s = &dev->subdevices[0 ]; s->type =COMEDI_SUBD_AI ; s->subdev_flags =SDF_READABLE | - (it->options[2 ] =1 ) ?SDF_DIFF : - (it->options[2 ] =2 ) ?SDF_COMMON :SDF_GROUND ; + ((it->options[2 ] =1 ) ?SDF_DIFF : + (it->options[2 ] =2 ) ?SDF_COMMON :SDF_GROUND ); s->n_chan = (it->options[2 ] =1 ) ?8 :16 ; s->maxdata =0x0fff ; s->range_table = board->is_pgh ? &dt2811_pgh_ai_ranges
Quoted 12 lines · Dan Carpenter
Bitwise | has higher precedence than ?: so we need to add some parenthesis for this to work as intended.
Fixes 7c9574090d30 ('staging: comedi: dt2811: simplify A/D reference configuration')Signed-off-by Dan Carpenter <[email protected]>drivers/staging/comedi/drivers/dt2811.c +0
-0
drivers/staging/comedi/drivers/dt2811.c static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it) · line 595
Quoted 10 lines
drivers/staging/comedi/drivers/dt2811.c +2
-2@@ -588,8 +588,8 @@ static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it) s = &dev->subdevices[0 ]; s->type =COMEDI_SUBD_AI ; s->subdev_flags =SDF_READABLE | - (it->options[2 ] =1 ) ?SDF_DIFF : - (it->options[2 ] =2 ) ?SDF_COMMON :SDF_GROUND ; + ((it->options[2 ] =1 ) ?SDF_DIFF : + (it->options[2 ] =2 ) ?SDF_COMMON :SDF_GROUND ); s->n_chan = (it->options[2 ] =1 ) ?8 :16 ; s->maxdata =0x0fff ; s->range_table = board->is_pgh ? &dt2811_pgh_ai_ranges
Nice catch, thanks!
Signature · 2 lines
-=( Ian Abbott @ MEV Ltd. E-mail: <[email protected]> )=- -=( Web: http://www.mev.co.uk/ )=-
Am 21.06.2016 15:56, schrieb Ian Abbott:
Quoted 18 lines · Dan Carpenter
Quoted 17 lines
Bitwise | has higher precedence than ?: so we need to add some parenthesis for this to work as intended.
Fixes 7c9574090d30 ('staging: comedi: dt2811: simplify A/D referenceconfiguration')
Signed-off-by Dan Carpenter <[email protected]>drivers/staging/comedi/drivers/dt2811.c +0
-0@@ -588,8 +588,8 @@ static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it) s = &dev->subdevices[0 ]; s->type =COMEDI_SUBD_AI ; s->subdev_flags = SDF_READABLE |
Quoted 9 lines
Quoted 8 lines
drivers/staging/comedi/drivers/dt2811.c +2
-2- (it->options[2 ] =1 ) ?SDF_DIFF : - (it->options[2 ] =2 ) ?SDF_COMMON :SDF_GROUND ; + ((it->options[2 ] =1 ) ?SDF_DIFF : + (it->options[2 ] =2 ) ?SDF_COMMON :SDF_GROUND ); s->n_chan = (it->options[2 ] =1 ) ?8 :16 ; s->maxdata =0x0fff ;s->range_table = board->is_pgh ? &dt2811_pgh_ai_ranges
perhaps we can improve readability with something like that (untested):
switch(it->options[2]) {
case 1:
s->subdev_flags= SDF_READABLE|SDF_DIFF;
break;
case 2:
s->subdev_flags= SDF_READABLE|SDF_COMMON;
break;
default:
s->subdev_flags=SDF_READABLE|SDF_GROUND;
}so everyone has a chance to see what is going on.
just my 2 cents,
re,
wh
Quoted 4 lines
Nice catch, thanks!
Reviewed-by Ian Abbott <[email protected]>