Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers/ata/libata: Move dereference after NULL test

In each case, if the NULL test on qc is needed, then the derefernce
should be after the NULL test.

A simplified version of the semantic match that detects this problem is as
follows (http://coccinelle.lip6.fr/):

// <smpl>
@match exists@
expression x, E;
identifier fld;
@@

* x->fld
... when != \(x = E\|&x\)
* x == NULL
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>

authored by

Julia Lawall and committed by
Jeff Garzik
a1104016 e65cc194

+6 -3
+6 -3
drivers/ata/libata-core.c
··· 4919 4919 */ 4920 4920 void ata_qc_free(struct ata_queued_cmd *qc) 4921 4921 { 4922 - struct ata_port *ap = qc->ap; 4922 + struct ata_port *ap; 4923 4923 unsigned int tag; 4924 4924 4925 4925 WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ 4926 + ap = qc->ap; 4926 4927 4927 4928 qc->flags = 0; 4928 4929 tag = qc->tag; ··· 4935 4934 4936 4935 void __ata_qc_complete(struct ata_queued_cmd *qc) 4937 4936 { 4938 - struct ata_port *ap = qc->ap; 4939 - struct ata_link *link = qc->dev->link; 4937 + struct ata_port *ap; 4938 + struct ata_link *link; 4940 4939 4941 4940 WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ 4942 4941 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE)); 4942 + ap = qc->ap; 4943 + link = qc->dev->link; 4943 4944 4944 4945 if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) 4945 4946 ata_sg_clean(qc);