2022-09-30 07:30:09

by Horatiu Vultur

[permalink] [raw]
Subject: Re: [PATCH] net: lan966x: Fix return type of lan966x_port_xmit

The 09/29/2022 11:27, Nathan Huckleberry wrote:

Hi Nathan,

>
> The ndo_start_xmit field in net_device_ops is expected to be of type
> netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb, struct net_device *dev).
>
> The mismatched return type breaks forward edge kCFI since the underlying
> function definition does not match the function hook definition.
>
> The return type of lan966x_port_xmit should be changed from int to
> netdev_tx_t.
>
> Reported-by: Dan Carpenter <[email protected]>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1703
> Cc: [email protected]
> Signed-off-by: Nathan Huckleberry <[email protected]>

It looks pretty good.
If we change the return type of lan966x_port_xmit, can we change also the
return type of the functions lan966x_fdma_xmit and
lan966x_port_ifh_xmit?
And then also make sure to return NETDEV_TX_BUSY in case
lan966x_ptp_txtstamp_request fails and not the error code?

I have a diff below:
---
diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
index 7e4061c854f0e..148920bb74e08 100644
--- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
+++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
@@ -558,7 +558,8 @@ static int lan966x_fdma_get_next_dcb(struct lan966x_tx *tx)
return -1;
}

-int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev)
+netdev_tx_t lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh,
+ struct net_device *dev)
{
struct lan966x_port *port = netdev_priv(dev);
struct lan966x *lan966x = port->lan966x;
diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
index b98d37c76edbc..4b471a1562e29 100644
--- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
+++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
@@ -219,9 +219,9 @@ static int lan966x_port_inj_ready(struct lan966x *lan966x, u8 grp)
READL_SLEEP_US, READL_TIMEOUT_US);
}

-static int lan966x_port_ifh_xmit(struct sk_buff *skb,
- __be32 *ifh,
- struct net_device *dev)
+static netdev_tx_t lan966x_port_ifh_xmit(struct sk_buff *skb,
+ __be32 *ifh,
+ struct net_device *dev)
{
struct lan966x_port *port = netdev_priv(dev);
struct lan966x *lan966x = port->lan966x;
@@ -344,12 +344,12 @@ static void lan966x_ifh_set_timestamp(void *ifh, u64 timestamp)
IFH_POS_TIMESTAMP, IFH_LEN * 4, PACK, 0);
}

-static int lan966x_port_xmit(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t lan966x_port_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct lan966x_port *port = netdev_priv(dev);
struct lan966x *lan966x = port->lan966x;
__be32 ifh[IFH_LEN];
- int err;
+ netdev_tx_t ret;

memset(ifh, 0x0, sizeof(__be32) * IFH_LEN);

@@ -360,9 +360,8 @@ static int lan966x_port_xmit(struct sk_buff *skb, struct net_device *dev)
lan966x_ifh_set_vid(ifh, skb_vlan_tag_get(skb));

if (port->lan966x->ptp && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) {
- err = lan966x_ptp_txtstamp_request(port, skb);
- if (err)
- return err;
+ if (lan966x_ptp_txtstamp_request(port, skb))
+ return NETDEV_TX_BUSY;

lan966x_ifh_set_rew_op(ifh, LAN966X_SKB_CB(skb)->rew_op);
lan966x_ifh_set_timestamp(ifh, LAN966X_SKB_CB(skb)->ts_id);
@@ -370,12 +369,12 @@ static int lan966x_port_xmit(struct sk_buff *skb, struct net_device *dev)

spin_lock(&lan966x->tx_lock);
if (port->lan966x->fdma)
- err = lan966x_fdma_xmit(skb, ifh, dev);
+ ret = lan966x_fdma_xmit(skb, ifh, dev);
else
- err = lan966x_port_ifh_xmit(skb, ifh, dev);
+ ret = lan966x_port_ifh_xmit(skb, ifh, dev);
spin_unlock(&lan966x->tx_lock);

- return err;
+ return ret;
}

static int lan966x_port_change_mtu(struct net_device *dev, int new_mtu)
diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h
index 9656071b8289e..d61a0fc4b33ab 100644
--- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h
+++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h
@@ -434,7 +434,8 @@ irqreturn_t lan966x_ptp_ext_irq_handler(int irq, void *args);
u32 lan966x_ptp_get_period_ps(void);
int lan966x_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts);

-int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev);
+netdev_tx_t lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh,
+ struct net_device *dev);
int lan966x_fdma_change_mtu(struct lan966x *lan966x);
void lan966x_fdma_netdev_init(struct lan966x *lan966x, struct net_device *dev);
void lan966x_fdma_netdev_deinit(struct lan966x *lan966x, struct net_device *dev);
---

> ---
> drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
> index b98d37c76edb..be2fd030cccb 100644
> --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
> +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
> @@ -344,7 +344,8 @@ static void lan966x_ifh_set_timestamp(void *ifh, u64 timestamp)
> IFH_POS_TIMESTAMP, IFH_LEN * 4, PACK, 0);
> }
>
> -static int lan966x_port_xmit(struct sk_buff *skb, struct net_device *dev)
> +static netdev_tx_t lan966x_port_xmit(struct sk_buff *skb,
> + struct net_device *dev)
> {
> struct lan966x_port *port = netdev_priv(dev);
> struct lan966x *lan966x = port->lan966x;
> --
> 2.38.0.rc1.362.ged0d419d3c-goog
>

--
/Horatiu