diff options
Diffstat (limited to 'net/dccp/ccid.c')
-rw-r--r-- | net/dccp/ccid.c | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/net/dccp/ccid.c b/net/dccp/ccid.c index f3e9ba1cfd01..36479ca61e03 100644 --- a/net/dccp/ccid.c +++ b/net/dccp/ccid.c | |||
@@ -11,6 +11,8 @@ | |||
11 | * published by the Free Software Foundation. | 11 | * published by the Free Software Foundation. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/slab.h> | ||
15 | |||
14 | #include "ccid.h" | 16 | #include "ccid.h" |
15 | #include "ccids/lib/tfrc.h" | 17 | #include "ccids/lib/tfrc.h" |
16 | 18 | ||
@@ -63,48 +65,37 @@ int ccid_getsockopt_builtin_ccids(struct sock *sk, int len, | |||
63 | u8 *ccid_array, array_len; | 65 | u8 *ccid_array, array_len; |
64 | int err = 0; | 66 | int err = 0; |
65 | 67 | ||
66 | if (len < ARRAY_SIZE(ccids)) | ||
67 | return -EINVAL; | ||
68 | |||
69 | if (ccid_get_builtin_ccids(&ccid_array, &array_len)) | 68 | if (ccid_get_builtin_ccids(&ccid_array, &array_len)) |
70 | return -ENOBUFS; | 69 | return -ENOBUFS; |
71 | 70 | ||
72 | if (put_user(array_len, optlen) || | 71 | if (put_user(array_len, optlen)) |
73 | copy_to_user(optval, ccid_array, array_len)) | 72 | err = -EFAULT; |
73 | else if (len > 0 && copy_to_user(optval, ccid_array, | ||
74 | len > array_len ? array_len : len)) | ||
74 | err = -EFAULT; | 75 | err = -EFAULT; |
75 | 76 | ||
76 | kfree(ccid_array); | 77 | kfree(ccid_array); |
77 | return err; | 78 | return err; |
78 | } | 79 | } |
79 | 80 | ||
80 | static struct kmem_cache *ccid_kmem_cache_create(int obj_size, const char *fmt,...) | 81 | static struct kmem_cache *ccid_kmem_cache_create(int obj_size, char *slab_name_fmt, const char *fmt,...) |
81 | { | 82 | { |
82 | struct kmem_cache *slab; | 83 | struct kmem_cache *slab; |
83 | char slab_name_fmt[32], *slab_name; | ||
84 | va_list args; | 84 | va_list args; |
85 | 85 | ||
86 | va_start(args, fmt); | 86 | va_start(args, fmt); |
87 | vsnprintf(slab_name_fmt, sizeof(slab_name_fmt), fmt, args); | 87 | vsnprintf(slab_name_fmt, CCID_SLAB_NAME_LENGTH, fmt, args); |
88 | va_end(args); | 88 | va_end(args); |
89 | 89 | ||
90 | slab_name = kstrdup(slab_name_fmt, GFP_KERNEL); | 90 | slab = kmem_cache_create(slab_name_fmt, sizeof(struct ccid) + obj_size, 0, |
91 | if (slab_name == NULL) | ||
92 | return NULL; | ||
93 | slab = kmem_cache_create(slab_name, sizeof(struct ccid) + obj_size, 0, | ||
94 | SLAB_HWCACHE_ALIGN, NULL); | 91 | SLAB_HWCACHE_ALIGN, NULL); |
95 | if (slab == NULL) | ||
96 | kfree(slab_name); | ||
97 | return slab; | 92 | return slab; |
98 | } | 93 | } |
99 | 94 | ||
100 | static void ccid_kmem_cache_destroy(struct kmem_cache *slab) | 95 | static void ccid_kmem_cache_destroy(struct kmem_cache *slab) |
101 | { | 96 | { |
102 | if (slab != NULL) { | 97 | if (slab != NULL) |
103 | const char *name = kmem_cache_name(slab); | ||
104 | |||
105 | kmem_cache_destroy(slab); | 98 | kmem_cache_destroy(slab); |
106 | kfree(name); | ||
107 | } | ||
108 | } | 99 | } |
109 | 100 | ||
110 | static int ccid_activate(struct ccid_operations *ccid_ops) | 101 | static int ccid_activate(struct ccid_operations *ccid_ops) |
@@ -113,6 +104,7 @@ static int ccid_activate(struct ccid_operations *ccid_ops) | |||
113 | 104 | ||
114 | ccid_ops->ccid_hc_rx_slab = | 105 | ccid_ops->ccid_hc_rx_slab = |
115 | ccid_kmem_cache_create(ccid_ops->ccid_hc_rx_obj_size, | 106 | ccid_kmem_cache_create(ccid_ops->ccid_hc_rx_obj_size, |
107 | ccid_ops->ccid_hc_rx_slab_name, | ||
116 | "ccid%u_hc_rx_sock", | 108 | "ccid%u_hc_rx_sock", |
117 | ccid_ops->ccid_id); | 109 | ccid_ops->ccid_id); |
118 | if (ccid_ops->ccid_hc_rx_slab == NULL) | 110 | if (ccid_ops->ccid_hc_rx_slab == NULL) |
@@ -120,6 +112,7 @@ static int ccid_activate(struct ccid_operations *ccid_ops) | |||
120 | 112 | ||
121 | ccid_ops->ccid_hc_tx_slab = | 113 | ccid_ops->ccid_hc_tx_slab = |
122 | ccid_kmem_cache_create(ccid_ops->ccid_hc_tx_obj_size, | 114 | ccid_kmem_cache_create(ccid_ops->ccid_hc_tx_obj_size, |
115 | ccid_ops->ccid_hc_tx_slab_name, | ||
123 | "ccid%u_hc_tx_sock", | 116 | "ccid%u_hc_tx_sock", |
124 | ccid_ops->ccid_id); | 117 | ccid_ops->ccid_id); |
125 | if (ccid_ops->ccid_hc_tx_slab == NULL) | 118 | if (ccid_ops->ccid_hc_tx_slab == NULL) |