--- 11_atapi_pio_sg_fix/drivers/scsi/libata-core.c 2005-06-06 13:45:33.000000000 +0800 +++ 12_atapi_pio_if_condition_fix/drivers/scsi/libata-core.c 2005-06-06 13:52:11.000000000 +0800 @@ -2571,7 +2571,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: @@ -2592,11 +2592,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; } @@ -2608,7 +2607,9 @@ kunmap(page); - if (bytes) { + if (bytes > count) { + bytes -= count; + goto next_sg; } }