Browse Source

fw/abcio: correctly handle I/O beyond the end of a buffer

We would DTRT for the first I/O access, but then the counter would
wrap. Don't decrement the counter if it is already zero.
H. Peter Anvin 3 years ago
parent
commit
0d8c8fd6b3
1 changed files with 3 additions and 3 deletions
  1. 3 3
      fw/abcio.c

+ 3 - 3
fw/abcio.c

@@ -57,11 +57,11 @@ IRQHANDLER(abc)
 	    if (!dev)
 		break;
 
-	    if (dev->out_cnt--) {
+	    if (dev->out_cnt) {
 		*dev->out_buf++ = data;
 		dev->inp_data[1] &= dev->status_first_out_mask;
 		ABC_INP1_DATA = dev->inp_data[1];
-		if (dev->out_cnt)
+		if (--dev->out_cnt)
 		    break;	/* No callback, don't set out_data[] */
 	    }
 	    goto handle_out;
@@ -109,7 +109,7 @@ IRQHANDLER(abc)
     }
 
     if (what & 0x100) {
-	if (--dev->inp_cnt) {
+	if (dev->inp_cnt && --dev->inp_cnt) {
 	    dev->inp_data[1] &= dev->status_first_inp_mask;
 	    ABC_INP1_DATA = dev->inp_data[1];
 	    ABC_INP0_DATA = dev->inp_data[0] = *dev->inp_buf++;