Skip to content

Commit 90f7b11

Browse files
321lipengdavem330
authored andcommitted
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: Lipeng <lipeng321@huawei.com> Signed-off-by: Salil Mehta <salil.mehta@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5e43aef commit 90f7b11

File tree

1 file changed

+9
-34
lines changed
  • drivers/net/ethernet/hisilicon/hns3

1 file changed

+9
-34
lines changed

drivers/net/ethernet/hisilicon/hns3/hnae3.c

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,15 @@ static bool hnae3_client_match(enum hnae3_client_type client_type,
3737
}
3838

3939
static int hnae3_match_n_instantiate(struct hnae3_client *client,
40-
struct hnae3_ae_dev *ae_dev,
41-
bool is_reg, bool *matched)
40+
struct hnae3_ae_dev *ae_dev, bool is_reg)
4241
{
4342
int ret;
4443

45-
*matched = false;
46-
4744
/* check if this client matches the type of ae_dev */
4845
if (!(hnae3_client_match(client->type, ae_dev->dev_type) &&
4946
hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B))) {
5047
return 0;
5148
}
52-
/* there is a match of client and dev */
53-
*matched = true;
5449

5550
/* now, (un-)instantiate client by calling lower layer */
5651
if (is_reg) {
@@ -69,7 +64,6 @@ int hnae3_register_client(struct hnae3_client *client)
6964
{
7065
struct hnae3_client *client_tmp;
7166
struct hnae3_ae_dev *ae_dev;
72-
bool matched;
7367
int ret = 0;
7468

7569
mutex_lock(&hnae3_common_lock);
@@ -86,7 +80,7 @@ int hnae3_register_client(struct hnae3_client *client)
8680
/* if the client could not be initialized on current port, for
8781
* any error reasons, move on to next available port
8882
*/
89-
ret = hnae3_match_n_instantiate(client, ae_dev, true, &matched);
83+
ret = hnae3_match_n_instantiate(client, ae_dev, true);
9084
if (ret)
9185
dev_err(&ae_dev->pdev->dev,
9286
"match and instantiation failed for port\n");
@@ -102,12 +96,11 @@ EXPORT_SYMBOL(hnae3_register_client);
10296
void hnae3_unregister_client(struct hnae3_client *client)
10397
{
10498
struct hnae3_ae_dev *ae_dev;
105-
bool matched;
10699

107100
mutex_lock(&hnae3_common_lock);
108101
/* un-initialize the client on every matched port */
109102
list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) {
110-
hnae3_match_n_instantiate(client, ae_dev, false, &matched);
103+
hnae3_match_n_instantiate(client, ae_dev, false);
111104
}
112105

113106
list_del(&client->node);
@@ -124,7 +117,6 @@ int hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo)
124117
const struct pci_device_id *id;
125118
struct hnae3_ae_dev *ae_dev;
126119
struct hnae3_client *client;
127-
bool matched;
128120
int ret = 0;
129121

130122
mutex_lock(&hnae3_common_lock);
@@ -151,13 +143,10 @@ int hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo)
151143
* initialize the figure out client instance
152144
*/
153145
list_for_each_entry(client, &hnae3_client_list, node) {
154-
ret = hnae3_match_n_instantiate(client, ae_dev, true,
155-
&matched);
146+
ret = hnae3_match_n_instantiate(client, ae_dev, true);
156147
if (ret)
157148
dev_err(&ae_dev->pdev->dev,
158149
"match and instantiation failed\n");
159-
if (matched)
160-
break;
161150
}
162151
}
163152

@@ -175,7 +164,6 @@ void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo)
175164
const struct pci_device_id *id;
176165
struct hnae3_ae_dev *ae_dev;
177166
struct hnae3_client *client;
178-
bool matched;
179167

180168
mutex_lock(&hnae3_common_lock);
181169
/* Check if there are matched ae_dev */
@@ -187,12 +175,8 @@ void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo)
187175
/* check the client list for the match with this ae_dev type and
188176
* un-initialize the figure out client instance
189177
*/
190-
list_for_each_entry(client, &hnae3_client_list, node) {
191-
hnae3_match_n_instantiate(client, ae_dev, false,
192-
&matched);
193-
if (matched)
194-
break;
195-
}
178+
list_for_each_entry(client, &hnae3_client_list, node)
179+
hnae3_match_n_instantiate(client, ae_dev, false);
196180

197181
ae_algo->ops->uninit_ae_dev(ae_dev);
198182
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)
212196
const struct pci_device_id *id;
213197
struct hnae3_ae_algo *ae_algo;
214198
struct hnae3_client *client;
215-
bool matched;
216199
int ret = 0;
217200

218201
mutex_lock(&hnae3_common_lock);
@@ -246,13 +229,10 @@ int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev)
246229
* initialize the figure out client instance
247230
*/
248231
list_for_each_entry(client, &hnae3_client_list, node) {
249-
ret = hnae3_match_n_instantiate(client, ae_dev, true,
250-
&matched);
232+
ret = hnae3_match_n_instantiate(client, ae_dev, true);
251233
if (ret)
252234
dev_err(&ae_dev->pdev->dev,
253235
"match and instantiation failed\n");
254-
if (matched)
255-
break;
256236
}
257237

258238
out_err:
@@ -270,7 +250,6 @@ void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev)
270250
const struct pci_device_id *id;
271251
struct hnae3_ae_algo *ae_algo;
272252
struct hnae3_client *client;
273-
bool matched;
274253

275254
mutex_lock(&hnae3_common_lock);
276255
/* Check if there are matched ae_algo */
@@ -279,12 +258,8 @@ void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev)
279258
if (!id)
280259
continue;
281260

282-
list_for_each_entry(client, &hnae3_client_list, node) {
283-
hnae3_match_n_instantiate(client, ae_dev, false,
284-
&matched);
285-
if (matched)
286-
break;
287-
}
261+
list_for_each_entry(client, &hnae3_client_list, node)
262+
hnae3_match_n_instantiate(client, ae_dev, false);
288263

289264
ae_algo->ops->uninit_ae_dev(ae_dev);
290265
hnae_set_bit(ae_dev->flag, HNAE3_DEV_INITED_B, 0);

0 commit comments

Comments
 (0)