diff mbox

[06/15] IB/rxe: Enable type checking on SKB_TO_PKT() and PKT_TO_SKB() arguments

Message ID 1483353555.3592.24.camel@sandisk.com (mailing list archive)
State Changes Requested
Headers show

Commit Message

Bart Van Assche Jan. 2, 2017, 10:40 a.m. UTC
Let the compiler check the type of the arguments passed to SKB_TO_PKT()
and PKT_TO_SKB().

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>

Cc: Moni Shoua <monis@mellanox.com>
Cc: Andrew Boyer <andrew.boyer@dell.com>
---
 drivers/infiniband/sw/rxe/rxe_hdr.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

-- 
2.11.0

Comments

Leon Romanovsky Jan. 8, 2017, 9:44 a.m. UTC | #1
On Mon, Jan 02, 2017 at 10:40:49AM +0000, Bart Van Assche wrote:
> Let the compiler check the type of the arguments passed to SKB_TO_PKT()
> and PKT_TO_SKB().
>
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Cc: Moni Shoua <monis@mellanox.com>
> Cc: Andrew Boyer <andrew.boyer@dell.com>
> ---
>  drivers/infiniband/sw/rxe/rxe_hdr.h | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/sw/rxe/rxe_hdr.h b/drivers/infiniband/sw/rxe/rxe_hdr.h
> index d57b5e956ceb..6cb18406f5b8 100644
> --- a/drivers/infiniband/sw/rxe/rxe_hdr.h
> +++ b/drivers/infiniband/sw/rxe/rxe_hdr.h
> @@ -53,8 +53,16 @@ struct rxe_pkt_info {
>  };
>  
>  /* Macros should be used only for received skb */
> -#define SKB_TO_PKT(skb) ((struct rxe_pkt_info *)(skb)->cb)
> -#define PKT_TO_SKB(pkt) container_of((void *)(pkt), struct sk_buff, cb)
> +static inline struct rxe_pkt_info *SKB_TO_PKT(struct sk_buff *skb)
> +{
> +	BUILD_BUG_ON(sizeof(struct rxe_pkt_info) > sizeof(skb->cb));

It is very good check, thanks for catching it.

> +	return (void *)skb->cb;
> +}
> +

Thanks,
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Andrew Boyer Jan. 9, 2017, 2:31 p.m. UTC | #2
On 1/2/17, 5:40 AM, "linux-rdma-owner@vger.kernel.org on behalf of Bart
Van Assche" <linux-rdma-owner@vger.kernel.org on behalf of
Bart.VanAssche@sandisk.com> wrote:

>Let the compiler check the type of the arguments passed to SKB_TO_PKT()
>and PKT_TO_SKB().
>
>Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
>Cc: Moni Shoua <monis@mellanox.com>
>Cc: Andrew Boyer <andrew.boyer@dell.com>
>---
> drivers/infiniband/sw/rxe/rxe_hdr.h | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)

Reviewed-by: Andrew Boyer <andrew.boyer@dell.com>


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/infiniband/sw/rxe/rxe_hdr.h b/drivers/infiniband/sw/rxe/rxe_hdr.h
index d57b5e956ceb..6cb18406f5b8 100644
--- a/drivers/infiniband/sw/rxe/rxe_hdr.h
+++ b/drivers/infiniband/sw/rxe/rxe_hdr.h
@@ -53,8 +53,16 @@  struct rxe_pkt_info {
 };
 
 /* Macros should be used only for received skb */
-#define SKB_TO_PKT(skb) ((struct rxe_pkt_info *)(skb)->cb)
-#define PKT_TO_SKB(pkt) container_of((void *)(pkt), struct sk_buff, cb)
+static inline struct rxe_pkt_info *SKB_TO_PKT(struct sk_buff *skb)
+{
+	BUILD_BUG_ON(sizeof(struct rxe_pkt_info) > sizeof(skb->cb));
+	return (void *)skb->cb;
+}
+
+static inline struct sk_buff *PKT_TO_SKB(struct rxe_pkt_info *pkt)
+{
+	return container_of((void *)pkt, struct sk_buff, cb);
+}
 
 /*
  * IBA header types and methods