diff mbox

[10/15] gtphub: undup code: memset on a struct.

Message ID 1444947239-17582-11-git-send-email-nhofmeyr@sysmocom.de
State Superseded
Headers show

Commit Message

Neels Hofmeyr Oct. 15, 2015, 10:13 p.m. UTC

diff mbox

Patch

diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c
index 208b623..1d9c6d5 100644
--- a/openbsc/src/gprs/gtphub.c
+++ b/openbsc/src/gprs/gtphub.c
@@ -41,6 +41,8 @@  void *osmo_gtphub_ctx;
 #define LOG(fmt, args...) \
 	LOGP(DGTPHUB, LOGL_NOTICE, fmt, ##args)
 
+#define ZERO_STRUCT(struct_pointer) memset(struct_pointer, '\0', sizeof(*(struct_pointer)))
+
 /* TODO move this to osmocom/core/select.h ? */
 typedef int (*osmo_fd_cb_t)(struct osmo_fd *fd, unsigned int what);
 
@@ -182,7 +184,7 @@  void validate_gtp_header(struct gtp_packet_desc *p)
  * error, p->rc is set <= 0 (see enum gtp_rc). */
 static void gtp_decode(const uint8_t *data, int data_len, struct gtp_packet_desc *res)
 {
-	memset(res, '\0', sizeof(*res));
+	ZERO_STRUCT(res);
 	res->data = (union gtp_packet*)data;
 	res->data_len = data_len;
 
@@ -221,7 +223,7 @@  uint32_t tei_pool_next(struct tei_pool *pool)
 
 void tei_map_init(struct tei_map *map, struct tei_pool *pool)
 {
-	*map = (struct tei_map){};
+	ZERO_STRUCT(map);
 	map->pool = pool;
 	INIT_LLIST_HEAD(&map->mappings);
 }
@@ -283,7 +285,7 @@  void tei_map_del(struct tei_map *map, uint32_t tei_orig)
 
 void gtphub_zero(struct gtphub *hub)
 {
-	memset(hub, '\0', sizeof(*hub));
+	ZERO_STRUCT(hub);
 }
 
 static int gtphub_sock_init(struct osmo_fd *ofd,
@@ -316,7 +318,7 @@  static int gtphub_gtp_bind_init(struct gtphub_bind *b,
 				osmo_fd_cb_t cb, void *cb_data,
 				unsigned int ofd_id)
 {
-	memset(b, '\0', sizeof(*b));
+	ZERO_STRUCT(b);
 
 	tei_pool_init(&b->teip);
 	INIT_LLIST_HEAD(&b->peers);