From 2a5f07b5ec098edc69e05fdd2f35d3fbb1235723 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Mon, 1 Nov 2010 11:39:19 +0100 Subject: [PATCH 1/3] libata: fix NULL sdev dereference race in atapi_qc_complete() SCSI commands may be issued between __scsi_add_device() and dev->sdev assignment, so it's unsafe for ata_qc_complete() to dereference dev->sdev->locked without checking whether it's NULL or not. Fix it. Signed-off-by: Tejun Heo Cc: stable@kernel.org Signed-off-by: Jeff Garzik --- drivers/ata/libata-scsi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index d050e073e570..3f91c01c217f 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -2552,8 +2552,11 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc) * * If door lock fails, always clear sdev->locked to * avoid this infinite loop. + * + * This may happen before SCSI scan is complete. Make + * sure qc->dev->sdev isn't NULL before dereferencing. */ - if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL) + if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL && qc->dev->sdev) qc->dev->sdev->locked = 0; qc->scsicmd->result = SAM_STAT_CHECK_CONDITION; From f60215a1302f03ad435f8365c0dd85bdb022cac3 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Fri, 12 Nov 2010 12:01:41 +0100 Subject: [PATCH 2/3] pata_legacy: fix CONFIG_PATA_WINBOND_VLB_MODULE test pata_legacy is incorrectly testing PATA_WINBOND_VLB_MODULE instead of CONFIG_PATA_WINBOND_VLB_MODULE. Fix it. Signed-off-by: Tejun Heo Reported-by: "Robert P. J. Day" Signed-off-by: Jeff Garzik --- drivers/ata/pata_legacy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c index eaf194138f21..6bd9425ba5ab 100644 --- a/drivers/ata/pata_legacy.c +++ b/drivers/ata/pata_legacy.c @@ -142,7 +142,7 @@ static int autospeed; /* Chip present which snoops speed changes */ static int pio_mask = ATA_PIO4; /* PIO range for autospeed devices */ static int iordy_mask = 0xFFFFFFFF; /* Use iordy if available */ -#ifdef PATA_WINBOND_VLB_MODULE +#ifdef CONFIG_PATA_WINBOND_VLB_MODULE static int winbond = 1; /* Set to probe Winbond controllers, give I/O port if non standard */ #else From f2543790875b088e2a58aa12ee1ac20a75d6126d Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Tue, 26 Oct 2010 12:25:43 +0200 Subject: [PATCH 3/3] drivers/ata/pata_octeon_cf.c: delete double assignment Delete successive assignments to the same location. A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/) // @@ expression i; @@ *i = ...; i = ...; // Signed-off-by: Julia Lawall Signed-off-by: Jeff Garzik --- drivers/ata/pata_octeon_cf.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c index 74b829817891..fa1b95a9a7ff 100644 --- a/drivers/ata/pata_octeon_cf.c +++ b/drivers/ata/pata_octeon_cf.c @@ -652,8 +652,6 @@ static irqreturn_t octeon_cf_interrupt(int irq, void *dev_instance) struct octeon_cf_data *ocd; ap = host->ports[i]; - ocd = ap->dev->platform_data; - ocd = ap->dev->platform_data; cf_port = ap->private_data; dma_int.u64 =