[PATCH] scsi: bnx2fc: fix double free of skb in bnx2fc_rcv

From: Yin Xiujiang
Date: Mon Dec 27 2021 - 22:03:59 EST


In `bnx2fc_rcv`,if skb_share_check() return NULL,
the variable skb would be freed but not set to NULL,
then it would be freed in `goto err` again.

Signed-off-by: Yin Xiujiang <yinxiujiang@xxxxxxxxxx>
---
drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
index 71fa62bd3083..07a91b1f05a2 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
@@ -432,7 +432,6 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
struct fcoe_ctlr *ctlr;
struct fcoe_rcv_info *fr;
struct fcoe_percpu_s *bg;
- struct sk_buff *tmp_skb;

interface = container_of(ptype, struct bnx2fc_interface,
fcoe_packet_type);
@@ -444,11 +443,10 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
goto err;
}

- tmp_skb = skb_share_check(skb, GFP_ATOMIC);
- if (!tmp_skb)
+ skb = skb_share_check(skb, GFP_ATOMIC);
+ if (unlikely(!skb))
goto err;

- skb = tmp_skb;

if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
--
2.30.0