[Open-FCoE] [PATCH 3/3] libfc: Add a macro to get the rport from the rdata

Robert Love robert.w.love at intel.com
Thu Oct 2 17:51:22 UTC 2008


Just a convenience so I don't have to add and subtract
pointers in multiple places.

Signed-off-by: Robert Love <robert.w.love at intel.com>
---

 drivers/scsi/libfc/fc_rport.c |    4 ++--
 include/scsi/libfc/libfc.h    |    5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index 67c9149..107b304 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -72,7 +72,7 @@ struct fc_rport *fc_rport_dummy_create(struct fc_disc_port *dp)
 	if (!rport)
 		return NULL;
 
-	rdata = ((void *)rport + sizeof(struct fc_rport));
+	rdata = RPORT_TO_PRIV(rport);
 
 	rport->dd_data = rdata;
 	rport->port_id = dp->ids.port_id;
@@ -421,7 +421,7 @@ static void fc_rport_timeout(struct work_struct *work)
 {
 	struct fc_rport_libfc_priv *rdata =
 		container_of(work, struct fc_rport_libfc_priv, retry_work.work);
-	struct fc_rport *rport = (((void *)rdata) - sizeof(struct fc_rport));
+	struct fc_rport *rport = PRIV_TO_RPORT(rdata);
 
 	mutex_lock(&rdata->rp_mutex);
 
diff --git a/include/scsi/libfc/libfc.h b/include/scsi/libfc/libfc.h
index 740a0e0..24d3fcb 100644
--- a/include/scsi/libfc/libfc.h
+++ b/include/scsi/libfc/libfc.h
@@ -168,6 +168,11 @@ struct fc_rport_libfc_priv {
 	u32 roles;
 };
 
+#define PRIV_TO_RPORT(x)						\
+	(struct fc_rport*)((void *)x - sizeof(struct fc_rport));
+#define RPORT_TO_PRIV(x)						\
+	(struct fc_rport_libfc_priv*)((void *)x + sizeof(struct fc_rport));
+
 struct fc_rport *fc_rport_dummy_create(struct fc_disc_port *);
 void fc_rport_dummy_destroy(struct fc_rport *);
 




More information about the devel mailing list