diff options
author | Eric Dumazet <edumazet@google.com> | 2015-03-12 19:44:07 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-12 22:58:13 -0400 |
commit | 0159dfd3d7dff2da646f53039d29319b830207be (patch) | |
tree | 689aa485e80a6d2c5f0711453a5b1701b05f247c /net/core/sock.c | |
parent | 1e2e01172fd11b4dbfee746c0c8fbcaa9dbf22a0 (diff) |
net: add req_prot_cleanup() & req_prot_init() helpers
Make proto_register() & proto_unregister() a bit nicer.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/sock.c')
-rw-r--r-- | net/core/sock.c | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/net/core/sock.c b/net/core/sock.c index c8842f279f7a..63d871a91b5c 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
@@ -2726,6 +2726,42 @@ static inline void release_proto_idx(struct proto *prot) | |||
2726 | } | 2726 | } |
2727 | #endif | 2727 | #endif |
2728 | 2728 | ||
2729 | static void req_prot_cleanup(struct request_sock_ops *rsk_prot) | ||
2730 | { | ||
2731 | if (!rsk_prot) | ||
2732 | return; | ||
2733 | kfree(rsk_prot->slab_name); | ||
2734 | rsk_prot->slab_name = NULL; | ||
2735 | if (rsk_prot->slab) { | ||
2736 | kmem_cache_destroy(rsk_prot->slab); | ||
2737 | rsk_prot->slab = NULL; | ||
2738 | } | ||
2739 | } | ||
2740 | |||
2741 | static int req_prot_init(const struct proto *prot) | ||
2742 | { | ||
2743 | struct request_sock_ops *rsk_prot = prot->rsk_prot; | ||
2744 | |||
2745 | if (!rsk_prot) | ||
2746 | return 0; | ||
2747 | |||
2748 | rsk_prot->slab_name = kasprintf(GFP_KERNEL, "request_sock_%s", | ||
2749 | prot->name); | ||
2750 | if (!rsk_prot->slab_name) | ||
2751 | return -ENOMEM; | ||
2752 | |||
2753 | rsk_prot->slab = kmem_cache_create(rsk_prot->slab_name, | ||
2754 | rsk_prot->obj_size, 0, | ||
2755 | SLAB_HWCACHE_ALIGN, NULL); | ||
2756 | |||
2757 | if (!rsk_prot->slab) { | ||
2758 | pr_crit("%s: Can't create request sock SLAB cache!\n", | ||
2759 | prot->name); | ||
2760 | return -ENOMEM; | ||
2761 | } | ||
2762 | return 0; | ||
2763 | } | ||
2764 | |||
2729 | int proto_register(struct proto *prot, int alloc_slab) | 2765 | int proto_register(struct proto *prot, int alloc_slab) |
2730 | { | 2766 | { |
2731 | if (alloc_slab) { | 2767 | if (alloc_slab) { |
@@ -2739,21 +2775,8 @@ int proto_register(struct proto *prot, int alloc_slab) | |||
2739 | goto out; | 2775 | goto out; |
2740 | } | 2776 | } |
2741 | 2777 | ||
2742 | if (prot->rsk_prot != NULL) { | 2778 | if (req_prot_init(prot)) |
2743 | prot->rsk_prot->slab_name = kasprintf(GFP_KERNEL, "request_sock_%s", prot->name); | 2779 | goto out_free_request_sock_slab; |
2744 | if (prot->rsk_prot->slab_name == NULL) | ||
2745 | goto out_free_sock_slab; | ||
2746 | |||
2747 | prot->rsk_prot->slab = kmem_cache_create(prot->rsk_prot->slab_name, | ||
2748 | prot->rsk_prot->obj_size, 0, | ||
2749 | SLAB_HWCACHE_ALIGN, NULL); | ||
2750 | |||
2751 | if (prot->rsk_prot->slab == NULL) { | ||
2752 | pr_crit("%s: Can't create request sock SLAB cache!\n", | ||
2753 | prot->name); | ||
2754 | goto out_free_request_sock_slab_name; | ||
2755 | } | ||
2756 | } | ||
2757 | 2780 | ||
2758 | if (prot->twsk_prot != NULL) { | 2781 | if (prot->twsk_prot != NULL) { |
2759 | prot->twsk_prot->twsk_slab_name = kasprintf(GFP_KERNEL, "tw_sock_%s", prot->name); | 2782 | prot->twsk_prot->twsk_slab_name = kasprintf(GFP_KERNEL, "tw_sock_%s", prot->name); |
@@ -2782,14 +2805,8 @@ int proto_register(struct proto *prot, int alloc_slab) | |||
2782 | out_free_timewait_sock_slab_name: | 2805 | out_free_timewait_sock_slab_name: |
2783 | kfree(prot->twsk_prot->twsk_slab_name); | 2806 | kfree(prot->twsk_prot->twsk_slab_name); |
2784 | out_free_request_sock_slab: | 2807 | out_free_request_sock_slab: |
2785 | if (prot->rsk_prot && prot->rsk_prot->slab) { | 2808 | req_prot_cleanup(prot->rsk_prot); |
2786 | kmem_cache_destroy(prot->rsk_prot->slab); | 2809 | |
2787 | prot->rsk_prot->slab = NULL; | ||
2788 | } | ||
2789 | out_free_request_sock_slab_name: | ||
2790 | if (prot->rsk_prot) | ||
2791 | kfree(prot->rsk_prot->slab_name); | ||
2792 | out_free_sock_slab: | ||
2793 | kmem_cache_destroy(prot->slab); | 2810 | kmem_cache_destroy(prot->slab); |
2794 | prot->slab = NULL; | 2811 | prot->slab = NULL; |
2795 | out: | 2812 | out: |
@@ -2809,11 +2826,7 @@ void proto_unregister(struct proto *prot) | |||
2809 | prot->slab = NULL; | 2826 | prot->slab = NULL; |
2810 | } | 2827 | } |
2811 | 2828 | ||
2812 | if (prot->rsk_prot != NULL && prot->rsk_prot->slab != NULL) { | 2829 | req_prot_cleanup(prot->rsk_prot); |
2813 | kmem_cache_destroy(prot->rsk_prot->slab); | ||
2814 | kfree(prot->rsk_prot->slab_name); | ||
2815 | prot->rsk_prot->slab = NULL; | ||
2816 | } | ||
2817 | 2830 | ||
2818 | if (prot->twsk_prot != NULL && prot->twsk_prot->twsk_slab != NULL) { | 2831 | if (prot->twsk_prot != NULL && prot->twsk_prot->twsk_slab != NULL) { |
2819 | kmem_cache_destroy(prot->twsk_prot->twsk_slab); | 2832 | kmem_cache_destroy(prot->twsk_prot->twsk_slab); |