linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Albert Lee <albertcc@tw.ibm.com>
To: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Cc: Jeff Garzik <jgarzik@pobox.com>,
	Linux IDE <linux-ide@vger.kernel.org>,
	Doug Maxey <dwm@maxeymade.com>
Subject: Re: [PATCH 2/4] if condition fix for __atapi_pio_bytes()
Date: Wed, 08 Jun 2005 19:58:22 +0800	[thread overview]
Message-ID: <42A6DD5E.30408@tw.ibm.com> (raw)
In-Reply-To: <58cb370e0506080248378c2cf2@mail.gmail.com>


Hi Bart:

>>
>>Normally (qc->cursg_ofs > sg->length) or (count > bytes) won't happen.
>>However, if we apply patch [4/4], which overrun the odd-length buffer by one byte,
>>then (qc->cursg_ofs > sg->length) and (count > bytes) could happen.
> 
> 
> If so wouldn't it be easier to round 'bytes' instead of 'count' in the patch #4?
> 
> * this patch (#2) gets simpler
> * no need to round 'bytes' in the patch #3
> * rounding can be moved from "sg loop" to the beginning of __atapi_pio_bytes()
>   in the patch #4
> 

ata_data_xfer() also does rounding: 'unsigned int words = buflen >> 1;'
If we only round 'bytes' and moves rounding from "sg loop" to the beginning of __atapi_pio_bytes(),
then the last 1 bytes of odd length buffer will still be lost.

Ex. say 'sg->length' is 51, 'qc->cursg_ofs' is 0 and 'bytes' is 52 (rounded), after the min()
         /* don't overrun current sg */
	count = min(sg->length - qc->cursg_ofs, bytes);

      'count' will be 51, and ata_data_xfer() will only transfer 50 bytes.
  52 - 51 = 1 (1 byte trailing) So the trailing handling code will be invoked and eat the 51th and 52th byte.
The 51th byte is lost. :(

   Maybe we can round both 'sg->length' and 'bytes'?
Ex.
	bytes += bytes & 0x01;
         ....
loop:
	....
	/* don't overrun current sg */
	sg->length += (sg->length) & 0x01;  // Round sg->length
	count = min(sg->length - qc->cursg_ofs, bytes);
      => both 'count' and 'byte' will be 52 here

   However, this will introduce another rounding into the loop. :(

BTW, some cd-rom drive acutally rounds odd length from 51 to 52. (eg. asus crw-5232as on my test machine).
Overrunning the count and sg (sg->length is 51) by one byte as done in patch #4 can save us one loop in the trailing handling code.
Ex. count 51 rounded to 52; byte is 52 rounded by device
     => byte -= count is zero and no need to go the trailing handling code.

Albert




  reply	other threads:[~2005-06-08 11:59 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-06  7:47 [PATCH 0/4] Resubmit ATAPI PIO mode fixes Albert Lee
2005-06-06  7:56 ` [PATCH 1/4] sg traverse fix for __atapi_pio_bytes() Albert Lee
2005-06-06  9:24   ` Bartlomiej Zolnierkiewicz
2005-06-06  7:58 ` [PATCH 2/4] if condition " Albert Lee
2005-06-06  9:32   ` Bartlomiej Zolnierkiewicz
2005-06-08  3:47     ` Albert Lee
2005-06-08  9:48       ` Bartlomiej Zolnierkiewicz
2005-06-08 11:58         ` Albert Lee [this message]
2005-06-08 13:33           ` Bartlomiej Zolnierkiewicz
2005-06-09  4:05             ` Albert Lee
2005-06-09  6:54               ` Bartlomiej Zolnierkiewicz
2005-06-08 13:39           ` Bartlomiej Zolnierkiewicz
2005-06-06  7:59 ` [PATCH 3/4] trailing data handling " Albert Lee
2005-06-06  9:37   ` Bartlomiej Zolnierkiewicz
2005-06-06  8:01 ` [PATCH 4/4] odd length data handling " Albert Lee
2005-06-06  9:39   ` Bartlomiej Zolnierkiewicz
     [not found] ` <42A7ED91.4090008@pobox.com>
2005-06-10  6:08   ` [PATCH 0/4] Resubmit ATAPI PIO mode fixes Albert Lee
2005-06-10  7:38   ` [PATCH 2/4] libata: if condition fix for __atapi_pio_bytes() Albert Lee
2005-06-10  7:56     ` Bartlomiej Zolnierkiewicz
2005-06-10  8:31       ` Albert Lee
2005-06-10  7:44   ` [PATCH 3/4] libata: trailing data handling " Albert Lee
2005-06-10  7:46   ` [PATCH 4/4] libata: odd length data handling " Albert Lee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42A6DD5E.30408@tw.ibm.com \
    --to=albertcc@tw.ibm.com \
    --cc=bzolnier@gmail.com \
    --cc=dwm@maxeymade.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-ide@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).