Commit cffd1ee9 authored by Hannes Reinecke's avatar Hannes Reinecke Committed by Tejun Heo

libata: sanitize ata_tf_read_block()

Return U64_MAX if ata_tf_read_block() could not decode the LBA
address, and do not set the information sense descriptor in
ata_gen_ata_sense() in these cases.

tj: s/(u64)-1/U64_MAX/
Signed-off-by: default avatarHannes Reinecke <hare@suse.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent 5e6acd1c
...@@ -695,7 +695,7 @@ static int ata_rwcmd_protocol(struct ata_taskfile *tf, struct ata_device *dev) ...@@ -695,7 +695,7 @@ static int ata_rwcmd_protocol(struct ata_taskfile *tf, struct ata_device *dev)
* RETURNS: * RETURNS:
* Block address read from @tf. * Block address read from @tf.
*/ */
u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev) u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev)
{ {
u64 block = 0; u64 block = 0;
...@@ -720,7 +720,7 @@ u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev) ...@@ -720,7 +720,7 @@ u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev)
if (!sect) { if (!sect) {
ata_dev_warn(dev, ata_dev_warn(dev,
"device reported invalid CHS sector 0\n"); "device reported invalid CHS sector 0\n");
sect = 1; /* oh well */ return U64_MAX;
} }
block = (cyl * dev->heads + head) * dev->sectors + sect - 1; block = (cyl * dev->heads + head) * dev->sectors + sect - 1;
......
...@@ -1083,6 +1083,8 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc) ...@@ -1083,6 +1083,8 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)
} }
block = ata_tf_read_block(&qc->result_tf, dev); block = ata_tf_read_block(&qc->result_tf, dev);
if (block == U64_MAX)
return;
/* information sense data descriptor */ /* information sense data descriptor */
sb[7] = 12; sb[7] = 12;
......
...@@ -67,7 +67,8 @@ extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag); ...@@ -67,7 +67,8 @@ extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag);
extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
u64 block, u32 n_block, unsigned int tf_flags, u64 block, u32 n_block, unsigned int tf_flags,
unsigned int tag); unsigned int tag);
extern u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev); extern u64 ata_tf_read_block(const struct ata_taskfile *tf,
struct ata_device *dev);
extern unsigned ata_exec_internal(struct ata_device *dev, extern unsigned ata_exec_internal(struct ata_device *dev,
struct ata_taskfile *tf, const u8 *cdb, struct ata_taskfile *tf, const u8 *cdb,
int dma_dir, void *buf, unsigned int buflen, int dma_dir, void *buf, unsigned int buflen,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment