From b86e4a2f8bac0ecdf0fbcf855b786b3885024942 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 7 Nov 2007 02:23:38 -0800 Subject: [PATCH] --- yaml --- r: 73279 b: refs/heads/master c: b733c007edad6f3e05109951bacc6f87dd807917 h: refs/heads/master i: 73277: cf1f309d248ddfd0c9015f27d8a3a5cd38c8708b 73275: 8f1d0c55a6154da0a2af83eecc8753bfb9d18f94 73271: 1ed5c9f99850e9dcf21a678d623b42012b2f6bec 73263: 4eb7c011224113bd49471e7a48da8dde5ea1a9ed 73247: 65a8567e39b2bb7bc64c6ea4b1e2b32ec5db3032 73215: aaeed48e42b86fe6bab6982c9f262606fe5ae564 v: v3 --- [refs] | 2 +- trunk/net/core/sock.c | 67 +++++++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/[refs] b/[refs] index 7beeb1544318..2e0aa52ec813 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 4999f3621f4da622e77931b3d33ada6c7083c705 +refs/heads/master: b733c007edad6f3e05109951bacc6f87dd807917 diff --git a/trunk/net/core/sock.c b/trunk/net/core/sock.c index e077f263b730..8fc2f84209e4 100644 --- a/trunk/net/core/sock.c +++ b/trunk/net/core/sock.c @@ -1819,23 +1819,48 @@ static int inuse_get(const struct proto *prot) res += per_cpu_ptr(prot->inuse_ptr, cpu)[0]; return res; } -#endif -int proto_register(struct proto *prot, int alloc_slab) +static int inuse_init(struct proto *prot) { - char *request_sock_slab_name = NULL; - char *timewait_sock_slab_name; - int rc = -ENOBUFS; - -#ifdef CONFIG_SMP if (!prot->inuse_getval || !prot->inuse_add) { prot->inuse_ptr = alloc_percpu(int); if (prot->inuse_ptr == NULL) - goto out; + return -ENOBUFS; + prot->inuse_getval = inuse_get; prot->inuse_add = inuse_add; } + return 0; +} + +static void inuse_fini(struct proto *prot) +{ + if (prot->inuse_ptr != NULL) { + free_percpu(prot->inuse_ptr); + prot->inuse_ptr = NULL; + prot->inuse_getval = NULL; + prot->inuse_add = NULL; + } +} +#else +static inline int inuse_init(struct proto *prot) +{ + return 0; +} + +static inline void inuse_fini(struct proto *prot) +{ +} #endif + +int proto_register(struct proto *prot, int alloc_slab) +{ + char *request_sock_slab_name = NULL; + char *timewait_sock_slab_name; + + if (inuse_init(prot)) + goto out; + if (alloc_slab) { prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0, SLAB_HWCACHE_ALIGN, NULL); @@ -1887,9 +1912,8 @@ int proto_register(struct proto *prot, int alloc_slab) write_lock(&proto_list_lock); list_add(&prot->node, &proto_list); write_unlock(&proto_list_lock); - rc = 0; -out: - return rc; + return 0; + out_free_timewait_sock_slab_name: kfree(timewait_sock_slab_name); out_free_request_sock_slab: @@ -1903,15 +1927,9 @@ int proto_register(struct proto *prot, int alloc_slab) kmem_cache_destroy(prot->slab); prot->slab = NULL; out_free_inuse: -#ifdef CONFIG_SMP - if (prot->inuse_ptr != NULL) { - free_percpu(prot->inuse_ptr); - prot->inuse_ptr = NULL; - prot->inuse_getval = NULL; - prot->inuse_add = NULL; - } -#endif - goto out; + inuse_fini(prot); +out: + return -ENOBUFS; } EXPORT_SYMBOL(proto_register); @@ -1922,14 +1940,7 @@ void proto_unregister(struct proto *prot) list_del(&prot->node); write_unlock(&proto_list_lock); -#ifdef CONFIG_SMP - if (prot->inuse_ptr != NULL) { - free_percpu(prot->inuse_ptr); - prot->inuse_ptr = NULL; - prot->inuse_getval = NULL; - prot->inuse_add = NULL; - } -#endif + inuse_fini(prot); if (prot->slab != NULL) { kmem_cache_destroy(prot->slab); prot->slab = NULL;