test/timer: check memzone allocation
authorMin Hu (Connor) <humin29@huawei.com>
Tue, 4 May 2021 01:07:49 +0000 (09:07 +0800)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 12 May 2021 14:52:20 +0000 (16:52 +0200)
Segmentation fault may occur without checking if memzone
reserves succeed or not.

Fixes: 50247fe03fe0 ("test/timer: exercise new APIs in secondary process")
Cc: stable@dpdk.org
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
Acked-by: Erik Gabriel Carrillo <erik.g.carrillo@intel.com>
app/test/test_timer_secondary.c

index 1e8f1d4..16a9f18 100644 (file)
@@ -125,9 +125,9 @@ test_timer_secondary(void)
 
                mz = rte_memzone_reserve(TEST_INFO_MZ_NAME, sizeof(*test_info),
                                         SOCKET_ID_ANY, 0);
-               test_info = mz->addr;
-               TEST_ASSERT_NOT_NULL(test_info, "Couldn't allocate memory for "
+               TEST_ASSERT_NOT_NULL(mz, "Couldn't allocate memory for "
                                     "test data");
+               test_info = mz->addr;
 
                test_info->tim_mempool = rte_mempool_create("test_timer_mp",
                                NUM_TIMERS, sizeof(struct rte_timer), 0, 0,
@@ -171,9 +171,9 @@ test_timer_secondary(void)
                int i;
 
                mz = rte_memzone_lookup(TEST_INFO_MZ_NAME);
-               test_info = mz->addr;
-               TEST_ASSERT_NOT_NULL(test_info, "Couldn't lookup memzone for "
+               TEST_ASSERT_NOT_NULL(mz, "Couldn't lookup memzone for "
                                     "test info");
+               test_info = mz->addr;
 
                for (i = 0; i < NUM_TIMERS; i++) {
                        rte_mempool_get(test_info->tim_mempool, (void **)&tim);