Patchwork can: gw: use kmem_cache_free() instead of kfree()

login
register
mail settings
Submitter Wei Yongjun
Date April 9, 2013, 6:16 a.m.
Message ID <CAPgLHd9eAfwJMJ9P5RqOKNP5kq87y61V7CTw2J--Ld8uHT0RrQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/234963/
State Accepted
Delegated to: David Miller
Headers show

Comments

Wei Yongjun - April 9, 2013, 6:16 a.m.
From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

memory allocated by kmem_cache_alloc() should be freed using
kmem_cache_free(), not kfree().

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 net/can/gw.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Oliver Hartkopp - April 9, 2013, 6:48 a.m.
On 09.04.2013 08:16, Wei Yongjun wrote:

> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> memory allocated by kmem_cache_alloc() should be freed using
> kmem_cache_free(), not kfree().
> 
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>


Oh yes, that's right ...

Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>

Is also a stable candidate for Linux 3.2+ (can-gw emerged in 3.2)

Thanks for catching this!

Best regards,
Oliver

> ---
>  net/can/gw.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/net/can/gw.c b/net/can/gw.c
> index 2d117dc..117814a 100644
> --- a/net/can/gw.c
> +++ b/net/can/gw.c
> @@ -466,7 +466,7 @@ static int cgw_notifier(struct notifier_block *nb,
>  			if (gwj->src.dev == dev || gwj->dst.dev == dev) {
>  				hlist_del(&gwj->list);
>  				cgw_unregister_filter(gwj);
> -				kfree(gwj);
> +				kmem_cache_free(cgw_cache, gwj);
>  			}
>  		}
>  	}
> @@ -864,7 +864,7 @@ static void cgw_remove_all_jobs(void)
>  	hlist_for_each_entry_safe(gwj, nx, &cgw_list, list) {
>  		hlist_del(&gwj->list);
>  		cgw_unregister_filter(gwj);
> -		kfree(gwj);
> +		kmem_cache_free(cgw_cache, gwj);
>  	}
>  }
>  
> @@ -920,7 +920,7 @@ static int cgw_remove_job(struct sk_buff *skb,  struct nlmsghdr *nlh, void *arg)
>  
>  		hlist_del(&gwj->list);
>  		cgw_unregister_filter(gwj);
> -		kfree(gwj);
> +		kmem_cache_free(cgw_cache, gwj);
>  		err = 0;
>  		break;
>  	}
> 
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde - April 9, 2013, 8:20 a.m.
On 04/09/2013 08:16 AM, Wei Yongjun wrote:
> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> memory allocated by kmem_cache_alloc() should be freed using
> kmem_cache_free(), not kfree().
> 
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Thanks for catching this. Applied to can/master.
I've send a pull request to David, along with Oliver's Acked-by and
stable on Cc.

Thanks,
Marc

Patch

diff --git a/net/can/gw.c b/net/can/gw.c
index 2d117dc..117814a 100644
--- a/net/can/gw.c
+++ b/net/can/gw.c
@@ -466,7 +466,7 @@  static int cgw_notifier(struct notifier_block *nb,
 			if (gwj->src.dev == dev || gwj->dst.dev == dev) {
 				hlist_del(&gwj->list);
 				cgw_unregister_filter(gwj);
-				kfree(gwj);
+				kmem_cache_free(cgw_cache, gwj);
 			}
 		}
 	}
@@ -864,7 +864,7 @@  static void cgw_remove_all_jobs(void)
 	hlist_for_each_entry_safe(gwj, nx, &cgw_list, list) {
 		hlist_del(&gwj->list);
 		cgw_unregister_filter(gwj);
-		kfree(gwj);
+		kmem_cache_free(cgw_cache, gwj);
 	}
 }
 
@@ -920,7 +920,7 @@  static int cgw_remove_job(struct sk_buff *skb,  struct nlmsghdr *nlh, void *arg)
 
 		hlist_del(&gwj->list);
 		cgw_unregister_filter(gwj);
-		kfree(gwj);
+		kmem_cache_free(cgw_cache, gwj);
 		err = 0;
 		break;
 	}