[net] fm10k: fix potential memleak in fm10k_xmit_frame()

Message ID 1668775048-22031-1-git-send-email-zhangchangzhong@huawei.com
State New
Headers
Series [net] fm10k: fix potential memleak in fm10k_xmit_frame() |

Commit Message

Zhang Changzhong Nov. 18, 2022, 12:37 p.m. UTC
  The fm10k_xmit_frame() returns NETDEV_TX_OK without freeing skb in error
handling case, add dev_kfree_skb() to fix it. Compile tested only.

Fixes: b101c9626477 ("fm10k: Add transmit and receive fastpath and interrupt handlers")
Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
---
 drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Alexander Duyck Nov. 18, 2022, 3:36 p.m. UTC | #1
On Fri, 2022-11-18 at 20:37 +0800, Zhang Changzhong wrote:
> The fm10k_xmit_frame() returns NETDEV_TX_OK without freeing skb in error
> handling case, add dev_kfree_skb() to fix it. Compile tested only.
> 
> Fixes: b101c9626477 ("fm10k: Add transmit and receive fastpath and interrupt handlers")
> Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
> ---
>  drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c b/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c
> index 2cca9e8..c7b672a 100644
> --- a/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c
> +++ b/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c
> @@ -531,8 +531,10 @@ static netdev_tx_t fm10k_xmit_frame(struct sk_buff *skb, struct net_device *dev)
>  			return NETDEV_TX_OK;
>  
>  		/* make sure there is enough room to move the ethernet header */
> -		if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN)))
> +		if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN))) {
> +			dev_kfree_skb(skb);
>  			return NETDEV_TX_OK;
> +		}
>  
>  		/* verify the skb head is not shared */
>  		err = skb_cow_head(skb, 0);

Fix looks good to me.

Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
  

Patch

diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c b/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c
index 2cca9e8..c7b672a 100644
--- a/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c
+++ b/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c
@@ -531,8 +531,10 @@  static netdev_tx_t fm10k_xmit_frame(struct sk_buff *skb, struct net_device *dev)
 			return NETDEV_TX_OK;
 
 		/* make sure there is enough room to move the ethernet header */
-		if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN)))
+		if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN))) {
+			dev_kfree_skb(skb);
 			return NETDEV_TX_OK;
+		}
 
 		/* verify the skb head is not shared */
 		err = skb_cow_head(skb, 0);