logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0005-Remove-_nl_auto-helpers.patch (8182B)


  1. From 558f898c413bd46423c6b07073422fc6fc18769c Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Fri, 4 Oct 2019 18:13:36 -0700
  4. Subject: [PATCH] Remove _nl_auto helpers
  5. These use non-standard __attribute__((cleanup)) and statement
  6. expressions.
  7. ---
  8. include/netlink-private/utils.h | 49 ---------------------------------
  9. lib/genl/mngt.c | 10 +++++--
  10. lib/xfrm/sa.c | 24 ++++++++--------
  11. 3 files changed, 19 insertions(+), 64 deletions(-)
  12. diff --git a/include/netlink-private/utils.h b/include/netlink-private/utils.h
  13. index f33a2f8..1456797 100644
  14. --- a/include/netlink-private/utils.h
  15. +++ b/include/netlink-private/utils.h
  16. @@ -67,7 +67,6 @@
  17. /*****************************************************************************/
  18. #define _nl_unused __attribute__ ((__unused__))
  19. -#define _nl_auto(fcn) __attribute__ ((__cleanup__(fcn)))
  20. /*****************************************************************************/
  21. @@ -83,18 +82,6 @@
  22. /*****************************************************************************/
  23. -#define _NL_AUTO_DEFINE_FCN_VOID0(CastType, name, func) \
  24. -static inline void name (void *v) \
  25. -{ \
  26. - if (*((CastType *) v)) \
  27. - func (*((CastType *) v)); \
  28. -}
  29. -
  30. -#define _nl_auto_free _nl_auto(_nl_auto_free_fcn)
  31. -_NL_AUTO_DEFINE_FCN_VOID0 (void *, _nl_auto_free_fcn, free)
  32. -
  33. -/*****************************************************************************/
  34. -
  35. extern const char *nl_strerror_l(int err);
  36. /*****************************************************************************/
  37. @@ -106,42 +93,6 @@ extern const char *nl_strerror_l(int err);
  38. /*****************************************************************************/
  39. -#define _nl_clear_pointer(pp, destroy) \
  40. - ({ \
  41. - __typeof__ (*(pp)) *_pp = (pp); \
  42. - __typeof__ (*_pp) _p; \
  43. - int _changed = 0; \
  44. - \
  45. - if ( _pp \
  46. - && (_p = *_pp)) { \
  47. - _nl_unused const void *const _p_check_is_pointer = _p; \
  48. - \
  49. - *_pp = NULL; \
  50. - \
  51. - (destroy) (_p); \
  52. - \
  53. - _changed = 1; \
  54. - } \
  55. - _changed; \
  56. - })
  57. -
  58. -#define _nl_clear_free(pp) _nl_clear_pointer (pp, free)
  59. -
  60. -#define _nl_steal_pointer(pp) \
  61. - ({ \
  62. - __typeof__ (*(pp)) *const _pp = (pp); \
  63. - __typeof__ (*_pp) _p = NULL; \
  64. - \
  65. - if ( _pp \
  66. - && (_p = *_pp)) { \
  67. - *_pp = NULL; \
  68. - } \
  69. - \
  70. - _p; \
  71. - })
  72. -
  73. -/*****************************************************************************/
  74. -
  75. #define _nl_malloc_maybe_a(alloca_maxlen, bytes, to_free) \
  76. ({ \
  77. const size_t _bytes = (bytes); \
  78. diff --git a/lib/genl/mngt.c b/lib/genl/mngt.c
  79. index 28326cd..ff50e1d 100644
  80. --- a/lib/genl/mngt.c
  81. +++ b/lib/genl/mngt.c
  82. @@ -50,7 +50,7 @@ static struct genl_cmd *lookup_cmd(struct genl_ops *ops, int cmd_id)
  83. static int cmd_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *nlh,
  84. struct genl_ops *ops, struct nl_cache_ops *cache_ops, void *arg)
  85. {
  86. - _nl_auto_free struct nlattr **tb_free = NULL;
  87. + struct nlattr **tb_free = NULL;
  88. int err;
  89. struct genlmsghdr *ghdr;
  90. struct genl_cmd *cmd;
  91. @@ -74,7 +74,7 @@ static int cmd_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *nlh,
  92. cmd->c_maxattr,
  93. cmd->c_attr_policy);
  94. if (err < 0)
  95. - return err;
  96. + goto out;
  97. {
  98. struct genl_info info = {
  99. @@ -85,8 +85,12 @@ static int cmd_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *nlh,
  100. .attrs = tb,
  101. };
  102. - return cmd->c_msg_parser(cache_ops, cmd, &info, arg);
  103. + err = cmd->c_msg_parser(cache_ops, cmd, &info, arg);
  104. }
  105. +
  106. +out:
  107. + free(tb_free);
  108. + return err;
  109. }
  110. static int genl_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
  111. diff --git a/lib/xfrm/sa.c b/lib/xfrm/sa.c
  112. index 48265ba..14bf298 100644
  113. --- a/lib/xfrm/sa.c
  114. +++ b/lib/xfrm/sa.c
  115. @@ -1683,7 +1683,7 @@ int xfrmnl_sa_get_aead_params (struct xfrmnl_sa* sa, char* alg_name, unsigned in
  116. 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)
  117. {
  118. - _nl_auto_free struct xfrmnl_algo_aead *b = NULL;
  119. + struct xfrmnl_algo_aead *b = NULL;
  120. size_t keysize = sizeof (uint8_t) * ((key_len + 7)/8);
  121. uint32_t newlen = sizeof (struct xfrmnl_algo_aead) + keysize;
  122. @@ -1699,7 +1699,7 @@ int xfrmnl_sa_set_aead_params (struct xfrmnl_sa* sa, const char* alg_name, unsig
  123. memcpy (b->alg_key, key, keysize);
  124. free (sa->aead);
  125. - sa->aead = _nl_steal_pointer (&b);
  126. + sa->aead = b;
  127. sa->ce_mask |= XFRM_SA_ATTR_ALG_AEAD;
  128. return 0;
  129. }
  130. @@ -1741,7 +1741,7 @@ int xfrmnl_sa_get_auth_params (struct xfrmnl_sa* sa, char* alg_name, unsigned in
  131. 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)
  132. {
  133. - _nl_auto_free struct xfrmnl_algo_auth *b = NULL;
  134. + struct xfrmnl_algo_auth *b = NULL;
  135. size_t keysize = sizeof (uint8_t) * ((key_len + 7)/8);
  136. uint32_t newlen = sizeof (struct xfrmnl_algo_auth) + keysize;
  137. @@ -1756,7 +1756,7 @@ int xfrmnl_sa_set_auth_params (struct xfrmnl_sa* sa, const char* alg_name, unsig
  138. memcpy (b->alg_key, key, keysize);
  139. free (sa->auth);
  140. - sa->auth = _nl_steal_pointer (&b);
  141. + sa->auth = b;
  142. sa->ce_mask |= XFRM_SA_ATTR_ALG_AUTH;
  143. return 0;
  144. }
  145. @@ -1795,7 +1795,7 @@ int xfrmnl_sa_get_crypto_params (struct xfrmnl_sa* sa, char* alg_name, unsigned
  146. int xfrmnl_sa_set_crypto_params (struct xfrmnl_sa* sa, const char* alg_name, unsigned int key_len, const char* key)
  147. {
  148. - _nl_auto_free struct xfrmnl_algo *b = NULL;
  149. + struct xfrmnl_algo *b = NULL;
  150. size_t keysize = sizeof (uint8_t) * ((key_len + 7)/8);
  151. uint32_t newlen = sizeof (struct xfrmnl_algo) + keysize;
  152. @@ -1809,7 +1809,7 @@ int xfrmnl_sa_set_crypto_params (struct xfrmnl_sa* sa, const char* alg_name, uns
  153. memcpy (b->alg_key, key, keysize);
  154. free(sa->crypt);
  155. - sa->crypt = _nl_steal_pointer(&b);
  156. + sa->crypt = b;
  157. sa->ce_mask |= XFRM_SA_ATTR_ALG_CRYPT;
  158. return 0;
  159. }
  160. @@ -1848,7 +1848,7 @@ int xfrmnl_sa_get_comp_params (struct xfrmnl_sa* sa, char* alg_name, unsigned in
  161. int xfrmnl_sa_set_comp_params (struct xfrmnl_sa* sa, const char* alg_name, unsigned int key_len, const char* key)
  162. {
  163. - _nl_auto_free struct xfrmnl_algo *b = NULL;
  164. + struct xfrmnl_algo *b = NULL;
  165. size_t keysize = sizeof (uint8_t) * ((key_len + 7)/8);
  166. uint32_t newlen = sizeof (struct xfrmnl_algo) + keysize;
  167. @@ -1862,7 +1862,7 @@ int xfrmnl_sa_set_comp_params (struct xfrmnl_sa* sa, const char* alg_name, unsig
  168. memcpy (b->alg_key, key, keysize);
  169. free(sa->comp);
  170. - sa->comp = _nl_steal_pointer(&b);
  171. + sa->comp = b;
  172. sa->ce_mask |= XFRM_SA_ATTR_ALG_COMP;
  173. return 0;
  174. }
  175. @@ -2023,7 +2023,7 @@ int xfrmnl_sa_get_sec_ctx (struct xfrmnl_sa* sa, unsigned int* doi, unsigned int
  176. int xfrmnl_sa_set_sec_ctx (struct xfrmnl_sa* sa, unsigned int doi, unsigned int alg, unsigned int len,
  177. unsigned int sid, const char* ctx_str)
  178. {
  179. - _nl_auto_free struct xfrmnl_user_sec_ctx *b = NULL;
  180. + struct xfrmnl_user_sec_ctx *b = NULL;
  181. if (!(b = calloc(1, sizeof (struct xfrmnl_user_sec_ctx) + 1 + len)))
  182. return -1;
  183. @@ -2037,7 +2037,7 @@ int xfrmnl_sa_set_sec_ctx (struct xfrmnl_sa* sa, unsigned int doi, unsigned int
  184. b->ctx[len] = '\0';
  185. free(sa->sec_ctx);
  186. - sa->sec_ctx = _nl_steal_pointer(&b);
  187. + sa->sec_ctx = b;
  188. sa->ce_mask |= XFRM_SA_ATTR_SECCTX;
  189. return 0;
  190. }
  191. @@ -2136,7 +2136,7 @@ int xfrmnl_sa_set_replay_state_esn (struct xfrmnl_sa* sa, unsigned int oseq, uns
  192. unsigned int oseq_hi, unsigned int seq_hi, unsigned int replay_window,
  193. unsigned int bmp_len, unsigned int* bmp)
  194. {
  195. - _nl_auto_free struct xfrmnl_replay_state_esn *b = NULL;
  196. + struct xfrmnl_replay_state_esn *b = NULL;
  197. if (!(b = calloc (1, sizeof (struct xfrmnl_replay_state_esn) + (sizeof (uint32_t) * bmp_len))))
  198. return -1;
  199. @@ -2150,7 +2150,7 @@ int xfrmnl_sa_set_replay_state_esn (struct xfrmnl_sa* sa, unsigned int oseq, uns
  200. memcpy (b->bmp, bmp, bmp_len * sizeof (uint32_t));
  201. free(sa->replay_state_esn);
  202. - sa->replay_state_esn = _nl_steal_pointer(&b);
  203. + sa->replay_state_esn = b;
  204. sa->ce_mask |= XFRM_SA_ATTR_REPLAY_STATE;
  205. return 0;
  206. }
  207. --
  208. 2.23.0