Skip to content

Commit 40b0655

Browse files
Ganesh Goudardavem330
authored andcommitted
cxgb4: fix the error path of cxgb4_uld_register()
On multi adapter setup if the uld registration fails even on one adapter, the allocated resources for the uld on all the adapters are freed, rendering the functioning adapters unusable. This commit fixes the issue by freeing the allocated resources only for the failed adapter. Signed-off-by: Ganesh Goudar <ganeshgr@chelsio.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 35b842f commit 40b0655

File tree

3 files changed

+13
-39
lines changed

3 files changed

+13
-39
lines changed

drivers/crypto/chelsio/chcr_core.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ static int chcr_uld_state_change(void *handle, enum cxgb4_state state)
237237

238238
static int __init chcr_crypto_init(void)
239239
{
240-
if (cxgb4_register_uld(CXGB4_ULD_CRYPTO, &chcr_uld_info))
241-
pr_err("ULD register fail: No chcr crypto support in cxgb4\n");
242-
240+
cxgb4_register_uld(CXGB4_ULD_CRYPTO, &chcr_uld_info);
243241
return 0;
244242
}
245243

drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -702,15 +702,14 @@ static void uld_attach(struct adapter *adap, unsigned int uld)
702702
* about any presently available devices that support its type. Returns
703703
* %-EBUSY if a ULD of the same type is already registered.
704704
*/
705-
int cxgb4_register_uld(enum cxgb4_uld type,
706-
const struct cxgb4_uld_info *p)
705+
void cxgb4_register_uld(enum cxgb4_uld type,
706+
const struct cxgb4_uld_info *p)
707707
{
708708
int ret = 0;
709-
unsigned int adap_idx = 0;
710709
struct adapter *adap;
711710

712711
if (type >= CXGB4_ULD_MAX)
713-
return -EINVAL;
712+
return;
714713

715714
mutex_lock(&uld_mutex);
716715
list_for_each_entry(adap, &adapter_list, list_node) {
@@ -733,52 +732,29 @@ int cxgb4_register_uld(enum cxgb4_uld type,
733732
}
734733
if (adap->flags & FULL_INIT_DONE)
735734
enable_rx_uld(adap, type);
736-
if (adap->uld[type].add) {
737-
ret = -EBUSY;
735+
if (adap->uld[type].add)
738736
goto free_irq;
739-
}
740737
ret = setup_sge_txq_uld(adap, type, p);
741738
if (ret)
742739
goto free_irq;
743740
adap->uld[type] = *p;
744741
uld_attach(adap, type);
745-
adap_idx++;
746-
}
747-
mutex_unlock(&uld_mutex);
748-
return 0;
749-
742+
continue;
750743
free_irq:
751-
if (adap->flags & FULL_INIT_DONE)
752-
quiesce_rx_uld(adap, type);
753-
if (adap->flags & USING_MSIX)
754-
free_msix_queue_irqs_uld(adap, type);
755-
free_rxq:
756-
free_sge_queues_uld(adap, type);
757-
free_queues:
758-
free_queues_uld(adap, type);
759-
out:
760-
761-
list_for_each_entry(adap, &adapter_list, list_node) {
762-
if ((type == CXGB4_ULD_CRYPTO && !is_pci_uld(adap)) ||
763-
(type != CXGB4_ULD_CRYPTO && !is_offload(adap)))
764-
continue;
765-
if (type == CXGB4_ULD_ISCSIT && is_t4(adap->params.chip))
766-
continue;
767-
if (!adap_idx)
768-
break;
769-
adap->uld[type].handle = NULL;
770-
adap->uld[type].add = NULL;
771-
release_sge_txq_uld(adap, type);
772744
if (adap->flags & FULL_INIT_DONE)
773745
quiesce_rx_uld(adap, type);
774746
if (adap->flags & USING_MSIX)
775747
free_msix_queue_irqs_uld(adap, type);
748+
free_rxq:
776749
free_sge_queues_uld(adap, type);
750+
free_queues:
777751
free_queues_uld(adap, type);
778-
adap_idx--;
752+
out:
753+
dev_warn(adap->pdev_dev,
754+
"ULD registration failed for uld type %d\n", type);
779755
}
780756
mutex_unlock(&uld_mutex);
781-
return ret;
757+
return;
782758
}
783759
EXPORT_SYMBOL(cxgb4_register_uld);
784760

drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ struct cxgb4_uld_info {
384384
int (*tx_handler)(struct sk_buff *skb, struct net_device *dev);
385385
};
386386

387-
int cxgb4_register_uld(enum cxgb4_uld type, const struct cxgb4_uld_info *p);
387+
void cxgb4_register_uld(enum cxgb4_uld type, const struct cxgb4_uld_info *p);
388388
int cxgb4_unregister_uld(enum cxgb4_uld type);
389389
int cxgb4_ofld_send(struct net_device *dev, struct sk_buff *skb);
390390
int cxgb4_immdata_send(struct net_device *dev, unsigned int idx,

0 commit comments

Comments
 (0)