public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* NULL check after starget_to_rport()?
@ 2009-07-15 21:12 Roel Kluin
  2009-07-16  8:28 ` Abhijeet Joglekar (abjoglek)
  2009-07-16 11:23 ` [PATCH] fnic: clean up Roel Kluin
  0 siblings, 2 replies; 4+ messages in thread
From: Roel Kluin @ 2009-07-15 21:12 UTC (permalink / raw)
  To: abjoglek, jeykholt, linux-scsi

// vi include/scsi/scsi_transport_fc.h +396
#define starget_to_rport(s)			\
	scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL

So shouldn't we test for this NULL value (something like the untested patch
below?)

Also I had two more questions concerning this file:

In fnic_clean_pending_aborts(), rport isn't used after the starget_to_rport().
is the rport needed?

Should fnic_block_error_handler() return an error value if rport is NULL?

Roel

diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c
index bfc9969..8a6bb3e 100644
--- a/drivers/scsi/fnic/fnic_scsi.c
+++ b/drivers/scsi/fnic/fnic_scsi.c
@@ -346,6 +346,9 @@ int fnic_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
 	unsigned long ptr;
 
 	rport = starget_to_rport(scsi_target(sc->device));
+	if (rport == NULL)
+		return 0;
+
 	ret = fc_remote_port_chkready(rport);
 	if (ret) {
 		sc->result = ret;
@@ -1230,6 +1233,9 @@ static void fnic_block_error_handler(struct scsi_cmnd *sc)
 	struct fc_rport *rport = starget_to_rport(scsi_target(sc->device));
 	unsigned long flags;
 
+	if (rport == NULL)
+		return;
+
 	spin_lock_irqsave(shost->host_lock, flags);
 	while (rport->port_state == FC_PORTSTATE_BLOCKED) {
 		spin_unlock_irqrestore(shost->host_lock, flags);
@@ -1265,11 +1271,12 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
 	lp = shost_priv(sc->device->host);
 
 	fnic = lport_priv(lp);
-	FNIC_SCSI_DBG(KERN_DEBUG,
-		      fnic->lport->host,
-		      "Abort Cmd called FCID 0x%x, LUN 0x%x TAG %d\n",
-		      (starget_to_rport(scsi_target(sc->device)))->port_id,
-		      sc->device->lun, sc->request->tag);
+	rport = starget_to_rport(scsi_target(sc->device));
+	if (rport != NULL)
+		FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
+				"Abort Cmd called FCID 0x%x, LUN 0x%x TAG %d\n",
+				rport->port_id, sc->device->lun,
+				sc->request->tag);
 
 	if (lp->state != LPORT_ST_READY || !(lp->link_up)) {
 		ret = FAILED;
@@ -1319,6 +1326,9 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
 	 * the IO. Else, just locally terminate the IO in the firmware
 	 */
 	rport = starget_to_rport(scsi_target(sc->device));
+	if (rport == NULL)
+		goto fnic_abort_cmd_end;
+
 	if (fc_remote_port_chkready(rport) == 0)
 		task_req = FCPIO_ITMF_ABT_TASK;
 	else
@@ -1478,6 +1488,8 @@ static int fnic_clean_pending_aborts(struct fnic *fnic,
 		/* Now queue the abort command to firmware */
 		int_to_scsilun(sc->device->lun, &fc_lun);
 		rport = starget_to_rport(scsi_target(sc->device));
+		if (rport == NULL)
+			goto clean_pending_aborts_end;
 
 		if (fnic_queue_abort_io_req(fnic, tag,
 					    FCPIO_ITMF_ABT_TASK_TERM,
@@ -1547,19 +1559,19 @@ int fnic_device_reset(struct scsi_cmnd *sc)
 	lp = shost_priv(sc->device->host);
 
 	fnic = lport_priv(lp);
-	FNIC_SCSI_DBG(KERN_DEBUG,
-		      fnic->lport->host,
-		      "Device reset called FCID 0x%x, LUN 0x%x\n",
-		      (starget_to_rport(scsi_target(sc->device)))->port_id,
-		      sc->device->lun);
 
+	rport = starget_to_rport(scsi_target(sc->device));
+	if (rport != NULL)
+		FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
+				"Device reset called FCID 0x%x, LUN 0x%x\n",
+				rport->port_id, sc->device->lun);
 
 	if (lp->state != LPORT_ST_READY || !(lp->link_up))
 		goto fnic_device_reset_end;
 
 	/* Check if remote port up */
 	rport = starget_to_rport(scsi_target(sc->device));
-	if (fc_remote_port_chkready(rport))
+	if (rport == NULL || fc_remote_port_chkready(rport))
 		goto fnic_device_reset_end;
 
 	io_lock = fnic_io_lock_hash(fnic, sc);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-07-17 17:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-15 21:12 NULL check after starget_to_rport()? Roel Kluin
2009-07-16  8:28 ` Abhijeet Joglekar (abjoglek)
2009-07-16 11:23 ` [PATCH] fnic: clean up Roel Kluin
2009-07-17 17:14   ` Abhijeet Joglekar (abjoglek)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox