* [PATCH iw_cxgb4-4.8] RDMA/iw_cxgb4: Use kfree_skb instead of kfree
@ 2016-06-29 8:39 Hariprasad Shenai
[not found] ` <1467189584-9812-1-git-send-email-hariprasad-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Hariprasad Shenai @ 2016-06-29 8:39 UTC (permalink / raw)
To: dledford-H+wXaHxf7aLQT0dZR+AlfA
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA,
swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW,
dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA,
nirranjan-ut6Up61K2wZBDgjK7y7TUQ, Hariprasad Shenai
The commit 0f8ab0b6e91b4d53 ("RDMA/iw_cxgb4: Low resource fixes for Memory
registration") from Jun 10, 2016, leads to the following static checker
warning:
drivers/infiniband/hw/cxgb4/mem.c:612 c4iw_alloc_mw()
error: use kfree_skb() here instead of kfree(mhp->dereg_skb)
Also fixes skb leak in c4iw_dealloc_mw
Fixes: 0f8ab0b6e91b4d53 ("RDMA/iw_cxgb4: Low resource fixes for Memory registration")
Reported-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Steve Wise <swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org>
Signed-off-by: Hariprasad Shenai <hariprasad-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>
---
drivers/infiniband/hw/cxgb4/mem.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
index 5d0aa55e82d4..3a4e6fba3010 100644
--- a/drivers/infiniband/hw/cxgb4/mem.c
+++ b/drivers/infiniband/hw/cxgb4/mem.c
@@ -603,16 +603,13 @@ struct ib_mw *c4iw_alloc_mw(struct ib_pd *pd, enum ib_mw_type type,
mhp->dereg_skb = alloc_skb(SGE_MAX_WR_LEN, GFP_KERNEL);
if (!mhp->dereg_skb) {
- kfree(mhp);
- return ERR_PTR(-ENOMEM);
+ ret = -ENOMEM;
+ goto free_mhp;
}
ret = allocate_window(&rhp->rdev, &stag, php->pdid);
- if (ret) {
- kfree(mhp->dereg_skb);
- kfree(mhp);
- return ERR_PTR(ret);
- }
+ if (ret)
+ goto free_skb;
mhp->rhp = rhp;
mhp->attr.pdid = php->pdid;
mhp->attr.type = FW_RI_STAG_MW;
@@ -620,13 +617,19 @@ struct ib_mw *c4iw_alloc_mw(struct ib_pd *pd, enum ib_mw_type type,
mmid = (stag) >> 8;
mhp->ibmw.rkey = stag;
if (insert_handle(rhp, &rhp->mmidr, mhp, mmid)) {
- deallocate_window(&rhp->rdev, mhp->attr.stag, mhp->dereg_skb);
- kfree(mhp->dereg_skb);
- kfree(mhp);
- return ERR_PTR(-ENOMEM);
+ ret = -ENOMEM;
+ goto dealloc_win;
}
PDBG("%s mmid 0x%x mhp %p stag 0x%x\n", __func__, mmid, mhp, stag);
return &(mhp->ibmw);
+
+dealloc_win:
+ deallocate_window(&rhp->rdev, mhp->attr.stag, mhp->dereg_skb);
+free_skb:
+ kfree_skb(mhp->dereg_skb);
+free_mhp:
+ kfree(mhp);
+ return ERR_PTR(ret);
}
int c4iw_dealloc_mw(struct ib_mw *mw)
@@ -640,6 +643,8 @@ int c4iw_dealloc_mw(struct ib_mw *mw)
mmid = (mw->rkey) >> 8;
remove_handle(rhp, &rhp->mmidr, mmid);
deallocate_window(&rhp->rdev, mhp->attr.stag, mhp->dereg_skb);
+ if (mhp->dereg_skb)
+ kfree_skb(mhp->dereg_skb);
kfree(mhp);
PDBG("%s ib_mw %p mmid 0x%x ptr %p\n", __func__, mw, mmid, mhp);
return 0;
--
2.3.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH iw_cxgb4-4.8] RDMA/iw_cxgb4: Use kfree_skb instead of kfree
[not found] ` <1467189584-9812-1-git-send-email-hariprasad-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>
@ 2016-06-29 10:48 ` Leon Romanovsky
0 siblings, 0 replies; 2+ messages in thread
From: Leon Romanovsky @ 2016-06-29 10:48 UTC (permalink / raw)
To: Hariprasad Shenai
Cc: dledford-H+wXaHxf7aLQT0dZR+AlfA,
linux-rdma-u79uwXL29TY76Z2rM5mHXA,
swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW,
dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA,
nirranjan-ut6Up61K2wZBDgjK7y7TUQ
[-- Attachment #1: Type: text/plain, Size: 3284 bytes --]
On Wed, Jun 29, 2016 at 02:09:44PM +0530, Hariprasad Shenai wrote:
> The commit 0f8ab0b6e91b4d53 ("RDMA/iw_cxgb4: Low resource fixes for Memory
> registration") from Jun 10, 2016, leads to the following static checker
> warning:
>
> drivers/infiniband/hw/cxgb4/mem.c:612 c4iw_alloc_mw()
> error: use kfree_skb() here instead of kfree(mhp->dereg_skb)
>
> Also fixes skb leak in c4iw_dealloc_mw
>
> Fixes: 0f8ab0b6e91b4d53 ("RDMA/iw_cxgb4: Low resource fixes for Memory registration")
>
> Reported-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Steve Wise <swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org>
> Signed-off-by: Hariprasad Shenai <hariprasad-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>
> ---
> drivers/infiniband/hw/cxgb4/mem.c | 27 ++++++++++++++++-----------
> 1 file changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
> index 5d0aa55e82d4..3a4e6fba3010 100644
> --- a/drivers/infiniband/hw/cxgb4/mem.c
> +++ b/drivers/infiniband/hw/cxgb4/mem.c
> @@ -603,16 +603,13 @@ struct ib_mw *c4iw_alloc_mw(struct ib_pd *pd, enum ib_mw_type type,
>
> mhp->dereg_skb = alloc_skb(SGE_MAX_WR_LEN, GFP_KERNEL);
> if (!mhp->dereg_skb) {
> - kfree(mhp);
> - return ERR_PTR(-ENOMEM);
> + ret = -ENOMEM;
> + goto free_mhp;
> }
>
> ret = allocate_window(&rhp->rdev, &stag, php->pdid);
> - if (ret) {
> - kfree(mhp->dereg_skb);
> - kfree(mhp);
> - return ERR_PTR(ret);
> - }
> + if (ret)
> + goto free_skb;
> mhp->rhp = rhp;
> mhp->attr.pdid = php->pdid;
> mhp->attr.type = FW_RI_STAG_MW;
> @@ -620,13 +617,19 @@ struct ib_mw *c4iw_alloc_mw(struct ib_pd *pd, enum ib_mw_type type,
> mmid = (stag) >> 8;
> mhp->ibmw.rkey = stag;
> if (insert_handle(rhp, &rhp->mmidr, mhp, mmid)) {
> - deallocate_window(&rhp->rdev, mhp->attr.stag, mhp->dereg_skb);
> - kfree(mhp->dereg_skb);
> - kfree(mhp);
> - return ERR_PTR(-ENOMEM);
> + ret = -ENOMEM;
> + goto dealloc_win;
> }
> PDBG("%s mmid 0x%x mhp %p stag 0x%x\n", __func__, mmid, mhp, stag);
> return &(mhp->ibmw);
> +
> +dealloc_win:
> + deallocate_window(&rhp->rdev, mhp->attr.stag, mhp->dereg_skb);
> +free_skb:
> + kfree_skb(mhp->dereg_skb);
> +free_mhp:
> + kfree(mhp);
> + return ERR_PTR(ret);
> }
>
> int c4iw_dealloc_mw(struct ib_mw *mw)
> @@ -640,6 +643,8 @@ int c4iw_dealloc_mw(struct ib_mw *mw)
> mmid = (mw->rkey) >> 8;
> remove_handle(rhp, &rhp->mmidr, mmid);
> deallocate_window(&rhp->rdev, mhp->attr.stag, mhp->dereg_skb);
> + if (mhp->dereg_skb)
> + kfree_skb(mhp->dereg_skb);
You don't need to check existence of mhp->dereg_skb.
kfree_skb will check it by itself.
net/core/skbuff.c:
695 void kfree_skb(struct sk_buff *skb)
696 {
697 if (unlikely(!skb))
698 return;
> kfree(mhp);
> PDBG("%s ib_mw %p mmid 0x%x ptr %p\n", __func__, mw, mmid, mhp);
> return 0;
> --
> 2.3.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-06-29 10:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-29 8:39 [PATCH iw_cxgb4-4.8] RDMA/iw_cxgb4: Use kfree_skb instead of kfree Hariprasad Shenai
[not found] ` <1467189584-9812-1-git-send-email-hariprasad-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>
2016-06-29 10:48 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox