]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: mempool-datastack - Use container_of instead of casts
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Wed, 20 Jun 2018 15:18:32 +0000 (11:18 -0400)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 4 Jul 2018 08:28:51 +0000 (08:28 +0000)
src/lib/mempool-datastack.c

index e3971d1a9953a384c15cef376bc66540cf0eee3e..e240dc40a32f54030d9a7962f3a785d07736cbae 100644 (file)
@@ -112,7 +112,8 @@ static const char *pool_data_stack_get_name(pool_t pool ATTR_UNUSED)
 
 static void pool_data_stack_ref(pool_t pool)
 {
-       struct datastack_pool *dpool = (struct datastack_pool *) pool;
+       struct datastack_pool *dpool =
+               container_of(pool, struct datastack_pool, pool);
 
        if (unlikely(dpool->data_stack_frame != data_stack_frame_id))
                i_panic("pool_data_stack_ref(): stack frame changed");
@@ -122,7 +123,8 @@ static void pool_data_stack_ref(pool_t pool)
 
 static void pool_data_stack_unref(pool_t *pool)
 {
-       struct datastack_pool *dpool = (struct datastack_pool *)*pool;
+       struct datastack_pool *dpool =
+               container_of(*pool, struct datastack_pool, pool);
 
        if (unlikely(dpool->data_stack_frame != data_stack_frame_id))
                i_panic("pool_data_stack_unref(): stack frame changed");
@@ -135,7 +137,8 @@ static void pool_data_stack_unref(pool_t *pool)
 
 static void *pool_data_stack_malloc(pool_t pool ATTR_UNUSED, size_t size)
 {
-       struct datastack_pool *dpool = (struct datastack_pool *) pool;
+       struct datastack_pool *dpool =
+               container_of(pool, struct datastack_pool, pool);
 
        if (unlikely(size == 0 || size > SSIZE_T_MAX))
                i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);
@@ -148,7 +151,8 @@ static void *pool_data_stack_malloc(pool_t pool ATTR_UNUSED, size_t size)
 
 static void pool_data_stack_free(pool_t pool, void *mem ATTR_UNUSED)
 {
-       struct datastack_pool *dpool = (struct datastack_pool *) pool;
+       struct datastack_pool *dpool =
+               container_of(pool, struct datastack_pool, pool);
 
        if (unlikely(dpool->data_stack_frame != data_stack_frame_id))
                i_panic("pool_data_stack_free(): stack frame changed");
@@ -157,7 +161,8 @@ static void pool_data_stack_free(pool_t pool, void *mem ATTR_UNUSED)
 static void *pool_data_stack_realloc(pool_t pool, void *mem,
                                     size_t old_size, size_t new_size)
 {
-       struct datastack_pool *dpool = (struct datastack_pool *) pool;
+       struct datastack_pool *dpool =
+               container_of(pool, struct datastack_pool, pool);
        void *new_mem;
 
        /* @UNSAFE */