Re: [PATCH v5 1/2] ata: pata_cswarp: Add Amiga cslab ata support
From: Geert Uytterhoeven
Date: Thu Aug 27 2026 - 03:30:02 EST
Hi Michael,
On Wed, 26 Aug 2026 at 21:31, Michael Schmitz <schmitzmic@xxxxxxxxx> wrote:
> On 25/08/26 19:53, Geert Uytterhoeven wrote:
> >> +static unsigned int pata_cswarp_data_xfer(struct ata_queued_cmd *qc,
> >> + unsigned char *buf,
> >> + unsigned int buflen, int rw)
> >> +{
> >> + struct ata_device *dev = qc->dev;
> >> + struct ata_port *ap = dev->link->ap;
> >> + void __iomem *data_addr = ap->ioaddr.data_addr;
> >> + unsigned int words = buflen >> 1;
> >> + u16 *buf16 = (u16 *)buf;
> >> +
> >> + /* Transfer multiple of 2 bytes */
> >> + if (rw == READ)
> >> + raw_insw(data_addr, buf16, words);
> >> + else
> >> + raw_outsw(data_addr, buf16, words);
> >> +
> >> + /* Transfer trailing byte, if any. */
> >> + if (unlikely(buflen & 0x01)) {
> >> + if (rw == READ)
> >> + buf[buflen - 1] = raw_inw(data_addr) >> 8;
> >> + else
> >> + raw_outw(buf[buflen - 1] << 8, data_addr);
> >> + words++;
> >> + }
> >> +
> >> + return words << 1;
> > This may be one less than the actual number of bytes
> > Why not buflen?
> >
> words = buflen >> 1;
>
> followed by
>
> if (buflen & 0x01) words++;
>
> makes 'words' the correct (i.e. rounded upwards if buflen was odd)
> number of words transferred.
Thanks, I had completely missed that increment.
> The return value is then either correct, or one larger than the actual
> number of bytes?
>
> I believe the template for these functions was
> drivers/ata/libata-sff.c:ata_sff_data_xfer() which follows the exact
> same logic.
Then Life's Good ;-)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds