[PATCH] libata: convert assert(X)'s in libata core layer to WARN_ON(!X)'s
In an effort to kill libata-specific assert() and use generic
WARN_ON(), this patch converts all assert(X)'s in libata core layer to
WARN_ON(!X)'s. Most conversions are straight-forward logical negation
exception for the followings.
* In libata-core.c:ata_fill_sg(),
assert(qc->n_elem > 0) is converted to WARN_ON(qc->n_elem == 0) because
qc->n_elem is unsigned and unsigned <= 0 is weird.
* In libata-scsi.c:ata_gen_ata_desc/fixed_sense(),
assert(NULL != qc->ap->ops->tf_read) is converted to
WARN_ON(qc->ap->ops->tf_read == NULL), as there are no other users of
'constant cond var' style in libata.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jgarzik@pobox.com>
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index fffbaa9..cef85e5 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -904,8 +904,8 @@
DPRINTK("ENTER, host %u, dev %u\n", ap->id, device);
- assert (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ATAPI ||
- dev->class == ATA_DEV_NONE);
+ WARN_ON(dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ATAPI &&
+ dev->class != ATA_DEV_NONE);
ata_dev_select(ap, device, 1, 1); /* select device 0/1 */
@@ -2301,7 +2301,7 @@
master = &ap->device[0];
slave = &ap->device[1];
- assert (ata_dev_present(master) || ata_dev_present(slave));
+ WARN_ON(!ata_dev_present(master) && !ata_dev_present(slave));
if (shift == ATA_SHIFT_UDMA) {
mask = ap->udma_mask;
@@ -2547,11 +2547,11 @@
int dir = qc->dma_dir;
void *pad_buf = NULL;
- assert(qc->flags & ATA_QCFLAG_DMAMAP);
- assert(sg != NULL);
+ WARN_ON(!(qc->flags & ATA_QCFLAG_DMAMAP));
+ WARN_ON(sg == NULL);
if (qc->flags & ATA_QCFLAG_SINGLE)
- assert(qc->n_elem == 1);
+ WARN_ON(qc->n_elem != 1);
VPRINTK("unmapping %u sg elements\n", qc->n_elem);
@@ -2606,8 +2606,8 @@
struct scatterlist *sg;
unsigned int idx;
- assert(qc->__sg != NULL);
- assert(qc->n_elem > 0);
+ WARN_ON(qc->__sg == NULL);
+ WARN_ON(qc->n_elem == 0);
idx = 0;
ata_for_each_sg(sg, qc) {
@@ -2759,7 +2759,7 @@
void *pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ);
struct scatterlist *psg = &qc->pad_sgent;
- assert(qc->dev->class == ATA_DEV_ATAPI);
+ WARN_ON(qc->dev->class != ATA_DEV_ATAPI);
memset(pad_buf, 0, ATA_DMA_PAD_SZ);
@@ -2821,7 +2821,7 @@
int n_elem, pre_n_elem, dir, trim_sg = 0;
VPRINTK("ENTER, ata%u\n", ap->id);
- assert(qc->flags & ATA_QCFLAG_SG);
+ WARN_ON(!(qc->flags & ATA_QCFLAG_SG));
/* we must lengthen transfers to end on a 32-bit boundary */
qc->pad_len = lsg->length & 3;
@@ -2830,7 +2830,7 @@
struct scatterlist *psg = &qc->pad_sgent;
unsigned int offset;
- assert(qc->dev->class == ATA_DEV_ATAPI);
+ WARN_ON(qc->dev->class != ATA_DEV_ATAPI);
memset(pad_buf, 0, ATA_DMA_PAD_SZ);
@@ -2924,7 +2924,7 @@
unsigned int reg_state = HSM_ST_UNKNOWN;
qc = ata_qc_from_tag(ap, ap->active_tag);
- assert(qc != NULL);
+ WARN_ON(qc == NULL);
switch (ap->hsm_task_state) {
case HSM_ST:
@@ -2992,7 +2992,7 @@
}
qc = ata_qc_from_tag(ap, ap->active_tag);
- assert(qc != NULL);
+ WARN_ON(qc == NULL);
drv_stat = ata_wait_idle(ap);
if (!ata_ok(drv_stat)) {
@@ -3003,7 +3003,7 @@
ap->hsm_task_state = HSM_ST_IDLE;
- assert(qc->err_mask == 0);
+ WARN_ON(qc->err_mask);
ata_poll_qc_complete(qc);
/* another command may start at this point */
@@ -3360,7 +3360,7 @@
}
qc = ata_qc_from_tag(ap, ap->active_tag);
- assert(qc != NULL);
+ WARN_ON(qc == NULL);
/* check error */
if (status & (ATA_ERR | ATA_DF)) {
@@ -3397,12 +3397,12 @@
printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
qc = ata_qc_from_tag(ap, ap->active_tag);
- assert(qc != NULL);
+ WARN_ON(qc == NULL);
/* make sure qc->err_mask is available to
* know what's wrong and recover
*/
- assert(qc->err_mask);
+ WARN_ON(qc->err_mask == 0);
ap->hsm_task_state = HSM_ST_IDLE;
@@ -3609,7 +3609,7 @@
struct ata_port *ap = qc->ap;
unsigned int tag;
- assert(qc != NULL); /* ata_qc_from_tag _might_ return NULL */
+ WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
qc->flags = 0;
tag = qc->tag;
@@ -3623,8 +3623,8 @@
void __ata_qc_complete(struct ata_queued_cmd *qc)
{
- assert(qc != NULL); /* ata_qc_from_tag _might_ return NULL */
- assert(qc->flags & ATA_QCFLAG_ACTIVE);
+ WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
+ WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE));
if (likely(qc->flags & ATA_QCFLAG_DMAMAP))
ata_sg_clean(qc);
@@ -4155,8 +4155,8 @@
u8 status;
qc = ata_qc_from_tag(ap, ap->active_tag);
- assert(qc != NULL);
- assert(qc->flags & ATA_QCFLAG_ACTIVE);
+ WARN_ON(qc == NULL);
+ WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE));
/* sleep-wait for BSY to clear */
DPRINTK("busy wait\n");
@@ -4174,7 +4174,7 @@
/* send SCSI cdb */
DPRINTK("send cdb\n");
- assert(ap->cdb_len >= 12);
+ WARN_ON(ap->cdb_len < 12);
if (qc->tf.protocol == ATA_PROT_ATAPI_DMA ||
qc->tf.protocol == ATA_PROT_ATAPI_NODATA) {