Skip to content

Commit 69fe9b0

Browse files
henrikbrixandersenaescolar
authored andcommitted
net: buf: remove use of special putter and getter functions
Convert users of net_buf_put() and net_buf_get() functions to use non-wrapped putters and getters k_fifo_put() and k_fifo_get(). Special handling of net_bufs in k_fifos is no longer needed after commit 3d306c1, since these actions are now atomic regardless of any net_buf fragments. Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent cb47ed2 commit 69fe9b0

File tree

40 files changed

+154
-155
lines changed

40 files changed

+154
-155
lines changed

drivers/bluetooth/hci/h4.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static void rx_thread(void *p1, void *p2, void *p3)
252252
/* Let the ISR continue receiving new packets */
253253
uart_irq_rx_enable(cfg->uart);
254254

255-
buf = net_buf_get(&h4->rx.fifo, K_FOREVER);
255+
buf = k_fifo_get(&h4->rx.fifo, K_FOREVER);
256256
do {
257257
uart_irq_rx_enable(cfg->uart);
258258

@@ -266,7 +266,7 @@ static void rx_thread(void *p1, void *p2, void *p3)
266266
k_yield();
267267

268268
uart_irq_rx_disable(cfg->uart);
269-
buf = net_buf_get(&h4->rx.fifo, K_NO_WAIT);
269+
buf = k_fifo_get(&h4->rx.fifo, K_NO_WAIT);
270270
} while (buf);
271271
}
272272
}
@@ -352,7 +352,7 @@ static inline void read_payload(const struct device *dev)
352352
reset_rx(h4);
353353

354354
LOG_DBG("Putting buf %p to rx fifo", buf);
355-
net_buf_put(&h4->rx.fifo, buf);
355+
k_fifo_put(&h4->rx.fifo, buf);
356356
}
357357

358358
static inline void read_header(const struct device *dev)
@@ -398,7 +398,7 @@ static inline void process_tx(const struct device *dev)
398398
int bytes;
399399

400400
if (!h4->tx.buf) {
401-
h4->tx.buf = net_buf_get(&h4->tx.fifo, K_NO_WAIT);
401+
h4->tx.buf = k_fifo_get(&h4->tx.fifo, K_NO_WAIT);
402402
if (!h4->tx.buf) {
403403
LOG_ERR("TX interrupt but no pending buffer!");
404404
uart_irq_tx_disable(cfg->uart);
@@ -447,7 +447,7 @@ static inline void process_tx(const struct device *dev)
447447
done:
448448
h4->tx.type = BT_HCI_H4_NONE;
449449
net_buf_unref(h4->tx.buf);
450-
h4->tx.buf = net_buf_get(&h4->tx.fifo, K_NO_WAIT);
450+
h4->tx.buf = k_fifo_get(&h4->tx.fifo, K_NO_WAIT);
451451
if (!h4->tx.buf) {
452452
uart_irq_tx_disable(cfg->uart);
453453
}
@@ -496,7 +496,7 @@ static int h4_send(const struct device *dev, struct net_buf *buf)
496496

497497
LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
498498

499-
net_buf_put(&h4->tx.fifo, buf);
499+
k_fifo_put(&h4->tx.fifo, buf);
500500
uart_irq_tx_enable(cfg->uart);
501501

502502
return 0;

drivers/bluetooth/hci/h5.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static void process_unack(struct h5_data *h5)
212212
LOG_DBG("Need to remove %u packet from the queue", number_removed);
213213

214214
while (number_removed) {
215-
struct net_buf *buf = net_buf_get(&h5->unack_queue, K_NO_WAIT);
215+
struct net_buf *buf = k_fifo_get(&h5->unack_queue, K_NO_WAIT);
216216

217217
if (!buf) {
218218
LOG_ERR("Unack queue is empty");
@@ -349,22 +349,22 @@ static void retx_timeout(struct k_work *work)
349349
k_fifo_init(&tmp_queue);
350350

351351
/* Queue to temporary queue */
352-
while ((buf = net_buf_get(&h5->tx_queue, K_NO_WAIT))) {
353-
net_buf_put(&tmp_queue, buf);
352+
while ((buf = k_fifo_get(&h5->tx_queue, K_NO_WAIT))) {
353+
k_fifo_put(&tmp_queue, buf);
354354
}
355355

356356
/* Queue unack packets to the beginning of the queue */
357-
while ((buf = net_buf_get(&h5->unack_queue, K_NO_WAIT))) {
357+
while ((buf = k_fifo_get(&h5->unack_queue, K_NO_WAIT))) {
358358
/* include also packet type */
359359
net_buf_push(buf, sizeof(uint8_t));
360-
net_buf_put(&h5->tx_queue, buf);
360+
k_fifo_put(&h5->tx_queue, buf);
361361
h5->tx_seq = (h5->tx_seq - 1) & 0x07;
362362
h5->unack_queue_len--;
363363
}
364364

365365
/* Queue saved packets from temp queue */
366-
while ((buf = net_buf_get(&tmp_queue, K_NO_WAIT))) {
367-
net_buf_put(&h5->tx_queue, buf);
366+
while ((buf = k_fifo_get(&tmp_queue, K_NO_WAIT))) {
367+
k_fifo_put(&h5->tx_queue, buf);
368368
}
369369
}
370370
}
@@ -408,7 +408,7 @@ static void h5_process_complete_packet(const struct device *dev, uint8_t *hdr)
408408
net_buf_unref(buf);
409409
break;
410410
case HCI_3WIRE_LINK_PKT:
411-
net_buf_put(&h5->rx_queue, buf);
411+
k_fifo_put(&h5->rx_queue, buf);
412412
break;
413413
case HCI_EVENT_PKT:
414414
case HCI_ACLDATA_PKT:
@@ -619,7 +619,7 @@ static int h5_queue(const struct device *dev, struct net_buf *buf)
619619

620620
memcpy(net_buf_push(buf, sizeof(type)), &type, sizeof(type));
621621

622-
net_buf_put(&h5->tx_queue, buf);
622+
k_fifo_put(&h5->tx_queue, buf);
623623

624624
return 0;
625625
}
@@ -653,15 +653,15 @@ static void tx_thread(void *p1, void *p2, void *p3)
653653
k_sleep(K_MSEC(100));
654654
break;
655655
case ACTIVE:
656-
buf = net_buf_get(&h5->tx_queue, K_FOREVER);
656+
buf = k_fifo_get(&h5->tx_queue, K_FOREVER);
657657
type = h5_get_type(buf);
658658

659659
h5_send(dev, buf->data, type, buf->len);
660660

661661
/* buf is dequeued from tx_queue and queued to unack
662662
* queue.
663663
*/
664-
net_buf_put(&h5->unack_queue, buf);
664+
k_fifo_put(&h5->unack_queue, buf);
665665
h5->unack_queue_len++;
666666

667667
k_work_reschedule(&h5->retx_work, H5_TX_ACK_TIMEOUT);
@@ -689,7 +689,7 @@ static void rx_thread(void *p1, void *p2, void *p3)
689689
while (true) {
690690
struct net_buf *buf;
691691

692-
buf = net_buf_get(&h5->rx_queue, K_FOREVER);
692+
buf = k_fifo_get(&h5->rx_queue, K_FOREVER);
693693

694694
hexdump("=> ", buf->data, buf->len);
695695

drivers/bluetooth/hci/hci_da1469x.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static void rx_thread(void *p1, void *p2, void *p3)
242242
/* Let the ISR continue receiving new packets */
243243
rx_isr_start();
244244

245-
buf = net_buf_get(&rx.fifo, K_FOREVER);
245+
buf = k_fifo_get(&rx.fifo, K_FOREVER);
246246
do {
247247
rx_isr_start();
248248

@@ -257,7 +257,7 @@ static void rx_thread(void *p1, void *p2, void *p3)
257257

258258
rx_isr_stop();
259259

260-
buf = net_buf_get(&rx.fifo, K_NO_WAIT);
260+
buf = k_fifo_get(&rx.fifo, K_NO_WAIT);
261261
} while (buf);
262262
}
263263
}
@@ -339,7 +339,7 @@ static inline void read_payload(void)
339339
reset_rx();
340340

341341
LOG_DBG("Putting buf %p to rx fifo", buf);
342-
net_buf_put(&rx.fifo, buf);
342+
k_fifo_put(&rx.fifo, buf);
343343
}
344344

345345
static inline void read_header(void)

drivers/usb/udc/udc_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct net_buf *udc_buf_get(const struct device *dev, const uint8_t ep)
124124
return NULL;
125125
}
126126

127-
return net_buf_get(&ep_cfg->fifo, K_NO_WAIT);
127+
return k_fifo_get(&ep_cfg->fifo, K_NO_WAIT);
128128
}
129129

130130
struct net_buf *udc_buf_get_all(const struct device *dev, const uint8_t ep)
@@ -169,7 +169,7 @@ struct net_buf *udc_buf_peek(const struct device *dev, const uint8_t ep)
169169
void udc_buf_put(struct udc_ep_config *const ep_cfg,
170170
struct net_buf *const buf)
171171
{
172-
net_buf_put(&ep_cfg->fifo, buf);
172+
k_fifo_put(&ep_cfg->fifo, buf);
173173
}
174174

175175
void udc_ep_buf_set_setup(struct net_buf *const buf)

drivers/usb/udc/udc_mcux_ehci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int udc_mcux_ctrl_feed_dout(const struct device *dev,
151151
return -ENOMEM;
152152
}
153153

154-
net_buf_put(&cfg->fifo, buf);
154+
k_fifo_put(&cfg->fifo, buf);
155155

156156
ret = udc_mcux_ep_feed(dev, cfg, buf);
157157

drivers/usb/udc/udc_mcux_ip3511.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int udc_mcux_ctrl_feed_dout(const struct device *dev,
151151
return -ENOMEM;
152152
}
153153

154-
net_buf_put(&cfg->fifo, buf);
154+
k_fifo_put(&cfg->fifo, buf);
155155

156156
ret = udc_mcux_ep_feed(dev, cfg, buf);
157157

drivers/usb/udc/udc_nrf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static int usbd_ctrl_feed_dout(const struct device *dev,
308308
return -ENOMEM;
309309
}
310310

311-
net_buf_put(&cfg->fifo, buf);
311+
k_fifo_put(&cfg->fifo, buf);
312312
udc_nrf_clear_control_out(dev);
313313

314314
return 0;

drivers/usb/udc/udc_stm32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static int usbd_ctrl_feed_dout(const struct device *dev, const size_t length)
136136
return -ENOMEM;
137137
}
138138

139-
net_buf_put(&cfg->fifo, buf);
139+
k_fifo_put(&cfg->fifo, buf);
140140

141141
HAL_PCD_EP_Receive(&priv->pcd, cfg->addr, buf->data, buf->size);
142142

samples/bluetooth/hci_ipc/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static void hci_ipc_rx(uint8_t *data, size_t len)
192192
}
193193

194194
if (buf) {
195-
net_buf_put(&tx_queue, buf);
195+
k_fifo_put(&tx_queue, buf);
196196

197197
LOG_HEXDUMP_DBG(buf->data, buf->len, "Final net buffer:");
198198
}
@@ -205,7 +205,7 @@ static void tx_thread(void *p1, void *p2, void *p3)
205205
int err;
206206

207207
/* Wait until a buffer is available */
208-
buf = net_buf_get(&tx_queue, K_FOREVER);
208+
buf = k_fifo_get(&tx_queue, K_FOREVER);
209209
/* Pass buffer to the stack */
210210
err = bt_send(buf);
211211
if (err) {
@@ -412,7 +412,7 @@ int main(void)
412412
while (1) {
413413
struct net_buf *buf;
414414

415-
buf = net_buf_get(&rx_queue, K_FOREVER);
415+
buf = k_fifo_get(&rx_queue, K_FOREVER);
416416
hci_ipc_send(buf, HCI_REGULAR_MSG);
417417
}
418418
return 0;

samples/bluetooth/hci_spi/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ int main(void)
317317
}
318318

319319
while (1) {
320-
buf = net_buf_get(&rx_queue, K_FOREVER);
320+
buf = k_fifo_get(&rx_queue, K_FOREVER);
321321
err = spi_send(buf);
322322
if (err) {
323323
LOG_ERR("Failed to send");

0 commit comments

Comments
 (0)