Message ID | 1340994290-28832-5-git-send-email-jitendra.kalsaria@qlogic.com |
---|---|
State | Changes Requested, archived |
Delegated to: | David Miller |
Headers | show |
Jitendra Kalsaria <jitendra.kalsaria@qlogic.com> : [...] > diff --git a/drivers/net/ethernet/qlogic/qlge/qlge_main.c b/drivers/net/ethernet/qlogic/qlge/qlge_main.c > index cdbc860..aa514c5 100644 > --- a/drivers/net/ethernet/qlogic/qlge/qlge_main.c > +++ b/drivers/net/ethernet/qlogic/qlge/qlge_main.c > @@ -2701,11 +2701,9 @@ static int ql_alloc_tx_resources(struct ql_adapter *qdev, > pci_alloc_consistent(qdev->pdev, tx_ring->wq_size, > &tx_ring->wq_base_dma); > > - if ((tx_ring->wq_base == NULL) || > - tx_ring->wq_base_dma & WQ_ADDR_ALIGN) { > - netif_err(qdev, ifup, qdev->ndev, "tx_ring alloc failed.\n"); > - return -ENOMEM; > - } > + if ((tx_ring->wq_base == NULL) || tx_ring->wq_base_dma & WQ_ADDR_ALIGN) > + goto err; > + > tx_ring->q = > kmalloc(tx_ring->wq_len * sizeof(struct tx_ring_desc), GFP_KERNEL); > if (tx_ring->q == NULL) > @@ -2713,8 +2711,12 @@ static int ql_alloc_tx_resources(struct ql_adapter *qdev, > > return 0; > err: > - pci_free_consistent(qdev->pdev, tx_ring->wq_size, > + if (tx_ring->wq_base) { > + pci_free_consistent(qdev->pdev, tx_ring->wq_size, > tx_ring->wq_base, tx_ring->wq_base_dma); > + tx_ring->wq_base = NULL; > + } You do not need a test: use a second label + goto. Nit: You can replace 'if ((tx_ring->wq_base == NULL)' with 'if (!tx_ring->wq_base' and add a local variable for qdev->pdev. You may consider replacing pci_alloc_consistent with dma_alloc_coherent in a future patch.
Francois, See comments inline. Jiten -----Original Message----- From: Francois Romieu [mailto:romieu@fr.zoreil.com] Sent: Friday, June 29, 2012 2:38 PM To: Jitendra Kalsaria Cc: David Miller; netdev; Ron@linux-zupk.site; Dept-NX Linux NIC Driver Subject: Re: [PATCH net-next 4/6] qlge: Fixed double pci free upon tx_ring->q allocation failure. Jitendra Kalsaria <jitendra.kalsaria@qlogic.com> : [...] > diff --git a/drivers/net/ethernet/qlogic/qlge/qlge_main.c b/drivers/net/ethernet/qlogic/qlge/qlge_main.c > index cdbc860..aa514c5 100644 > --- a/drivers/net/ethernet/qlogic/qlge/qlge_main.c > +++ b/drivers/net/ethernet/qlogic/qlge/qlge_main.c > @@ -2701,11 +2701,9 @@ static int ql_alloc_tx_resources(struct ql_adapter *qdev, > pci_alloc_consistent(qdev->pdev, tx_ring->wq_size, > &tx_ring->wq_base_dma); > > - if ((tx_ring->wq_base == NULL) || > - tx_ring->wq_base_dma & WQ_ADDR_ALIGN) { > - netif_err(qdev, ifup, qdev->ndev, "tx_ring alloc failed.\n"); > - return -ENOMEM; > - } > + if ((tx_ring->wq_base == NULL) || tx_ring->wq_base_dma & WQ_ADDR_ALIGN) > + goto err; > + > tx_ring->q = > kmalloc(tx_ring->wq_len * sizeof(struct tx_ring_desc), GFP_KERNEL); > if (tx_ring->q == NULL) > @@ -2713,8 +2711,12 @@ static int ql_alloc_tx_resources(struct ql_adapter *qdev, > > return 0; > err: > - pci_free_consistent(qdev->pdev, tx_ring->wq_size, > + if (tx_ring->wq_base) { > + pci_free_consistent(qdev->pdev, tx_ring->wq_size, > tx_ring->wq_base, tx_ring->wq_base_dma); > + tx_ring->wq_base = NULL; > + } You do not need a test: use a second label + goto. Nit: You can replace 'if ((tx_ring->wq_base == NULL)' with 'if (!tx_ring->wq_base' and add a local variable for qdev->pdev. You may consider replacing pci_alloc_consistent with dma_alloc_coherent in a future patch. [JK] Will, definitely take care of this in future patch.
diff --git a/drivers/net/ethernet/qlogic/qlge/qlge_main.c b/drivers/net/ethernet/qlogic/qlge/qlge_main.c index cdbc860..aa514c5 100644 --- a/drivers/net/ethernet/qlogic/qlge/qlge_main.c +++ b/drivers/net/ethernet/qlogic/qlge/qlge_main.c @@ -2701,11 +2701,9 @@ static int ql_alloc_tx_resources(struct ql_adapter *qdev, pci_alloc_consistent(qdev->pdev, tx_ring->wq_size, &tx_ring->wq_base_dma); - if ((tx_ring->wq_base == NULL) || - tx_ring->wq_base_dma & WQ_ADDR_ALIGN) { - netif_err(qdev, ifup, qdev->ndev, "tx_ring alloc failed.\n"); - return -ENOMEM; - } + if ((tx_ring->wq_base == NULL) || tx_ring->wq_base_dma & WQ_ADDR_ALIGN) + goto err; + tx_ring->q = kmalloc(tx_ring->wq_len * sizeof(struct tx_ring_desc), GFP_KERNEL); if (tx_ring->q == NULL) @@ -2713,8 +2711,12 @@ static int ql_alloc_tx_resources(struct ql_adapter *qdev, return 0; err: - pci_free_consistent(qdev->pdev, tx_ring->wq_size, + if (tx_ring->wq_base) { + pci_free_consistent(qdev->pdev, tx_ring->wq_size, tx_ring->wq_base, tx_ring->wq_base_dma); + tx_ring->wq_base = NULL; + } + netif_err(qdev, ifup, qdev->ndev, "tx_ring alloc failed.\n"); return -ENOMEM; }