[openib-general] [PATCH] SDP: use container_of in place of cast to sdp_opt

Michael S. Tsirkin mst at mellanox.co.il
Mon Jun 20 23:21:32 PDT 2005


Here's a patch to replace explicit cast to sdp_opt with container_of, removing
assumptions on structure layout.
As a side note, wouldnt sk_to_sdp and sdp_to_sk be better names for
sdp_sk and sk_sdp?

---

Use container_of in place of cast to sdp_opt.

Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>

Index: ulp/sdp/sdp_actv.c
===================================================================
--- ulp/sdp/sdp_actv.c	(revision 2665)
+++ ulp/sdp/sdp_actv.c	(working copy)
@@ -343,7 +343,7 @@
 {
 	struct ib_cm_req_param param;
 	struct sdp_msg_hello *hello_msg;
-	struct sdp_opt *conn = (struct sdp_opt *) arg;
+	struct sdp_opt *conn = arg;
 	struct sdpc_buff *buff;
 	int result = 0;
 	/*
Index: ulp/sdp/sdp_conn.h
===================================================================
--- ulp/sdp/sdp_conn.h	(revision 2665)
+++ ulp/sdp/sdp_conn.h	(working copy)
@@ -109,16 +109,6 @@
  */
 #define SDP_MSG_EVENT_TABLE_SIZE 0x20
 
-static inline struct sdp_opt *sdp_sk(struct sock *sk)
-{
-	return (struct sdp_opt *)sk;
-}
-
-static inline struct sock *sk_sdp(struct sdp_opt *conn)
-{
-	return (struct sock *)conn;
-}
-
 #define SDP_CONN_SET_ERR(conn, val) \
         ((conn)->error = sk_sdp(conn)->sk_err = (val))
 #define SDP_CONN_GET_ERR(conn) \
@@ -182,11 +172,6 @@
  * SDP Connection structure.
  */
 struct sdp_opt {
-	/*
-	 * inet_sock must be first member of sdp_opt
-	 * NOTE: this depends on inet_sock having struct sock as its
-	 * first member
-	 */
 	struct inet_sock in;
 	__s32 hashent;     /* connection ID/hash entry */
 	atomic_t refcnt;   /* connection reference count. */
@@ -386,6 +371,16 @@
 #endif
 };
 
+static inline struct sdp_opt *sdp_sk(struct sock *sk)
+{
+	return container_of(sk, struct sdp_opt, in.sk);
+}
+
+static inline struct sock *sk_sdp(struct sdp_opt *conn)
+{
+	return &conn->in.sk;
+}
+
 #define SDP_WRAP_GT(x, y) ((signed int)((x) - (y)) > 0)
 #define SDP_WRAP_LT(x, y) ((signed int)((x) - (y)) < 0)
 #define SDP_WRAP_GTE(x, y) ((signed int)((x) - (y)) >= 0)
-- 
MST



More information about the general mailing list