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

* RE: NULL check after starget_to_rport()?
  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
  1 sibling, 0 replies; 4+ messages in thread
From: Abhijeet Joglekar (abjoglek) @ 2009-07-16  8:28 UTC (permalink / raw)
  To: Roel Kluin, Joe Eykholt (jeykholt), linux-scsi

> -----Original Message-----
> From: Roel Kluin [mailto:roel.kluin@gmail.com] 
> Sent: Wednesday, July 15, 2009 2:13 PM
> To: Abhijeet Joglekar (abjoglek); Joe Eykholt (jeykholt); 
> linux-scsi@vger.kernel.org
> Subject: NULL check after starget_to_rport()?
> 
> // 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?)

I think scsi_is_fc_rport(s->dev.parent) should always be true since the
discovered scsi targets are all fc remote ports created by
fc_remote_port_add(). So, NULL check should not be required on the
rport.

> 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?

No, it can be removed.
 
> Should fnic_block_error_handler() return an error value if 
> rport is NULL?

Same as above, it should not be NULL, since the target dev's parent
should be an fc rport.

thanks
-- abhijeet

> 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	[flat|nested] 4+ messages in thread

* [PATCH] fnic: clean up
  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 ` Roel Kluin
  2009-07-17 17:14   ` Abhijeet Joglekar (abjoglek)
  1 sibling, 1 reply; 4+ messages in thread
From: Roel Kluin @ 2009-07-16 11:23 UTC (permalink / raw)
  To: abjoglek; +Cc: jeykholt, linux-scsi, Andrew Morton

In fnic_abort_cmd() and  fnic_device_reset() assign `rport' earlier
to make FNIC_SCSI_DBG() calls cleaner.

In fnic_clean_pending_aborts() `rport' is not used.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
thanks abhijeet, is this ackable?

diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c
index bfc9969..c04b7e8 100644
--- a/drivers/scsi/fnic/fnic_scsi.c
+++ b/drivers/scsi/fnic/fnic_scsi.c
@@ -1265,11 +1265,10 @@ 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));
+	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;
@@ -1318,7 +1317,6 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
 	 * port is up, then send abts to the remote port to terminate
 	 * the IO. Else, just locally terminate the IO in the firmware
 	 */
-	rport = starget_to_rport(scsi_target(sc->device));
 	if (fc_remote_port_chkready(rport) == 0)
 		task_req = FCPIO_ITMF_ABT_TASK;
 	else
@@ -1437,7 +1435,6 @@ static int fnic_clean_pending_aborts(struct fnic *fnic,
 	unsigned long flags;
 	int ret = 0;
 	struct scsi_cmnd *sc;
-	struct fc_rport *rport;
 	struct scsi_lun fc_lun;
 	struct scsi_device *lun_dev = lr_sc->device;
 	DECLARE_COMPLETION_ONSTACK(tm_done);
@@ -1477,7 +1474,6 @@ 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 (fnic_queue_abort_io_req(fnic, tag,
 					    FCPIO_ITMF_ABT_TASK_TERM,
@@ -1547,18 +1543,16 @@ 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));
+	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))
 		goto fnic_device_reset_end;
 

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

* RE: [PATCH] fnic: clean up
  2009-07-16 11:23 ` [PATCH] fnic: clean up Roel Kluin
@ 2009-07-17 17:14   ` Abhijeet Joglekar (abjoglek)
  0 siblings, 0 replies; 4+ messages in thread
From: Abhijeet Joglekar (abjoglek) @ 2009-07-17 17:14 UTC (permalink / raw)
  To: Roel Kluin; +Cc: Joe Eykholt (jeykholt), linux-scsi, Andrew Morton

> -----Original Message-----
> From: Roel Kluin [mailto:roel.kluin@gmail.com] 
> Sent: Thursday, July 16, 2009 4:23 AM
> To: Abhijeet Joglekar (abjoglek)
> Cc: Joe Eykholt (jeykholt); linux-scsi@vger.kernel.org; Andrew Morton
> Subject: [PATCH] fnic: clean up
> 
> In fnic_abort_cmd() and  fnic_device_reset() assign `rport' 
> earlier to make FNIC_SCSI_DBG() calls cleaner.
> 
> In fnic_clean_pending_aborts() `rport' is not used.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> thanks abhijeet, is this ackable?


Yes, this looks good. 

thanks
-- abhijeet

 
> diff --git a/drivers/scsi/fnic/fnic_scsi.c 
> b/drivers/scsi/fnic/fnic_scsi.c index bfc9969..c04b7e8 100644
> --- a/drivers/scsi/fnic/fnic_scsi.c
> +++ b/drivers/scsi/fnic/fnic_scsi.c
> @@ -1265,11 +1265,10 @@ 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));
> +	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;
> @@ -1318,7 +1317,6 @@ int fnic_abort_cmd(struct scsi_cmnd *sc)
>  	 * port is up, then send abts to the remote port to terminate
>  	 * the IO. Else, just locally terminate the IO in the firmware
>  	 */
> -	rport = starget_to_rport(scsi_target(sc->device));
>  	if (fc_remote_port_chkready(rport) == 0)
>  		task_req = FCPIO_ITMF_ABT_TASK;
>  	else
> @@ -1437,7 +1435,6 @@ static int 
> fnic_clean_pending_aborts(struct fnic *fnic,
>  	unsigned long flags;
>  	int ret = 0;
>  	struct scsi_cmnd *sc;
> -	struct fc_rport *rport;
>  	struct scsi_lun fc_lun;
>  	struct scsi_device *lun_dev = lr_sc->device;
>  	DECLARE_COMPLETION_ONSTACK(tm_done);
> @@ -1477,7 +1474,6 @@ 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 (fnic_queue_abort_io_req(fnic, tag,
>  					    FCPIO_ITMF_ABT_TASK_TERM,
> @@ -1547,18 +1543,16 @@ 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));
> +	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))
>  		goto fnic_device_reset_end;
>  
> 

^ permalink raw reply	[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