Linux ATA/IDE development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: linux-ide@vger.kernel.org, dlemoal@kernel.org, cassel@kernel.org
Subject: Re: [PATCH] ata: pata_ep93xx: fix endianness bug in trailing byte transfer
Date: Mon, 01 Jun 2026 19:16:54 +0000	[thread overview]
Message-ID: <20260601191655.3E4B91F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260601190921.20167-1-rosenp@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The `ep93xx_pata_data_xfer()` function destroys the `words` loop counter, returning an incorrect byte count that breaks ATAPI PIO transfers.
--

commit c92ab9f0ecc44ddedc25d0e57302962565e67769
Author: Rosen Penev <rosenp@gmail.com>

ata: pata_ep93xx: fix endianness bug in trailing byte transfer

This commit fixes an endianness bug in ep93xx_pata_data_xfer() where a trailing
odd byte was being truncated and incorrectly byte-swapped on big-endian
systems. It removes the cpu_to_le16/le16_to_cpu wrappers and uses the raw
read/write values directly.

> diff --git a/drivers/ata/pata_ep93xx.c b/drivers/ata/pata_ep93xx.c
> --- a/drivers/ata/pata_ep93xx.c
> +++ b/drivers/ata/pata_ep93xx.c
> @@ -495,19 +495,12 @@ static unsigned int ep93xx_pata_data_xfer(struct ata_queued_cmd *qc,
>  
>  	/* Transfer trailing 1 byte, if any. */
>  	if (unlikely(buflen & 0x01)) {

[ ... ]

>  		if (rw == READ) {
> -			*pad = cpu_to_le16(
> -				ep93xx_pata_read_data(
> -					drv_data, IDECTRL_ADDR_DATA));
> -			*buf = pad[0];
> +			*buf = ep93xx_pata_read_data(drv_data, IDECTRL_ADDR_DATA);
>  		} else {
> -			pad[0] = *buf;
> -			ep93xx_pata_write_data(drv_data, le16_to_cpu(*pad),
> -					  IDECTRL_ADDR_DATA);
> +			ep93xx_pata_write_data(drv_data, *buf, IDECTRL_ADDR_DATA);
>  		}
>  		words++;

[Severity: High]
This is a pre-existing issue, but does this function return an incorrect byte
count that breaks ATAPI PIO transfers?

Earlier in ep93xx_pata_data_xfer(), there is a loop that destroys the words
counter:

        unsigned int words = buflen >> 1;
        while (words--)
            /* transfer 2 bytes */

Because of the post-decrement, the words counter underflows to UINT_MAX when
the loop terminates. If there is an odd trailing byte, words++ wraps it back
to 0, and the function returns 0 since the end of the function is:

        return words << 1;

If there is no trailing byte, the function returns UINT_MAX << 1, which is
0xFFFFFFFE.

Returning 0 for an odd-length transfer causes callers like
__atapi_pio_bytes() to not decrement their remaining bytes counter while
still advancing the scatter-gather list, resulting in unexpected or too
much trailing data errors.

Returning 0xFFFFFFFE causes __atapi_pio_bytes() to subtract that huge amount
in a single iteration, instantly dropping the remaining transfer count to zero
even if the DRQ block spanned multiple scatter-gather entries.

Could this be fixed by saving the original buffer length and returning that
instead of relying on the mutated words counter?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260601190921.20167-1-rosenp@gmail.com?part=1

      reply	other threads:[~2026-06-01 19:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01 19:09 [PATCH] ata: pata_ep93xx: fix endianness bug in trailing byte transfer Rosen Penev
2026-06-01 19:16 ` sashiko-bot [this message]

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=20260601191655.3E4B91F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=rosenp@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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