Skip to contentSkip to conversation

staging: comedi: cb_das16_cs: cleanup das16cs_ai_rinsn()

PATCH In review H Hartley Sweeten 2 participants 4 messages Jun 26, 2012 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 28/33 staging: comedi: cb_das16_cs: cleanup das16cs_ai_rinsn()

Cleanup to analog input read function.

1) Initialize the chan, range, and aref locale variables when they are declared.
2) Remove need for the static local variable.
3) Remove the unnecessary cast of inw()'s return value.

Cc Ian Abbott <[email protected]>
Cc Frank Mori Hess <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/staging/comedi/drivers/cb_das16_cs.c | 30 ++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
drivers/staging/comedi/drivers/cb_das16_cs.c +20 -10
index 11dc9b1..80e3540 100644
@@ -111,16 +111,11 @@ static int das16cs_ai_rinsn(struct comedi_device *dev,
 			    struct comedi_insn *insn, unsigned int *data)
 {
 	struct das16cs_private *devpriv = dev->private;
+	int chan = CR_CHAN(insn->chanspec);
+	int range = CR_RANGE(insn->chanspec);
+	int aref = CR_AREF(insn->chanspec);
 	int i;
 	int to;
-	int aref;
-	int range;
-	int chan;
-	static int range_bits[] = { 0x800, 0x000, 0x100, 0x200 };
-
-	chan = CR_CHAN(insn->chanspec);
-	aref = CR_AREF(insn->chanspec);
-	range = CR_RANGE(insn->chanspec);
 
 	outw(chan, dev->iobase + 2);
 
@@ -129,7 +124,22 @@ static int das16cs_ai_rinsn(struct comedi_device *dev,
 	outw(devpriv->status1, dev->iobase + 4);
 
 	devpriv->status2 &= ~0xff00;
-	devpriv->status2 |= range_bits[range];
+	switch (range) {
+	case 0:
+		devpriv->status2 |= 0x800;
+		break;
+	case 1:
+		devpriv->status2 |= 0x000;
+		break;
+	case 2:
+		devpriv->status2 |= 0x100;
+		break;
+	case 3:
+		devpriv->status2 |= 0x200;
+		break;
+	default:
+		return -EINVAL;
+	}
 	outw(devpriv->status2, dev->iobase + 6);
 
 	for (i = 0; i < insn->n; i++) {
@@ -144,7 +154,7 @@ static int das16cs_ai_rinsn(struct comedi_device *dev,
 			dev_dbg(dev->class_dev, "cb_das16_cs: ai timeout\n");
 			return -ETIME;
 		}
-		data[i] = (unsigned short)inw(dev->iobase + 0);
+		data[i] = inw(dev->iobase + 0);
 	}
 
 	return i;
Signature · 1 line
1.7.11
#1 lore raw
Quoted 11 lines · H Hartley Sweeten
drivers/staging/comedi/drivers/cb_das16_cs.c +6 -1
@@ -129,7 +124,22 @@ static int das16cs_ai_rinsn(struct comedi_device *dev,
  	outw(devpriv->status1, dev->iobase + 4);
 
  	devpriv->status2 &= ~0xff00;
-	devpriv->status2 |= range_bits[range];
+	switch (range) {
+	case 0:
+		devpriv->status2 |= 0x800;
+		break;
+	case 1:
+		devpriv->status2 |= 0x000;

drivers/staging/comedi/drivers/cb_das16_cs.c static int das16cs_ai_rinsn(struct comedi_device *dev, · line 142

Quoted 10 lines
drivers/staging/comedi/drivers/cb_das16_cs.c +10 -0
+		break;
+	case 2:
+		devpriv->status2 |= 0x100;
+		break;
+	case 3:
+		devpriv->status2 |= 0x200;
+		break;
+	default:
+		return -EINVAL;
+	}

Is that really an improvement? The 'range' variable value will be in range anyway (the comedi core checks beforehand in comedi_check_chanlist()), and looking up the constant to OR with devpriv->status2 is probably less object code (and certainly less source code).

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
Quoted 20 lines · Ian Abbott
Quoted 19 lines · H Hartley Sweeten
drivers/staging/comedi/drivers/cb_das16_cs.c +14 -1
@@ -129,7 +124,22 @@ static int das16cs_ai_rinsn(struct comedi_device *dev,
   	outw(devpriv->status1, dev->iobase + 4);
 
   	devpriv->status2 &= ~0xff00;
-	devpriv->status2 |= range_bits[range];
+	switch (range) {
+	case 0:
+		devpriv->status2 |= 0x800;
+		break;
+	case 1:
+		devpriv->status2 |= 0x000;
+		break;
+	case 2:
+		devpriv->status2 |= 0x100;
+		break;
+	case 3:
+		devpriv->status2 |= 0x200;
+		break;
+	default:
Quoted 8 lines

drivers/staging/comedi/drivers/cb_das16_cs.c static int das16cs_ai_rinsn(struct comedi_device *dev, · line 142

Quoted 2 lines
drivers/staging/comedi/drivers/cb_das16_cs.c +2 -0
+		return -EINVAL;
+	}

Is that really an improvement? The 'range' variable value will be in range anyway (the comedi core checks beforehand in comedi_check_chanlist()), and looking up the constant to OR with devpriv->status2 is probably less object code (and certainly less source code).

I meant looking up the constant in the static array of course. It doesn't really matter if you want to do it this way though, and the static int range_bits[] you removed should have been static const int range_bits[] anyway.

Signature · 2 lines
-=( Ian Abbott @ MEV Ltd.    E-mail: <[email protected]>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
#3 lore raw
Quoted 30 lines · Ian Abbott
Quoted 20 lines · Ian Abbott
Quoted 19 lines · H Hartley Sweeten
drivers/staging/comedi/drivers/cb_das16_cs.c +14 -1
@@ -129,7 +124,22 @@ static int das16cs_ai_rinsn(struct comedi_device *dev,
   	outw(devpriv->status1, dev->iobase + 4);
 
   	devpriv->status2 &= ~0xff00;
-	devpriv->status2 |= range_bits[range];
+	switch (range) {
+	case 0:
+		devpriv->status2 |= 0x800;
+		break;
+	case 1:
+		devpriv->status2 |= 0x000;
+		break;
+	case 2:
+		devpriv->status2 |= 0x100;
+		break;
+	case 3:
+		devpriv->status2 |= 0x200;
+		break;
+	default:
Quoted 8 lines

drivers/staging/comedi/drivers/cb_das16_cs.c static int das16cs_ai_rinsn(struct comedi_device *dev, · line 142

Quoted 2 lines
drivers/staging/comedi/drivers/cb_das16_cs.c +2 -0
+		return -EINVAL;
+	}

Is that really an improvement? The 'range' variable value will be in range anyway (the comedi core checks beforehand in comedi_check_chanlist()), and looking up the constant to OR with devpriv->status2 is probably less object code (and certainly less source code).

Quoted 4 lines

I meant looking up the constant in the static array of course. It doesn't really matter if you want to do it this way though, and the static int range_bits[] you removed should have been static const int range_bits[] anyway.

This, and your other comment about the PCMCIA support, have been addressed.

Thanks for the review!

Regards,
Hartley

���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�