* [patch] libsas: dereferencing variable before check
@ 2010-05-12 22:56 Dan Carpenter
  2010-05-12 23:08 ` Tejun Heo
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2010-05-12 22:56 UTC (permalink / raw)
  To: James E.J. Bottomley; +Cc: Tejun Heo, linux-scsi, linux-kernel
The "qc->scsicmd" could be null so I moved the dereference inside the
check.  This was introduced by 70b25f890: "[SCSI] fix locking around
blk_abort_request()" 
Signed-off-by: Dan Carpenter <error27@gmail.com>
diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 88f7446..98b1545 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -395,12 +395,13 @@ int sas_ata_init_host_and_port(struct domain_device *found_dev,
 void sas_ata_task_abort(struct sas_task *task)
 {
 	struct ata_queued_cmd *qc = task->uldd_task;
-	struct request_queue *q = qc->scsicmd->device->request_queue;
+	struct request_queue *q;
 	struct completion *waiting;
 	unsigned long flags;
 
 	/* Bounce SCSI-initiated commands to the SCSI EH */
 	if (qc->scsicmd) {
+		q = qc->scsicmd->device->request_queue;
 		spin_lock_irqsave(q->queue_lock, flags);
 		blk_abort_request(qc->scsicmd->request);
 		spin_unlock_irqrestore(q->queue_lock, flags);
^ permalink raw reply related	[flat|nested] 5+ messages in thread
* Re: [patch] libsas: dereferencing variable before check
  2010-05-12 22:56 [patch] libsas: dereferencing variable before check Dan Carpenter
@ 2010-05-12 23:08 ` Tejun Heo
  2010-05-13 14:31   ` James Bottomley
  0 siblings, 1 reply; 5+ messages in thread
From: Tejun Heo @ 2010-05-12 23:08 UTC (permalink / raw)
  To: Dan Carpenter, James E.J. Bottomley; +Cc: linux-scsi, linux-kernel
"Dan Carpenter" <error27@gmail.com> wrote:
>The "qc->scsicmd" could be null so I moved the dereference inside the
>check.  This was introduced by 70b25f890: "[SCSI] fix locking around
>blk_abort_request()" 
>
>Signed-off-by: Dan Carpenter <error27@gmail.com>
Ooh.. right.
Asked-by: Tejun Heo <tj@kernel.org>
Thanks.
-- 
tejun
^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [patch] libsas: dereferencing variable before check
  2010-05-12 23:08 ` Tejun Heo
@ 2010-05-13 14:31   ` James Bottomley
  2010-05-13 14:37     ` Tejun Heo
  2010-05-13 18:42     ` Dan Carpenter
  0 siblings, 2 replies; 5+ messages in thread
From: James Bottomley @ 2010-05-13 14:31 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Dan Carpenter, linux-scsi, linux-kernel
On Thu, 2010-05-13 at 01:08 +0200, Tejun Heo wrote:
> 
> "Dan Carpenter" <error27@gmail.com> wrote:
> 
> >The "qc->scsicmd" could be null so I moved the dereference inside the
> >check.  This was introduced by 70b25f890: "[SCSI] fix locking around
> >blk_abort_request()" 
> >
> >Signed-off-by: Dan Carpenter <error27@gmail.com>
> 
> Ooh.. right.
> 
> Asked-by: Tejun Heo <tj@kernel.org>
Well, oops, yes.  Two patches to fix one bug is a bit overboard, I
think, plus some code rearrangement to fix the locality of the problem
and ensure it doesn't happen again might be useful.  What about this.
James
---
diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 88f7446..8c496b5 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -395,12 +395,13 @@ int sas_ata_init_host_and_port(struct domain_device *found_dev,
 void sas_ata_task_abort(struct sas_task *task)
 {
 	struct ata_queued_cmd *qc = task->uldd_task;
-	struct request_queue *q = qc->scsicmd->device->request_queue;
 	struct completion *waiting;
-	unsigned long flags;
 
 	/* Bounce SCSI-initiated commands to the SCSI EH */
 	if (qc->scsicmd) {
+		struct request_queue *q = qc->scsicmd->device->request_queue;
+		unsigned long flags;
+
 		spin_lock_irqsave(q->queue_lock, flags);
 		blk_abort_request(qc->scsicmd->request);
 		spin_unlock_irqrestore(q->queue_lock, flags);
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 8228350..53849f2 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -1030,8 +1030,6 @@ int __sas_task_abort(struct sas_task *task)
 void sas_task_abort(struct sas_task *task)
 {
 	struct scsi_cmnd *sc = task->uldd_task;
-	struct request_queue *q = sc->device->request_queue;
-	unsigned long flags;
 
 	/* Escape for libsas internal commands */
 	if (!sc) {
@@ -1043,13 +1041,15 @@ void sas_task_abort(struct sas_task *task)
 
 	if (dev_is_sata(task->dev)) {
 		sas_ata_task_abort(task);
-		return;
-	}
+	} else {
+		struct request_queue *q = sc->device->request_queue;
+		unsigned long flags;
 
-	spin_lock_irqsave(q->queue_lock, flags);
-	blk_abort_request(sc->request);
-	spin_unlock_irqrestore(q->queue_lock, flags);
-	scsi_schedule_eh(sc->device->host);
+		spin_lock_irqsave(q->queue_lock, flags);
+		blk_abort_request(sc->request);
+		spin_unlock_irqrestore(q->queue_lock, flags);
+		scsi_schedule_eh(sc->device->host);
+	}
 }
 
 int sas_slave_alloc(struct scsi_device *scsi_dev)
^ permalink raw reply related	[flat|nested] 5+ messages in thread
* Re: [patch] libsas: dereferencing variable before check
  2010-05-13 14:31   ` James Bottomley
@ 2010-05-13 14:37     ` Tejun Heo
  2010-05-13 18:42     ` Dan Carpenter
  1 sibling, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2010-05-13 14:37 UTC (permalink / raw)
  To: James Bottomley; +Cc: Dan Carpenter, linux-scsi, linux-kernel
Hello,
On 05/13/2010 04:31 PM, James Bottomley wrote:
>> Ooh.. right.
>>
>> Asked-by: Tejun Heo <tj@kernel.org>
That was my first mail from android and of course I typed Asked
instead of Acked.  :-)
> Well, oops, yes.  Two patches to fix one bug is a bit overboard, I
> think, plus some code rearrangement to fix the locality of the problem
> and ensure it doesn't happen again might be useful.  What about this.
Yeap, as long as the silly bug is fixed.
Thank you.
-- 
tejun
^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [patch] libsas: dereferencing variable before check
  2010-05-13 14:31   ` James Bottomley
  2010-05-13 14:37     ` Tejun Heo
@ 2010-05-13 18:42     ` Dan Carpenter
  1 sibling, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2010-05-13 18:42 UTC (permalink / raw)
  To: James Bottomley; +Cc: Tejun Heo, linux-scsi, linux-kernel
On Thu, May 13, 2010 at 09:31:54AM -0500, James Bottomley wrote:
> On Thu, 2010-05-13 at 01:08 +0200, Tejun Heo wrote:
> > 
> > "Dan Carpenter" <error27@gmail.com> wrote:
> > 
> > >The "qc->scsicmd" could be null so I moved the dereference inside the
> > >check.  This was introduced by 70b25f890: "[SCSI] fix locking around
> > >blk_abort_request()" 
> > >
> > >Signed-off-by: Dan Carpenter <error27@gmail.com>
> > 
> > Ooh.. right.
> > 
> > Asked-by: Tejun Heo <tj@kernel.org>
> 
> Well, oops, yes.  Two patches to fix one bug is a bit overboard, I
> think, plus some code rearrangement to fix the locality of the problem
> and ensure it doesn't happen again might be useful.  What about this.
> 
Looks good.
Acked-by: Dan Carpenter <error27@gmail.com>
regards,
dan carpenter
^ permalink raw reply	[flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-05-13 18:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-12 22:56 [patch] libsas: dereferencing variable before check Dan Carpenter
2010-05-12 23:08 ` Tejun Heo
2010-05-13 14:31   ` James Bottomley
2010-05-13 14:37     ` Tejun Heo
2010-05-13 18:42     ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).