Skip to content

Commit

Permalink
gianfar: Fix alloc_skb_resources on -ENOMEM cleanup path
Browse files Browse the repository at this point in the history
Should gfar_init_bds() return with -ENOMEM inside gfar_alloc_skb_resources(),
free_skb_resources() will be called twice in a row on the "cleanup" path,
leading to duplicate kfree() calls for rx_|tx_queue->rx_|tx_skbuff resulting
in segmentation fault.
This patch prevents the segmentation fault to happen in the future
(rx_|tx_sbkbuff set to NULL), and corrects the error path handling
for gfar_init_bds().

Cc: Paul Gortmaker <paul.gortmaker@windriver.com>

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Acked-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Claudiu Manoil authored and David S. Miller committed Nov 9, 2012
1 parent be44389 commit 1eb8f7a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/net/ethernet/freescale/gianfar.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static int gfar_init_bds(struct net_device *ndev)
skb = gfar_new_skb(ndev);
if (!skb) {
netdev_err(ndev, "Can't allocate RX buffers\n");
goto err_rxalloc_fail;
return -ENOMEM;
}
rx_queue->rx_skbuff[j] = skb;

Expand All @@ -223,10 +223,6 @@ static int gfar_init_bds(struct net_device *ndev)
}

return 0;

err_rxalloc_fail:
free_skb_resources(priv);
return -ENOMEM;
}

static int gfar_alloc_skb_resources(struct net_device *ndev)
Expand Down Expand Up @@ -1356,7 +1352,11 @@ static int gfar_restore(struct device *dev)
if (!netif_running(ndev))
return 0;

gfar_init_bds(ndev);
if (gfar_init_bds(ndev)) {
free_skb_resources(priv);
return -ENOMEM;
}

init_registers(ndev);
gfar_set_mac_address(ndev);
gfar_init_mac(ndev);
Expand Down Expand Up @@ -1709,6 +1709,7 @@ static void free_skb_tx_queue(struct gfar_priv_tx_q *tx_queue)
tx_queue->tx_skbuff[i] = NULL;
}
kfree(tx_queue->tx_skbuff);
tx_queue->tx_skbuff = NULL;
}

static void free_skb_rx_queue(struct gfar_priv_rx_q *rx_queue)
Expand All @@ -1732,6 +1733,7 @@ static void free_skb_rx_queue(struct gfar_priv_rx_q *rx_queue)
rxbdp++;
}
kfree(rx_queue->rx_skbuff);
rx_queue->rx_skbuff = NULL;
}

/* If there are any tx skbs or rx skbs still around, free them.
Expand Down

0 comments on commit 1eb8f7a

Please sign in to comment.