提交 ac8672ea 编写于 作者: T Tejun Heo 提交者: Jeff Garzik

libata: fix off-by-one error in ata_tf_read_block()

ata_tf_read_block() has off-by-one error when converting CHS address
to LBA.  The bug isn't very visible because ata_tf_read_block() is
used only when generating sense data for a failed RW command and CHS
addressing isn't used too often these days.

This problem was spotted by Atsushi Nemoto.
Signed-off-by: NTejun Heo <tj@kernel.org>
Reported-by: NAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: NJeff Garzik <jgarzik@redhat.com>
上级 1b549dcb
......@@ -709,7 +709,13 @@ u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev)
head = tf->device & 0xf;
sect = tf->lbal;
block = (cyl * dev->heads + head) * dev->sectors + sect;
if (!sect) {
ata_dev_printk(dev, KERN_WARNING, "device reported "
"invalid CHS sector 0\n");
sect = 1; /* oh well */
}
block = (cyl * dev->heads + head) * dev->sectors + sect - 1;
}
return block;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册