Re: ata_tf_read_block() question

From: Tejun Heo
Date: Sat Aug 15 2009 - 22:15:48 EST


Hello, Atsushi.

Atsushi Nemoto wrote:
> I have a question on CHS calculation in ata_tf_read_block().
>
> The calculation in ata_tf_read_block() is:
> block = (cyl * dev->heads + head) * dev->sectors + sect;
>
> but ata_build_rw_tf() does:
> track = (u32)block / dev->sectors;
> cyl = track / dev->heads;
> head = track % dev->heads;
> sect = (u32)block % dev->sectors + 1;
>
> It seems inconsistent. The correct calculation is:
> block = (cyl * dev->heads + head) * dev->sectors + sect - 1;
> isn't it?

Yes, indeed.

> I don't have any real problem. Just noticed by code reading.

ata_tf_read_block() currently is used only when reporting failed block
address to upper layer so off-by-one bug there wouldn't be too
visible, especially for the venerable CHS addressing.

Care to submit a patch w/ warning message and capping for sect == 0
case?

Thanks.

--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/