Skip to contentSkip to conversation

net: smc: fix error return code of smc_diag_dump_proto()

PATCH In review Jia-Ju Bai 2 participants 2 messages Mar 5, 2021

Subsystems (4)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 net: smc: fix error return code of smc_diag_dump_proto()

When the list of head is empty, no error return code of smc_diag_dump_proto() is assigned.
To fix this bug, rc is assigned with -ENOENT as error return code.

---
 net/smc/smc_diag.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/smc/smc_diag.c +3 -1
index c952986a6aca..a90889482842 100644
@@ -201,8 +201,10 @@ static int smc_diag_dump_proto(struct proto *prot, struct sk_buff *skb,
 
 	read_lock(&prot->h.smc_hash->lock);
 	head = &prot->h.smc_hash->ht;
-	if (hlist_empty(head))
+	if (hlist_empty(head)) {
+		rc = -ENOENT;
 		goto out;
+	}
 
 	sk_for_each(sk, head) {
 		if (!net_eq(sock_net(sk), net))
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Jia-Ju Bai

When the list of head is empty, no error return code of smc_diag_dump_proto() is assigned.
To fix this bug, rc is assigned with -ENOENT as error return code.

Your change would break smc_diag_dump().
When there are no IPv4 sockets (SMCPROTO_SMC) in the list and -ENOENT is returned then smc_diag_dump() will not try to dump any IPv6 sockets (SMCPROTO_SMC6). Returning zero is correct here.

Quoted 24 lines
---
 net/smc/smc_diag.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/smc/smc_diag.c +3 -1
index c952986a6aca..a90889482842 100644
@@ -201,8 +201,10 @@ static int smc_diag_dump_proto(struct proto *prot, struct sk_buff *skb,
 
 	read_lock(&prot->h.smc_hash->lock);
 	head = &prot->h.smc_hash->ht;
-	if (hlist_empty(head))
+	if (hlist_empty(head)) {
+		rc = -ENOENT;
 		goto out;
+	}
 
 	sk_for_each(sk, head) {
 		if (!net_eq(sock_net(sk), net))
Signature · 3 lines
Karsten

(I'm a dude)