--- linux/drivers/scsi/libata-core.c 2005-08-01 15:35:17.000000000 +0800 +++ 01_pio_ifcond/drivers/scsi/libata-core.c 2005-08-01 15:52:29.000000000 +0800 @@ -2603,7 +2603,7 @@ unsigned char *buf; unsigned int offset, count; - if (qc->curbytes == qc->nbytes - bytes) + if (qc->curbytes + bytes >= qc->nbytes) ap->pio_task_state = PIO_ST_LAST; next_sg: @@ -2624,11 +2624,10 @@ buf = kmap(page) + offset; - bytes -= count; qc->curbytes += count; qc->cursg_ofs += count; - if (qc->cursg_ofs == sg->length) { + if (qc->cursg_ofs >= sg->length) { qc->cursg++; qc->cursg_ofs = 0; } @@ -2640,7 +2639,9 @@ kunmap(page); - if (bytes) { + if (bytes > count) { + bytes -= count; + goto next_sg; } }