Commit 90f7b11a authored by Lipeng's avatar Lipeng Committed by David S. Miller

net: hns3: Fixes the premature exit of loop when matching clients

When register/unregister ae_dev, ae_dev should match all client
in the client_list. Enet and roce can co-exists together so we
should continue checking for enet and roce presence together.
So break should not be there.

Above caused problems in loading and unloading of modules.

Fixes: 38eddd126772 ("net: hns3: Add support of the HNAE3 framework")
Signed-off-by: default avatarLipeng <lipeng321@huawei.com>
Signed-off-by: default avatarSalil Mehta <salil.mehta@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5e43aef8
...@@ -37,20 +37,15 @@ static bool hnae3_client_match(enum hnae3_client_type client_type, ...@@ -37,20 +37,15 @@ static bool hnae3_client_match(enum hnae3_client_type client_type,
} }
static int hnae3_match_n_instantiate(struct hnae3_client *client, static int hnae3_match_n_instantiate(struct hnae3_client *client,
struct hnae3_ae_dev *ae_dev, struct hnae3_ae_dev *ae_dev, bool is_reg)
bool is_reg, bool *matched)
{ {
int ret; int ret;
*matched = false;
/* check if this client matches the type of ae_dev */ /* check if this client matches the type of ae_dev */
if (!(hnae3_client_match(client->type, ae_dev->dev_type) && if (!(hnae3_client_match(client->type, ae_dev->dev_type) &&
hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B))) { hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B))) {
return 0; return 0;
} }
/* there is a match of client and dev */
*matched = true;
/* now, (un-)instantiate client by calling lower layer */ /* now, (un-)instantiate client by calling lower layer */
if (is_reg) { if (is_reg) {
...@@ -69,7 +64,6 @@ int hnae3_register_client(struct hnae3_client *client) ...@@ -69,7 +64,6 @@ int hnae3_register_client(struct hnae3_client *client)
{ {
struct hnae3_client *client_tmp; struct hnae3_client *client_tmp;
struct hnae3_ae_dev *ae_dev; struct hnae3_ae_dev *ae_dev;
bool matched;
int ret = 0; int ret = 0;
mutex_lock(&hnae3_common_lock); mutex_lock(&hnae3_common_lock);
...@@ -86,7 +80,7 @@ int hnae3_register_client(struct hnae3_client *client) ...@@ -86,7 +80,7 @@ int hnae3_register_client(struct hnae3_client *client)
/* if the client could not be initialized on current port, for /* if the client could not be initialized on current port, for
* any error reasons, move on to next available port * any error reasons, move on to next available port
*/ */
ret = hnae3_match_n_instantiate(client, ae_dev, true, &matched); ret = hnae3_match_n_instantiate(client, ae_dev, true);
if (ret) if (ret)
dev_err(&ae_dev->pdev->dev, dev_err(&ae_dev->pdev->dev,
"match and instantiation failed for port\n"); "match and instantiation failed for port\n");
...@@ -102,12 +96,11 @@ EXPORT_SYMBOL(hnae3_register_client); ...@@ -102,12 +96,11 @@ EXPORT_SYMBOL(hnae3_register_client);
void hnae3_unregister_client(struct hnae3_client *client) void hnae3_unregister_client(struct hnae3_client *client)
{ {
struct hnae3_ae_dev *ae_dev; struct hnae3_ae_dev *ae_dev;
bool matched;
mutex_lock(&hnae3_common_lock); mutex_lock(&hnae3_common_lock);
/* un-initialize the client on every matched port */ /* un-initialize the client on every matched port */
list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) { list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) {
hnae3_match_n_instantiate(client, ae_dev, false, &matched); hnae3_match_n_instantiate(client, ae_dev, false);
} }
list_del(&client->node); list_del(&client->node);
...@@ -124,7 +117,6 @@ int hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo) ...@@ -124,7 +117,6 @@ int hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo)
const struct pci_device_id *id; const struct pci_device_id *id;
struct hnae3_ae_dev *ae_dev; struct hnae3_ae_dev *ae_dev;
struct hnae3_client *client; struct hnae3_client *client;
bool matched;
int ret = 0; int ret = 0;
mutex_lock(&hnae3_common_lock); mutex_lock(&hnae3_common_lock);
...@@ -151,13 +143,10 @@ int hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo) ...@@ -151,13 +143,10 @@ int hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo)
* initialize the figure out client instance * initialize the figure out client instance
*/ */
list_for_each_entry(client, &hnae3_client_list, node) { list_for_each_entry(client, &hnae3_client_list, node) {
ret = hnae3_match_n_instantiate(client, ae_dev, true, ret = hnae3_match_n_instantiate(client, ae_dev, true);
&matched);
if (ret) if (ret)
dev_err(&ae_dev->pdev->dev, dev_err(&ae_dev->pdev->dev,
"match and instantiation failed\n"); "match and instantiation failed\n");
if (matched)
break;
} }
} }
...@@ -175,7 +164,6 @@ void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo) ...@@ -175,7 +164,6 @@ void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo)
const struct pci_device_id *id; const struct pci_device_id *id;
struct hnae3_ae_dev *ae_dev; struct hnae3_ae_dev *ae_dev;
struct hnae3_client *client; struct hnae3_client *client;
bool matched;
mutex_lock(&hnae3_common_lock); mutex_lock(&hnae3_common_lock);
/* Check if there are matched ae_dev */ /* Check if there are matched ae_dev */
...@@ -187,12 +175,8 @@ void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo) ...@@ -187,12 +175,8 @@ void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo)
/* check the client list for the match with this ae_dev type and /* check the client list for the match with this ae_dev type and
* un-initialize the figure out client instance * un-initialize the figure out client instance
*/ */
list_for_each_entry(client, &hnae3_client_list, node) { list_for_each_entry(client, &hnae3_client_list, node)
hnae3_match_n_instantiate(client, ae_dev, false, hnae3_match_n_instantiate(client, ae_dev, false);
&matched);
if (matched)
break;
}
ae_algo->ops->uninit_ae_dev(ae_dev); ae_algo->ops->uninit_ae_dev(ae_dev);
hnae_set_bit(ae_dev->flag, HNAE3_DEV_INITED_B, 0); hnae_set_bit(ae_dev->flag, HNAE3_DEV_INITED_B, 0);
...@@ -212,7 +196,6 @@ int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev) ...@@ -212,7 +196,6 @@ int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev)
const struct pci_device_id *id; const struct pci_device_id *id;
struct hnae3_ae_algo *ae_algo; struct hnae3_ae_algo *ae_algo;
struct hnae3_client *client; struct hnae3_client *client;
bool matched;
int ret = 0; int ret = 0;
mutex_lock(&hnae3_common_lock); mutex_lock(&hnae3_common_lock);
...@@ -246,13 +229,10 @@ int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev) ...@@ -246,13 +229,10 @@ int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev)
* initialize the figure out client instance * initialize the figure out client instance
*/ */
list_for_each_entry(client, &hnae3_client_list, node) { list_for_each_entry(client, &hnae3_client_list, node) {
ret = hnae3_match_n_instantiate(client, ae_dev, true, ret = hnae3_match_n_instantiate(client, ae_dev, true);
&matched);
if (ret) if (ret)
dev_err(&ae_dev->pdev->dev, dev_err(&ae_dev->pdev->dev,
"match and instantiation failed\n"); "match and instantiation failed\n");
if (matched)
break;
} }
out_err: out_err:
...@@ -270,7 +250,6 @@ void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev) ...@@ -270,7 +250,6 @@ void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev)
const struct pci_device_id *id; const struct pci_device_id *id;
struct hnae3_ae_algo *ae_algo; struct hnae3_ae_algo *ae_algo;
struct hnae3_client *client; struct hnae3_client *client;
bool matched;
mutex_lock(&hnae3_common_lock); mutex_lock(&hnae3_common_lock);
/* Check if there are matched ae_algo */ /* Check if there are matched ae_algo */
...@@ -279,12 +258,8 @@ void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev) ...@@ -279,12 +258,8 @@ void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev)
if (!id) if (!id)
continue; continue;
list_for_each_entry(client, &hnae3_client_list, node) { list_for_each_entry(client, &hnae3_client_list, node)
hnae3_match_n_instantiate(client, ae_dev, false, hnae3_match_n_instantiate(client, ae_dev, false);
&matched);
if (matched)
break;
}
ae_algo->ops->uninit_ae_dev(ae_dev); ae_algo->ops->uninit_ae_dev(ae_dev);
hnae_set_bit(ae_dev->flag, HNAE3_DEV_INITED_B, 0); hnae_set_bit(ae_dev->flag, HNAE3_DEV_INITED_B, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment