From: Peter Lafreniere <peter@n8pjl.ca>
To: linux-hams@vger.kernel.org
Cc: Peter Lafreniere <peter@n8pjl.ca>, netdev@vger.kernel.org
Subject: [PATCH net-next] ax25: exit linked-list searches earlier
Date: Fri, 7 Apr 2023 10:20:42 -0400 [thread overview]
Message-ID: <20230407142042.11901-1-peter@n8pjl.ca> (raw)
There's no need to loop until the end of the list if we have a result.
Device callsigns are unique, so there can only be one dev returned from
ax25_addr_ax25dev(). If not, there would be inconsistencies based on
order of insertion, and refcount leaks.
Same reasoning for ax25_get_route() as above.
Signed-off-by: Peter Lafreniere <peter@n8pjl.ca>
---
net/ax25/ax25_dev.c | 4 +++-
net/ax25/ax25_route.c | 3 +++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/ax25/ax25_dev.c b/net/ax25/ax25_dev.c
index c5462486dbca..8186faea6b0d 100644
--- a/net/ax25/ax25_dev.c
+++ b/net/ax25/ax25_dev.c
@@ -34,11 +34,13 @@ ax25_dev *ax25_addr_ax25dev(ax25_address *addr)
ax25_dev *ax25_dev, *res = NULL;
spin_lock_bh(&ax25_dev_lock);
- for (ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next)
+ for (ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) {
if (ax25cmp(addr, (const ax25_address *)ax25_dev->dev->dev_addr) == 0) {
res = ax25_dev;
ax25_dev_hold(ax25_dev);
+ break;
}
+ }
spin_unlock_bh(&ax25_dev_lock);
return res;
diff --git a/net/ax25/ax25_route.c b/net/ax25/ax25_route.c
index b7c4d656a94b..ed2cab200589 100644
--- a/net/ax25/ax25_route.c
+++ b/net/ax25/ax25_route.c
@@ -364,6 +364,9 @@ ax25_route *ax25_get_route(ax25_address *addr, struct net_device *dev)
if (ax25cmp(&ax25_rt->callsign, &null_ax25_address) == 0 && ax25_rt->dev == dev)
ax25_def_rt = ax25_rt;
}
+
+ if (ax25_spe_rt != NULL)
+ break;
}
ax25_rt = ax25_def_rt;
--
2.40.0
next reply other threads:[~2023-04-07 14:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-07 14:20 Peter Lafreniere [this message]
2023-04-07 15:14 ` [PATCH net-next] ax25: exit linked-list searches earlier Dan Carpenter
2023-04-14 14:33 ` [PATCH v2 " Peter Lafreniere
2023-04-18 7:15 ` Paolo Abeni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230407142042.11901-1-peter@n8pjl.ca \
--to=peter@n8pjl.ca \
--cc=linux-hams@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).