net/devif: replace redundant code to iob_clone_partial()

Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an 2022-12-13 22:10:44 +08:00 committed by Xiang Xiao
parent 881c9d9fac
commit 5492e961bc

View File

@ -58,7 +58,6 @@ void devif_iob_send(FAR struct net_driver_s *dev, FAR struct iob_s *iob,
{ {
unsigned int limit = NETDEV_PKTSIZE(dev) - unsigned int limit = NETDEV_PKTSIZE(dev) -
NET_LL_HDRLEN(dev) - target_offset; NET_LL_HDRLEN(dev) - target_offset;
unsigned int copyin;
int ret; int ret;
if (dev == NULL || len == 0 || len > limit) if (dev == NULL || len == 0 || len > limit)
@ -77,50 +76,26 @@ void devif_iob_send(FAR struct net_driver_s *dev, FAR struct iob_s *iob,
if (dev->d_iob != NULL) if (dev->d_iob != NULL)
{ {
dev->d_sndlen = 0;
if (len > iob_navail(false) * CONFIG_IOB_BUFSIZE) if (len > iob_navail(false) * CONFIG_IOB_BUFSIZE)
{ {
dev->d_sndlen = 0;
return; return;
} }
/* Skip the l3/l4 offset before append */
iob_update_pktlen(dev->d_iob, target_offset);
/* Skip to the I/O buffer containing the data offset */
while (iob != NULL && offset > iob->io_len)
{
offset -= iob->io_len;
iob = iob->io_flink;
}
dev->d_sndlen = len;
/* Clone the iob to target device buffer */ /* Clone the iob to target device buffer */
while (iob != NULL && len > 0) ret = iob_clone_partial(iob, len, offset, dev->d_iob,
{ target_offset, false, false);
copyin = (len > iob->io_len - offset) ? if (ret != OK)
iob->io_len - offset : len;
ret = iob_trycopyin(dev->d_iob, iob->io_data +
iob->io_offset + offset,
copyin, target_offset, false);
if (ret != copyin)
{ {
netdev_iob_release(dev); netdev_iob_release(dev);
dev->d_sndlen = 0;
nerr("devif_iob_send error, not enough iob entries, " nerr("devif_iob_send error, not enough iob entries, "
"send len: %u\n", len); "send len: %u\n", len);
return; return;
} }
target_offset += copyin; dev->d_sndlen = len;
len -= copyin;
offset = 0;
iob = iob->io_flink;
}
} }
else else
{ {