net: pkt: convert remaining users of ref to atomic_ref

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 <dg@emlix.com>
This commit is contained in:
Daniel Glöckner 2019-01-28 02:11:09 +01:00 committed by Jukka Rissanen
parent 5ef825fdf6
commit d678f309b8
5 changed files with 18 additions and 15 deletions

View file

@ -677,7 +677,7 @@ static inline void ts_register_tx_event(struct eth_context *context)
enet_ptp_time_data_t timeData; enet_ptp_time_data_t timeData;
pkt = ts_tx_pkt[ts_tx_rd]; 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, if (eth_get_ptp_data(net_pkt_iface(pkt), pkt, &timeData,
true)) { true)) {
int status; int status;

View file

@ -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 #if CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
NET_DBG("%s [%u] pkt %p ref %d (%s():%d)", NET_DBG("%s [%u] pkt %p ref %d (%s():%d)",
slab2str(slab), k_mem_slab_num_free_get(slab), slab2str(slab), k_mem_slab_num_free_get(slab),
pkt, pkt->ref, caller, line); pkt, atomic_get(&pkt->atomic_ref), caller, line);
#endif #endif
return pkt; return pkt;
} }

View file

@ -969,12 +969,13 @@ static void tcp_sent_list_cb(struct net_tcp *tcp, void *user_data)
struct net_buf *frag = pkt->frags; struct net_buf *frag = pkt->frags;
if (!*printed) { if (!*printed) {
PR("%p[%d/%zd]", pkt, pkt->ref, PR("%p[%d/%zd]", pkt, atomic_get(&pkt->atomic_ref),
net_pkt_get_len(pkt)); net_pkt_get_len(pkt));
*printed = true; *printed = true;
} else { } else {
PR(" %p[%d/%zd]", 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) { if (frag) {
@ -1074,7 +1075,7 @@ static void allocs_cb(struct net_pkt *pkt,
if (func_alloc) { if (func_alloc) {
if (in_use) { if (in_use) {
PR("%p/%d\t%5s\t%5s\t%s():%d\n", 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), net_pkt_slab2str(pkt->slab),
func_alloc, line_alloc); func_alloc, line_alloc);
} else { } else {

View file

@ -475,7 +475,7 @@ void test_arp(void)
*/ */
net_pkt_unref(pkt2); net_pkt_unref(pkt2);
zassert_equal(pkt->ref, 2, zassert_equal(atomic_get(&pkt->atomic_ref), 2,
"ARP cache should own the original packet"); "ARP cache should own the original packet");
/* Then a case where target is not in the same subnet */ /* Then a case where target is not in the same subnet */
@ -579,7 +579,7 @@ void test_arp(void)
/**TESTPOINTS: Check ARP reply*/ /**TESTPOINTS: Check ARP reply*/
zassert_false(send_status < 0, "ARP reply was not sent"); 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"); "ARP cache should no longer own the original packet");
net_pkt_unref(pkt); net_pkt_unref(pkt);

View file

@ -199,7 +199,7 @@ static void timestamp_setup(void)
net_if_call_timestamp_cb(pkt); net_if_call_timestamp_cb(pkt);
zassert_true(timestamp_cb_called, "Timestamp callback not called\n"); 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) 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); net_if_call_timestamp_cb(pkt);
zassert_true(timestamp_cb_called, "Timestamp callback not called\n"); 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) static void timestamp_setup_all(void)
@ -272,7 +272,7 @@ static void timestamp_setup_all(void)
net_if_call_timestamp_cb(pkt); net_if_call_timestamp_cb(pkt);
zassert_true(timestamp_cb_called, "Timestamp callback not called\n"); 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(&timestamp_cb_3); net_if_unregister_timestamp_cb(&timestamp_cb_3);
} }
@ -297,7 +297,7 @@ static void timestamp_cleanup(void)
net_if_call_timestamp_cb(pkt); net_if_call_timestamp_cb(pkt);
zassert_false(timestamp_cb_called, "Timestamp callback called\n"); 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); 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 have unreffed the packet by now so the ref count
* should be zero now. * should be zero now.
*/ */
zassert_equal(pkt->ref, 0, "packet %p was not released (ref %d)\n", zassert_equal(atomic_get(&pkt->atomic_ref), 0,
pkt, pkt->ref); "packet %p was not released (ref %d)\n",
pkt, atomic_get(&pkt->atomic_ref));
} }
static void check_timestamp_after_enabling(void) 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 * and timestamp_cb() should have unreffed the packet by now so
* the ref count should be zero at this point. * the ref count should be zero at this point.
*/ */
zassert_equal(pkt->ref, 0, "packet %p was not released (ref %d)\n", zassert_equal(atomic_get(&pkt->atomic_ref), 0,
pkt, pkt->ref); "packet %p was not released (ref %d)\n",
pkt, atomic_get(&pkt->atomic_ref));
} }
void test_main(void) void test_main(void)