summaryrefslogtreecommitdiff
path: root/pkg/libnl/patch/0005-Remove-_nl_auto-helpers.patch
blob: f29a610c936e6f2c0ec9624327afbb181905053e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
From 558f898c413bd46423c6b07073422fc6fc18769c Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Fri, 4 Oct 2019 18:13:36 -0700
Subject: [PATCH] Remove _nl_auto helpers

These use non-standard __attribute__((cleanup)) and statement
expressions.
---
 include/netlink-private/utils.h | 49 ---------------------------------
 lib/genl/mngt.c                 | 10 +++++--
 lib/xfrm/sa.c                   | 24 ++++++++--------
 3 files changed, 19 insertions(+), 64 deletions(-)

diff --git a/include/netlink-private/utils.h b/include/netlink-private/utils.h
index f33a2f8..1456797 100644
--- a/include/netlink-private/utils.h
+++ b/include/netlink-private/utils.h
@@ -67,7 +67,6 @@
 /*****************************************************************************/
 
 #define _nl_unused                  __attribute__ ((__unused__))
-#define _nl_auto(fcn)               __attribute__ ((__cleanup__(fcn)))
 
 /*****************************************************************************/
 
@@ -83,18 +82,6 @@
 
 /*****************************************************************************/
 
-#define _NL_AUTO_DEFINE_FCN_VOID0(CastType, name, func) \
-static inline void name (void *v) \
-{ \
-	if (*((CastType *) v)) \
-		func (*((CastType *) v)); \
-}
-
-#define _nl_auto_free _nl_auto(_nl_auto_free_fcn)
-_NL_AUTO_DEFINE_FCN_VOID0 (void *, _nl_auto_free_fcn, free)
-
-/*****************************************************************************/
-
 extern const char *nl_strerror_l(int err);
 
 /*****************************************************************************/
@@ -106,42 +93,6 @@ extern const char *nl_strerror_l(int err);
 
 /*****************************************************************************/
 
-#define _nl_clear_pointer(pp, destroy) \
-	({ \
-		__typeof__ (*(pp)) *_pp = (pp); \
-		__typeof__ (*_pp) _p; \
-		int _changed = 0; \
-		\
-		if (   _pp \
-			&& (_p = *_pp)) { \
-			_nl_unused const void *const _p_check_is_pointer = _p; \
-			\
-			*_pp = NULL; \
-			\
-			(destroy) (_p); \
-			\
-			_changed = 1; \
-		} \
-		_changed; \
-	})
-
-#define _nl_clear_free(pp) _nl_clear_pointer (pp, free)
-
-#define _nl_steal_pointer(pp) \
-	({ \
-		__typeof__ (*(pp)) *const _pp = (pp); \
-		__typeof__ (*_pp) _p = NULL; \
-		\
-		if (   _pp \
-		    && (_p = *_pp)) { \
-			*_pp = NULL; \
-		} \
-		\
-		_p; \
-	})
-
-/*****************************************************************************/
-
 #define _nl_malloc_maybe_a(alloca_maxlen, bytes, to_free) \
 	({ \
 		const size_t _bytes = (bytes); \
diff --git a/lib/genl/mngt.c b/lib/genl/mngt.c
index 28326cd..ff50e1d 100644
--- a/lib/genl/mngt.c
+++ b/lib/genl/mngt.c
@@ -50,7 +50,7 @@ static struct genl_cmd *lookup_cmd(struct genl_ops *ops, int cmd_id)
 static int cmd_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *nlh,
                           struct genl_ops *ops, struct nl_cache_ops *cache_ops, void *arg)
 {
-	_nl_auto_free struct nlattr **tb_free = NULL;
+	struct nlattr **tb_free = NULL;
 	int err;
 	struct genlmsghdr *ghdr;
 	struct genl_cmd *cmd;
@@ -74,7 +74,7 @@ static int cmd_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *nlh,
 	                  cmd->c_maxattr,
 	                  cmd->c_attr_policy);
 	if (err < 0)
-		return err;
+		goto out;
 
 	{
 		struct genl_info info = {
@@ -85,8 +85,12 @@ static int cmd_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *nlh,
 			.attrs   = tb,
 		};
 
-		return cmd->c_msg_parser(cache_ops, cmd, &info, arg);
+		err = cmd->c_msg_parser(cache_ops, cmd, &info, arg);
 	}
+
+out:
+	free(tb_free);
+	return err;
 }
 
 static int genl_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
diff --git a/lib/xfrm/sa.c b/lib/xfrm/sa.c
index 48265ba..14bf298 100644
--- a/lib/xfrm/sa.c
+++ b/lib/xfrm/sa.c
@@ -1683,7 +1683,7 @@ int xfrmnl_sa_get_aead_params (struct xfrmnl_sa* sa, char* alg_name, unsigned in
 
 int xfrmnl_sa_set_aead_params (struct xfrmnl_sa* sa, const char* alg_name, unsigned int key_len, unsigned int icv_len, const char* key)
 {
-	_nl_auto_free struct xfrmnl_algo_aead *b = NULL;
+	struct xfrmnl_algo_aead *b = NULL;
 	size_t keysize = sizeof (uint8_t) * ((key_len + 7)/8);
 	uint32_t newlen = sizeof (struct xfrmnl_algo_aead) + keysize;
 
@@ -1699,7 +1699,7 @@ int xfrmnl_sa_set_aead_params (struct xfrmnl_sa* sa, const char* alg_name, unsig
 	memcpy (b->alg_key, key, keysize);
 
 	free (sa->aead);
-	sa->aead = _nl_steal_pointer (&b);
+	sa->aead = b;
 	sa->ce_mask |= XFRM_SA_ATTR_ALG_AEAD;
 	return 0;
 }
@@ -1741,7 +1741,7 @@ int xfrmnl_sa_get_auth_params (struct xfrmnl_sa* sa, char* alg_name, unsigned in
 
 int xfrmnl_sa_set_auth_params (struct xfrmnl_sa* sa, const char* alg_name, unsigned int key_len, unsigned int trunc_len, const char* key)
 {
-	_nl_auto_free struct xfrmnl_algo_auth *b = NULL;
+	struct xfrmnl_algo_auth *b = NULL;
 	size_t keysize = sizeof (uint8_t) * ((key_len + 7)/8);
 	uint32_t newlen = sizeof (struct xfrmnl_algo_auth) + keysize;
 
@@ -1756,7 +1756,7 @@ int xfrmnl_sa_set_auth_params (struct xfrmnl_sa* sa, const char* alg_name, unsig
 	memcpy (b->alg_key, key, keysize);
 
 	free (sa->auth);
-	sa->auth = _nl_steal_pointer (&b);
+	sa->auth = b;
 	sa->ce_mask |= XFRM_SA_ATTR_ALG_AUTH;
 	return 0;
 }
@@ -1795,7 +1795,7 @@ int xfrmnl_sa_get_crypto_params (struct xfrmnl_sa* sa, char* alg_name, unsigned
 
 int xfrmnl_sa_set_crypto_params (struct xfrmnl_sa* sa, const char* alg_name, unsigned int key_len, const char* key)
 {
-	_nl_auto_free struct xfrmnl_algo *b = NULL;
+	struct xfrmnl_algo *b = NULL;
 	size_t keysize = sizeof (uint8_t) * ((key_len + 7)/8);
 	uint32_t newlen = sizeof (struct xfrmnl_algo) + keysize;
 
@@ -1809,7 +1809,7 @@ int xfrmnl_sa_set_crypto_params (struct xfrmnl_sa* sa, const char* alg_name, uns
 	memcpy (b->alg_key, key, keysize);
 
 	free(sa->crypt);
-	sa->crypt = _nl_steal_pointer(&b);
+	sa->crypt = b;
 	sa->ce_mask |= XFRM_SA_ATTR_ALG_CRYPT;
 	return 0;
 }
@@ -1848,7 +1848,7 @@ int xfrmnl_sa_get_comp_params (struct xfrmnl_sa* sa, char* alg_name, unsigned in
 
 int xfrmnl_sa_set_comp_params (struct xfrmnl_sa* sa, const char* alg_name, unsigned int key_len, const char* key)
 {
-	_nl_auto_free struct xfrmnl_algo *b = NULL;
+	struct xfrmnl_algo *b = NULL;
 	size_t keysize = sizeof (uint8_t) * ((key_len + 7)/8);
 	uint32_t newlen = sizeof (struct xfrmnl_algo) + keysize;
 
@@ -1862,7 +1862,7 @@ int xfrmnl_sa_set_comp_params (struct xfrmnl_sa* sa, const char* alg_name, unsig
 	memcpy (b->alg_key, key, keysize);
 
 	free(sa->comp);
-	sa->comp = _nl_steal_pointer(&b);
+	sa->comp = b;
 	sa->ce_mask |= XFRM_SA_ATTR_ALG_COMP;
 	return 0;
 }
@@ -2023,7 +2023,7 @@ int xfrmnl_sa_get_sec_ctx (struct xfrmnl_sa* sa, unsigned int* doi, unsigned int
 int xfrmnl_sa_set_sec_ctx (struct xfrmnl_sa* sa, unsigned int doi, unsigned int alg, unsigned int len,
                            unsigned int sid, const char* ctx_str)
 {
-	_nl_auto_free struct xfrmnl_user_sec_ctx *b = NULL;
+	struct xfrmnl_user_sec_ctx *b = NULL;
 
 	if (!(b = calloc(1, sizeof (struct xfrmnl_user_sec_ctx) + 1 + len)))
 		return -1;
@@ -2037,7 +2037,7 @@ int xfrmnl_sa_set_sec_ctx (struct xfrmnl_sa* sa, unsigned int doi, unsigned int
 	b->ctx[len] = '\0';
 
 	free(sa->sec_ctx);
-	sa->sec_ctx = _nl_steal_pointer(&b);
+	sa->sec_ctx = b;
 	sa->ce_mask |= XFRM_SA_ATTR_SECCTX;
 	return 0;
 }
@@ -2136,7 +2136,7 @@ int xfrmnl_sa_set_replay_state_esn (struct xfrmnl_sa* sa, unsigned int oseq, uns
                                     unsigned int oseq_hi, unsigned int seq_hi, unsigned int replay_window,
                                     unsigned int bmp_len, unsigned int* bmp)
 {
-	_nl_auto_free struct xfrmnl_replay_state_esn *b = NULL;
+	struct xfrmnl_replay_state_esn *b = NULL;
 
 	if (!(b = calloc (1, sizeof (struct xfrmnl_replay_state_esn) + (sizeof (uint32_t) * bmp_len))))
 		return -1;
@@ -2150,7 +2150,7 @@ int xfrmnl_sa_set_replay_state_esn (struct xfrmnl_sa* sa, unsigned int oseq, uns
 	memcpy (b->bmp, bmp, bmp_len * sizeof (uint32_t));
 
 	free(sa->replay_state_esn);
-	sa->replay_state_esn = _nl_steal_pointer(&b);
+	sa->replay_state_esn = b;
 	sa->ce_mask |= XFRM_SA_ATTR_REPLAY_STATE;
 	return 0;
 }
-- 
2.23.0