drivers: net: mhi: fix error path in mhi_net_newlink
authorDaniele Palmas <dnlplm@gmail.com>
Fri, 24 Sep 2021 09:26:52 +0000 (11:26 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 7 Oct 2021 05:53:19 +0000 (07:53 +0200)
commit 4526fe74c3c5095cc55931a3a6fb4932f9e06002 upstream.

Fix double free_netdev when mhi_prepare_for_transfer fails.

Fixes: 3ffec6a14f24 ("net: Add mhi-net driver")
Signed-off-by: Daniele Palmas <dnlplm@gmail.com>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Loic Poulain <loic.poulain@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/mhi/net.c

index e60e38c1f09d317750c7fd6f0bdfa2ec9ca33513..5e49f7a919b614d359cf88c7888aab8e4418567c 100644 (file)
@@ -337,7 +337,7 @@ static int mhi_net_newlink(void *ctxt, struct net_device *ndev, u32 if_id,
        /* Start MHI channels */
        err = mhi_prepare_for_transfer(mhi_dev);
        if (err)
-               goto out_err;
+               return err;
 
        /* Number of transfer descriptors determines size of the queue */
        mhi_netdev->rx_queue_sz = mhi_get_free_desc_count(mhi_dev, DMA_FROM_DEVICE);
@@ -347,7 +347,7 @@ static int mhi_net_newlink(void *ctxt, struct net_device *ndev, u32 if_id,
        else
                err = register_netdev(ndev);
        if (err)
-               goto out_err;
+               return err;
 
        if (mhi_netdev->proto) {
                err = mhi_netdev->proto->init(mhi_netdev);
@@ -359,8 +359,6 @@ static int mhi_net_newlink(void *ctxt, struct net_device *ndev, u32 if_id,
 
 out_err_proto:
        unregister_netdevice(ndev);
-out_err:
-       free_netdev(ndev);
        return err;
 }