[PATCH 4/5] usb: eth: r8152: Use variable to store descritpor size
ChunHao Lin
hau at realtek.com
Tue Nov 26 03:25:14 CET 2024
Use variable to store tx/rx descriptor size to prevent the call
to sizeof().
Signed-off-by: ChunHao Lin <hau at realtek.com>
---
drivers/usb/eth/r8152.c | 20 ++++++++++++--------
drivers/usb/eth/r8152.h | 3 +++
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/drivers/usb/eth/r8152.c b/drivers/usb/eth/r8152.c
index 8ddfb402d8..e12753b720 100644
--- a/drivers/usb/eth/r8152.c
+++ b/drivers/usb/eth/r8152.c
@@ -663,7 +663,7 @@ static void r8153_set_rx_early_timeout(struct r8152 *tp)
static void r8153_set_rx_early_size(struct r8152 *tp)
{
u32 ocp_data = (RTL8152_AGG_BUF_SZ - RTL8153_RMS -
- sizeof(struct rx_desc));
+ tp->rx_desc_size);
switch (tp->version) {
case RTL_VER_03:
@@ -2217,6 +2217,10 @@ static void r8152b_get_version(struct r8152 *tp)
}
}
+ /* set descriptor size */
+ tp->rx_desc_size = sizeof(struct rx_desc);
+ tp->tx_desc_size = sizeof(struct tx_desc);
+
if (tp->version == RTL_VER_UNKNOWN)
debug("r8152 Unknown tcr version 0x%04x\n", tcr);
}
@@ -2663,7 +2667,7 @@ static int r8152_send_common(struct ueth_data *ueth, void *packet, int length)
int err;
int actual_len;
ALLOC_CACHE_ALIGN_BUFFER(uint8_t, msg,
- PKTSIZE + sizeof(struct tx_desc));
+ PKTSIZE + tp->tx_desc_size);
struct tx_desc *tx_desc = (struct tx_desc *)msg;
debug("** %s(), len %d\n", __func__, length);
@@ -2673,13 +2677,13 @@ static int r8152_send_common(struct ueth_data *ueth, void *packet, int length)
tx_desc->opts2 = cpu_to_le32(opts2);
tx_desc->opts1 = cpu_to_le32(opts1);
- memcpy(msg + sizeof(struct tx_desc), (void *)packet, length);
+ memcpy(msg + tp->tx_desc_size, (void *)packet, length);
err = usb_bulk_msg(udev, usb_sndbulkpipe(udev, ueth->ep_out),
- (void *)msg, length + sizeof(struct tx_desc),
+ (void *)msg, length + tp->tx_desc_size,
&actual_len, USB_BULK_SEND_TIMEOUT);
debug("Tx: len = %zu, actual = %u, err = %d\n",
- length + sizeof(struct tx_desc), actual_len, err);
+ length + tp->tx_desc_size, actual_len, err);
return err;
}
@@ -2735,12 +2739,12 @@ int r8152_eth_recv(struct udevice *dev, int flags, uchar **packetp)
packet_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK;
packet_len -= CRC_SIZE;
- if (packet_len > len - (sizeof(struct rx_desc) + CRC_SIZE)) {
+ if (packet_len > len - (tp->rx_desc_size + CRC_SIZE)) {
debug("Rx: too large packet: %d\n", packet_len);
goto err;
}
- *packetp = ptr + sizeof(struct rx_desc);
+ *packetp = ptr + tp->rx_desc_size;
return packet_len;
err:
@@ -2752,7 +2756,7 @@ static int r8152_free_pkt(struct udevice *dev, uchar *packet, int packet_len)
{
struct r8152 *tp = dev_get_priv(dev);
- packet_len += sizeof(struct rx_desc) + CRC_SIZE;
+ packet_len += tp->rx_desc_size + CRC_SIZE;
packet_len = ALIGN(packet_len, 8);
usb_ether_advance_rxbuf(&tp->ueth, packet_len);
diff --git a/drivers/usb/eth/r8152.h b/drivers/usb/eth/r8152.h
index 055ec5e385..3ced02a3b1 100644
--- a/drivers/usb/eth/r8152.h
+++ b/drivers/usb/eth/r8152.h
@@ -794,6 +794,9 @@ struct r8152 {
u8 version;
+ u8 rx_desc_size;
+ u8 tx_desc_size;
+
struct ueth_data ueth;
};
--
2.43.0
More information about the U-Boot
mailing list