Skip to content

Commit d678f30

Browse files
dgloeckjukkar
authored andcommitted
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>
1 parent 5ef825f commit d678f30

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

drivers/ethernet/eth_mcux.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ static inline void ts_register_tx_event(struct eth_context *context)
677677
enet_ptp_time_data_t timeData;
678678

679679
pkt = ts_tx_pkt[ts_tx_rd];
680-
if (pkt && pkt->ref > 0) {
680+
if (pkt && atomic_get(&pkt->atomic_ref) > 0) {
681681
if (eth_get_ptp_data(net_pkt_iface(pkt), pkt, &timeData,
682682
true)) {
683683
int status;

subsys/net/ip/net_pkt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ struct net_pkt *net_pkt_get_reserve(struct k_mem_slab *slab,
355355
#if CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
356356
NET_DBG("%s [%u] pkt %p ref %d (%s():%d)",
357357
slab2str(slab), k_mem_slab_num_free_get(slab),
358-
pkt, pkt->ref, caller, line);
358+
pkt, atomic_get(&pkt->atomic_ref), caller, line);
359359
#endif
360360
return pkt;
361361
}

subsys/net/ip/net_shell.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -969,12 +969,13 @@ static void tcp_sent_list_cb(struct net_tcp *tcp, void *user_data)
969969
struct net_buf *frag = pkt->frags;
970970

971971
if (!*printed) {
972-
PR("%p[%d/%zd]", pkt, pkt->ref,
972+
PR("%p[%d/%zd]", pkt, atomic_get(&pkt->atomic_ref),
973973
net_pkt_get_len(pkt));
974974
*printed = true;
975975
} else {
976976
PR(" %p[%d/%zd]",
977-
pkt, pkt->ref, net_pkt_get_len(pkt));
977+
pkt, atomic_get(&pkt->atomic_ref),
978+
net_pkt_get_len(pkt));
978979
}
979980

980981
if (frag) {
@@ -1074,7 +1075,7 @@ static void allocs_cb(struct net_pkt *pkt,
10741075
if (func_alloc) {
10751076
if (in_use) {
10761077
PR("%p/%d\t%5s\t%5s\t%s():%d\n",
1077-
pkt, pkt->ref, str,
1078+
pkt, atomic_get(&pkt->atomic_ref), str,
10781079
net_pkt_slab2str(pkt->slab),
10791080
func_alloc, line_alloc);
10801081
} else {

tests/net/arp/src/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void test_arp(void)
475475
*/
476476
net_pkt_unref(pkt2);
477477

478-
zassert_equal(pkt->ref, 2,
478+
zassert_equal(atomic_get(&pkt->atomic_ref), 2,
479479
"ARP cache should own the original packet");
480480

481481
/* Then a case where target is not in the same subnet */
@@ -579,7 +579,7 @@ void test_arp(void)
579579
/**TESTPOINTS: Check ARP reply*/
580580
zassert_false(send_status < 0, "ARP reply was not sent");
581581

582-
zassert_equal(pkt->ref, 1,
582+
zassert_equal(atomic_get(&pkt->atomic_ref), 1,
583583
"ARP cache should no longer own the original packet");
584584

585585
net_pkt_unref(pkt);

tests/net/tx_timestamp/src/main.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static void timestamp_setup(void)
199199
net_if_call_timestamp_cb(pkt);
200200

201201
zassert_true(timestamp_cb_called, "Timestamp callback not called\n");
202-
zassert_equal(pkt->ref, 0, "Pkt %p not released\n");
202+
zassert_equal(atomic_get(&pkt->atomic_ref), 0, "Pkt %p not released\n");
203203
}
204204

205205
static void timestamp_callback_2(struct net_pkt *pkt)
@@ -246,7 +246,7 @@ static void timestamp_setup_2nd_iface(void)
246246
net_if_call_timestamp_cb(pkt);
247247

248248
zassert_true(timestamp_cb_called, "Timestamp callback not called\n");
249-
zassert_equal(pkt->ref, 0, "Pkt %p not released\n");
249+
zassert_equal(atomic_get(&pkt->atomic_ref), 0, "Pkt %p not released\n");
250250
}
251251

252252
static void timestamp_setup_all(void)
@@ -272,7 +272,7 @@ static void timestamp_setup_all(void)
272272
net_if_call_timestamp_cb(pkt);
273273

274274
zassert_true(timestamp_cb_called, "Timestamp callback not called\n");
275-
zassert_equal(pkt->ref, 0, "Pkt %p not released\n");
275+
zassert_equal(atomic_get(&pkt->atomic_ref), 0, "Pkt %p not released\n");
276276

277277
net_if_unregister_timestamp_cb(&timestamp_cb_3);
278278
}
@@ -297,7 +297,7 @@ static void timestamp_cleanup(void)
297297
net_if_call_timestamp_cb(pkt);
298298

299299
zassert_false(timestamp_cb_called, "Timestamp callback called\n");
300-
zassert_false(pkt->ref < 1, "Pkt %p released\n");
300+
zassert_false(atomic_get(&pkt->atomic_ref) < 1, "Pkt %p released\n");
301301

302302
net_pkt_unref(pkt);
303303
}
@@ -502,8 +502,9 @@ static void check_timestamp_before_enabling(void)
502502
* should have unreffed the packet by now so the ref count
503503
* should be zero now.
504504
*/
505-
zassert_equal(pkt->ref, 0, "packet %p was not released (ref %d)\n",
506-
pkt, pkt->ref);
505+
zassert_equal(atomic_get(&pkt->atomic_ref), 0,
506+
"packet %p was not released (ref %d)\n",
507+
pkt, atomic_get(&pkt->atomic_ref));
507508
}
508509

509510
static void check_timestamp_after_enabling(void)
@@ -524,8 +525,9 @@ static void check_timestamp_after_enabling(void)
524525
* and timestamp_cb() should have unreffed the packet by now so
525526
* the ref count should be zero at this point.
526527
*/
527-
zassert_equal(pkt->ref, 0, "packet %p was not released (ref %d)\n",
528-
pkt, pkt->ref);
528+
zassert_equal(atomic_get(&pkt->atomic_ref), 0,
529+
"packet %p was not released (ref %d)\n",
530+
pkt, atomic_get(&pkt->atomic_ref));
529531
}
530532

531533
void test_main(void)

0 commit comments

Comments
 (0)