[PATCH] libata: fix qc->n_elem == 0 case handling in ata_qc_next_sg
This patch makes ata_for_each_sg() start with pad_sgent when qc->n_elem is zero. Previously, ata_for_each_sg() unconditionally started with qc->__sg, handling the first sg to fill_sg() routines even when the entry was invalid. And while at it, unwind ?: in ata_qc_next_sg() into if statement. Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jgarzik@pobox.com>
This commit is contained in:
parent
9ae61c6cb6
commit
cc1887f3d8
|
@ -556,6 +556,16 @@ ata_sg_is_last(struct scatterlist *sg, struct ata_queued_cmd *qc)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline struct scatterlist *
|
||||
ata_qc_first_sg(struct ata_queued_cmd *qc)
|
||||
{
|
||||
if (qc->n_elem)
|
||||
return qc->__sg;
|
||||
if (qc->pad_len)
|
||||
return &qc->pad_sgent;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline struct scatterlist *
|
||||
ata_qc_next_sg(struct scatterlist *sg, struct ata_queued_cmd *qc)
|
||||
{
|
||||
|
@ -563,11 +573,13 @@ ata_qc_next_sg(struct scatterlist *sg, struct ata_queued_cmd *qc)
|
|||
return NULL;
|
||||
if (++sg - qc->__sg < qc->n_elem)
|
||||
return sg;
|
||||
return qc->pad_len ? &qc->pad_sgent : NULL;
|
||||
if (qc->pad_len)
|
||||
return &qc->pad_sgent;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define ata_for_each_sg(sg, qc) \
|
||||
for (sg = qc->__sg; sg; sg = ata_qc_next_sg(sg, qc))
|
||||
for (sg = ata_qc_first_sg(qc); sg; sg = ata_qc_next_sg(sg, qc))
|
||||
|
||||
static inline unsigned int ata_tag_valid(unsigned int tag)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue