From d678f309b8fe566386a25a93b8821fd01f4ba639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gl=C3=B6ckner?= Date: Mon, 28 Jan 2019 02:11:09 +0100 Subject: [PATCH] net: pkt: convert remaining users of ref to atomic_ref MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous commit replaced the net_pkt element ref with an element atomic_ref. CI tests turned up more places where ref was used directly. This commit converts them to use the new element. Signed-off-by: Daniel Glöckner --- drivers/ethernet/eth_mcux.c | 2 +- subsys/net/ip/net_pkt.c | 2 +- subsys/net/ip/net_shell.c | 7 ++++--- tests/net/arp/src/main.c | 4 ++-- tests/net/tx_timestamp/src/main.c | 18 ++++++++++-------- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/ethernet/eth_mcux.c b/drivers/ethernet/eth_mcux.c index 7f0e6123d8..36f828627a 100644 --- a/drivers/ethernet/eth_mcux.c +++ b/drivers/ethernet/eth_mcux.c @@ -677,7 +677,7 @@ static inline void ts_register_tx_event(struct eth_context *context) enet_ptp_time_data_t timeData; pkt = ts_tx_pkt[ts_tx_rd]; - if (pkt && pkt->ref > 0) { + if (pkt && atomic_get(&pkt->atomic_ref) > 0) { if (eth_get_ptp_data(net_pkt_iface(pkt), pkt, &timeData, true)) { int status; diff --git a/subsys/net/ip/net_pkt.c b/subsys/net/ip/net_pkt.c index b0d3b3123f..ee9674322d 100644 --- a/subsys/net/ip/net_pkt.c +++ b/subsys/net/ip/net_pkt.c @@ -355,7 +355,7 @@ struct net_pkt *net_pkt_get_reserve(struct k_mem_slab *slab, #if CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG NET_DBG("%s [%u] pkt %p ref %d (%s():%d)", slab2str(slab), k_mem_slab_num_free_get(slab), - pkt, pkt->ref, caller, line); + pkt, atomic_get(&pkt->atomic_ref), caller, line); #endif return pkt; } diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index da40d2414c..fbf576764f 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -969,12 +969,13 @@ static void tcp_sent_list_cb(struct net_tcp *tcp, void *user_data) struct net_buf *frag = pkt->frags; if (!*printed) { - PR("%p[%d/%zd]", pkt, pkt->ref, + PR("%p[%d/%zd]", pkt, atomic_get(&pkt->atomic_ref), net_pkt_get_len(pkt)); *printed = true; } else { PR(" %p[%d/%zd]", - pkt, pkt->ref, net_pkt_get_len(pkt)); + pkt, atomic_get(&pkt->atomic_ref), + net_pkt_get_len(pkt)); } if (frag) { @@ -1074,7 +1075,7 @@ static void allocs_cb(struct net_pkt *pkt, if (func_alloc) { if (in_use) { PR("%p/%d\t%5s\t%5s\t%s():%d\n", - pkt, pkt->ref, str, + pkt, atomic_get(&pkt->atomic_ref), str, net_pkt_slab2str(pkt->slab), func_alloc, line_alloc); } else { diff --git a/tests/net/arp/src/main.c b/tests/net/arp/src/main.c index 3db5c592fc..516b9794e2 100644 --- a/tests/net/arp/src/main.c +++ b/tests/net/arp/src/main.c @@ -475,7 +475,7 @@ void test_arp(void) */ net_pkt_unref(pkt2); - zassert_equal(pkt->ref, 2, + zassert_equal(atomic_get(&pkt->atomic_ref), 2, "ARP cache should own the original packet"); /* Then a case where target is not in the same subnet */ @@ -579,7 +579,7 @@ void test_arp(void) /**TESTPOINTS: Check ARP reply*/ zassert_false(send_status < 0, "ARP reply was not sent"); - zassert_equal(pkt->ref, 1, + zassert_equal(atomic_get(&pkt->atomic_ref), 1, "ARP cache should no longer own the original packet"); net_pkt_unref(pkt); diff --git a/tests/net/tx_timestamp/src/main.c b/tests/net/tx_timestamp/src/main.c index e166fba6e4..6c6d6df0a1 100644 --- a/tests/net/tx_timestamp/src/main.c +++ b/tests/net/tx_timestamp/src/main.c @@ -199,7 +199,7 @@ static void timestamp_setup(void) net_if_call_timestamp_cb(pkt); zassert_true(timestamp_cb_called, "Timestamp callback not called\n"); - zassert_equal(pkt->ref, 0, "Pkt %p not released\n"); + zassert_equal(atomic_get(&pkt->atomic_ref), 0, "Pkt %p not released\n"); } static void timestamp_callback_2(struct net_pkt *pkt) @@ -246,7 +246,7 @@ static void timestamp_setup_2nd_iface(void) net_if_call_timestamp_cb(pkt); zassert_true(timestamp_cb_called, "Timestamp callback not called\n"); - zassert_equal(pkt->ref, 0, "Pkt %p not released\n"); + zassert_equal(atomic_get(&pkt->atomic_ref), 0, "Pkt %p not released\n"); } static void timestamp_setup_all(void) @@ -272,7 +272,7 @@ static void timestamp_setup_all(void) net_if_call_timestamp_cb(pkt); zassert_true(timestamp_cb_called, "Timestamp callback not called\n"); - zassert_equal(pkt->ref, 0, "Pkt %p not released\n"); + zassert_equal(atomic_get(&pkt->atomic_ref), 0, "Pkt %p not released\n"); net_if_unregister_timestamp_cb(×tamp_cb_3); } @@ -297,7 +297,7 @@ static void timestamp_cleanup(void) net_if_call_timestamp_cb(pkt); zassert_false(timestamp_cb_called, "Timestamp callback called\n"); - zassert_false(pkt->ref < 1, "Pkt %p released\n"); + zassert_false(atomic_get(&pkt->atomic_ref) < 1, "Pkt %p released\n"); net_pkt_unref(pkt); } @@ -502,8 +502,9 @@ static void check_timestamp_before_enabling(void) * should have unreffed the packet by now so the ref count * should be zero now. */ - zassert_equal(pkt->ref, 0, "packet %p was not released (ref %d)\n", - pkt, pkt->ref); + zassert_equal(atomic_get(&pkt->atomic_ref), 0, + "packet %p was not released (ref %d)\n", + pkt, atomic_get(&pkt->atomic_ref)); } static void check_timestamp_after_enabling(void) @@ -524,8 +525,9 @@ static void check_timestamp_after_enabling(void) * and timestamp_cb() should have unreffed the packet by now so * the ref count should be zero at this point. */ - zassert_equal(pkt->ref, 0, "packet %p was not released (ref %d)\n", - pkt, pkt->ref); + zassert_equal(atomic_get(&pkt->atomic_ref), 0, + "packet %p was not released (ref %d)\n", + pkt, atomic_get(&pkt->atomic_ref)); } void test_main(void)