aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Elfring <elfring@users.sourceforge.net>2015-02-02 05:00:24 -0500
committerDavid S. Miller <davem@davemloft.net>2015-02-03 19:22:13 -0500
commit4de46d5ebc000ea110bcb76a7478c1ac37724221 (patch)
treeeaf93ec8c6483184656e83b98d5a78eda53d3e6b
parent7a11b1d303ee97e4880caa3efc2f5cecc28d4ba2 (diff)
netlabel: Less function calls in netlbl_mgmt_add_common() after error detection
The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer. * This implementation detail could be improved by adjustments for jump labels. * Let us return immediately after the first failed function call according to the current Linux coding style convention. * Let us delete also an unnecessary check for the variable "entry" there. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Acked-by: Paul Moore <paul@paul-moore.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/netlabel/netlabel_mgmt.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c
index f5807f57aebc..70440748fe5c 100644
--- a/net/netlabel/netlabel_mgmt.c
+++ b/net/netlabel/netlabel_mgmt.c
@@ -93,23 +93,20 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
93 struct netlbl_audit *audit_info) 93 struct netlbl_audit *audit_info)
94{ 94{
95 int ret_val = -EINVAL; 95 int ret_val = -EINVAL;
96 struct netlbl_dom_map *entry = NULL;
97 struct netlbl_domaddr_map *addrmap = NULL; 96 struct netlbl_domaddr_map *addrmap = NULL;
98 struct cipso_v4_doi *cipsov4 = NULL; 97 struct cipso_v4_doi *cipsov4 = NULL;
99 u32 tmp_val; 98 u32 tmp_val;
99 struct netlbl_dom_map *entry = kzalloc(sizeof(*entry), GFP_KERNEL);
100 100
101 entry = kzalloc(sizeof(*entry), GFP_KERNEL); 101 if (!entry)
102 if (entry == NULL) { 102 return -ENOMEM;
103 ret_val = -ENOMEM;
104 goto add_failure;
105 }
106 entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]); 103 entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
107 if (info->attrs[NLBL_MGMT_A_DOMAIN]) { 104 if (info->attrs[NLBL_MGMT_A_DOMAIN]) {
108 size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]); 105 size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]);
109 entry->domain = kmalloc(tmp_size, GFP_KERNEL); 106 entry->domain = kmalloc(tmp_size, GFP_KERNEL);
110 if (entry->domain == NULL) { 107 if (entry->domain == NULL) {
111 ret_val = -ENOMEM; 108 ret_val = -ENOMEM;
112 goto add_failure; 109 goto add_free_entry;
113 } 110 }
114 nla_strlcpy(entry->domain, 111 nla_strlcpy(entry->domain,
115 info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size); 112 info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size);
@@ -125,16 +122,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
125 break; 122 break;
126 case NETLBL_NLTYPE_CIPSOV4: 123 case NETLBL_NLTYPE_CIPSOV4:
127 if (!info->attrs[NLBL_MGMT_A_CV4DOI]) 124 if (!info->attrs[NLBL_MGMT_A_CV4DOI])
128 goto add_failure; 125 goto add_free_domain;
129 126
130 tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]); 127 tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
131 cipsov4 = cipso_v4_doi_getdef(tmp_val); 128 cipsov4 = cipso_v4_doi_getdef(tmp_val);
132 if (cipsov4 == NULL) 129 if (cipsov4 == NULL)
133 goto add_failure; 130 goto add_free_domain;
134 entry->def.cipso = cipsov4; 131 entry->def.cipso = cipsov4;
135 break; 132 break;
136 default: 133 default:
137 goto add_failure; 134 goto add_free_domain;
138 } 135 }
139 136
140 if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) { 137 if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) {
@@ -145,7 +142,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
145 addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL); 142 addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
146 if (addrmap == NULL) { 143 if (addrmap == NULL) {
147 ret_val = -ENOMEM; 144 ret_val = -ENOMEM;
148 goto add_failure; 145 goto add_doi_put_def;
149 } 146 }
150 INIT_LIST_HEAD(&addrmap->list4); 147 INIT_LIST_HEAD(&addrmap->list4);
151 INIT_LIST_HEAD(&addrmap->list6); 148 INIT_LIST_HEAD(&addrmap->list6);
@@ -153,12 +150,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
153 if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) != 150 if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) !=
154 sizeof(struct in_addr)) { 151 sizeof(struct in_addr)) {
155 ret_val = -EINVAL; 152 ret_val = -EINVAL;
156 goto add_failure; 153 goto add_free_addrmap;
157 } 154 }
158 if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) != 155 if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) !=
159 sizeof(struct in_addr)) { 156 sizeof(struct in_addr)) {
160 ret_val = -EINVAL; 157 ret_val = -EINVAL;
161 goto add_failure; 158 goto add_free_addrmap;
162 } 159 }
163 addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]); 160 addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]);
164 mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]); 161 mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]);
@@ -166,7 +163,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
166 map = kzalloc(sizeof(*map), GFP_KERNEL); 163 map = kzalloc(sizeof(*map), GFP_KERNEL);
167 if (map == NULL) { 164 if (map == NULL) {
168 ret_val = -ENOMEM; 165 ret_val = -ENOMEM;
169 goto add_failure; 166 goto add_free_addrmap;
170 } 167 }
171 map->list.addr = addr->s_addr & mask->s_addr; 168 map->list.addr = addr->s_addr & mask->s_addr;
172 map->list.mask = mask->s_addr; 169 map->list.mask = mask->s_addr;
@@ -178,7 +175,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
178 ret_val = netlbl_af4list_add(&map->list, &addrmap->list4); 175 ret_val = netlbl_af4list_add(&map->list, &addrmap->list4);
179 if (ret_val != 0) { 176 if (ret_val != 0) {
180 kfree(map); 177 kfree(map);
181 goto add_failure; 178 goto add_free_addrmap;
182 } 179 }
183 180
184 entry->def.type = NETLBL_NLTYPE_ADDRSELECT; 181 entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -192,7 +189,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
192 addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL); 189 addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
193 if (addrmap == NULL) { 190 if (addrmap == NULL) {
194 ret_val = -ENOMEM; 191 ret_val = -ENOMEM;
195 goto add_failure; 192 goto add_doi_put_def;
196 } 193 }
197 INIT_LIST_HEAD(&addrmap->list4); 194 INIT_LIST_HEAD(&addrmap->list4);
198 INIT_LIST_HEAD(&addrmap->list6); 195 INIT_LIST_HEAD(&addrmap->list6);
@@ -200,12 +197,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
200 if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) != 197 if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) !=
201 sizeof(struct in6_addr)) { 198 sizeof(struct in6_addr)) {
202 ret_val = -EINVAL; 199 ret_val = -EINVAL;
203 goto add_failure; 200 goto add_free_addrmap;
204 } 201 }
205 if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) != 202 if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) !=
206 sizeof(struct in6_addr)) { 203 sizeof(struct in6_addr)) {
207 ret_val = -EINVAL; 204 ret_val = -EINVAL;
208 goto add_failure; 205 goto add_free_addrmap;
209 } 206 }
210 addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]); 207 addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]);
211 mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]); 208 mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]);
@@ -213,7 +210,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
213 map = kzalloc(sizeof(*map), GFP_KERNEL); 210 map = kzalloc(sizeof(*map), GFP_KERNEL);
214 if (map == NULL) { 211 if (map == NULL) {
215 ret_val = -ENOMEM; 212 ret_val = -ENOMEM;
216 goto add_failure; 213 goto add_free_addrmap;
217 } 214 }
218 map->list.addr = *addr; 215 map->list.addr = *addr;
219 map->list.addr.s6_addr32[0] &= mask->s6_addr32[0]; 216 map->list.addr.s6_addr32[0] &= mask->s6_addr32[0];
@@ -227,7 +224,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
227 ret_val = netlbl_af6list_add(&map->list, &addrmap->list6); 224 ret_val = netlbl_af6list_add(&map->list, &addrmap->list6);
228 if (ret_val != 0) { 225 if (ret_val != 0) {
229 kfree(map); 226 kfree(map);
230 goto add_failure; 227 goto add_free_addrmap;
231 } 228 }
232 229
233 entry->def.type = NETLBL_NLTYPE_ADDRSELECT; 230 entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -237,15 +234,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
237 234
238 ret_val = netlbl_domhsh_add(entry, audit_info); 235 ret_val = netlbl_domhsh_add(entry, audit_info);
239 if (ret_val != 0) 236 if (ret_val != 0)
240 goto add_failure; 237 goto add_free_addrmap;
241 238
242 return 0; 239 return 0;
243 240
244add_failure: 241add_free_addrmap:
245 cipso_v4_doi_putdef(cipsov4);
246 if (entry)
247 kfree(entry->domain);
248 kfree(addrmap); 242 kfree(addrmap);
243add_doi_put_def:
244 cipso_v4_doi_putdef(cipsov4);
245add_free_domain:
246 kfree(entry->domain);
247add_free_entry:
249 kfree(entry); 248 kfree(entry);
250 return ret_val; 249 return ret_val;
251} 250}