From mboxrd@z Thu Jan 1 00:00:00 1970 From: Albert Lee Subject: [PATCH 2/4] libata: if condition fix for __atapi_pio_bytes() Date: Fri, 10 Jun 2005 15:38:22 +0800 Message-ID: <42A9436E.9090906@tw.ibm.com> References: <42A3FF7B.3040201@tw.ibm.com> <42A7ED91.4090008@pobox.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------000807010209040403010802" Return-path: Received: from bluehawaii.tikira.net ([61.62.22.51]:55263 "EHLO bluehawaii.tikira.net") by vger.kernel.org with ESMTP id S261511AbVFJHir (ORCPT ); Fri, 10 Jun 2005 03:38:47 -0400 In-Reply-To: <42A7ED91.4090008@pobox.com> Sender: linux-ide-owner@vger.kernel.org List-Id: linux-ide@vger.kernel.org To: Jeff Garzik Cc: Linux IDE , Bartlomiej Zolnierkiewicz , Doug Maxey This is a multi-part message in MIME format. --------------000807010209040403010802 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Hi Jeff, Resend the patch #2 against the linux-2.6.git tree (0086b5ec7834b78358dea3f713275a9ae2b229ec). Problem: In __atapi_pio_bytes(), when (bytes > qc->nbytes) or (qc->cursg_ofs > sg->length) or (count > bytes), the if condition is not handled properly. Changes: - Fix the "if conditions" to make the "if conditions" more robust. Albert Signed-off-by: Albert Lee --------------000807010209040403010802 Content-Type: text/plain; name="02_if_fix.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="02_if_fix.diff" --- 11_atapi_pio_sg_fix/drivers/scsi/libata-core.c 2005-06-10 14:51:51.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; } } --------------000807010209040403010802--