* [PATCH net-next 0/2] can: raw: random optimizations
@ 2022-08-27 7:20 Ziyang Xuan
2022-08-27 7:20 ` [PATCH net-next 1/2] can: raw: process optimization in raw_init() Ziyang Xuan
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ziyang Xuan @ 2022-08-27 7:20 UTC (permalink / raw)
To: socketcan, mkl, linux-can, netdev
Cc: davem, edumazet, kuba, pabeni, linux-kernel
Do some small optimizations for can_raw.
Ziyang Xuan (2):
can: raw: process optimization in raw_init()
can: raw: use guard clause to optimize nesting in raw_rcv()
net/can/raw.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net-next 1/2] can: raw: process optimization in raw_init()
2022-08-27 7:20 [PATCH net-next 0/2] can: raw: random optimizations Ziyang Xuan
@ 2022-08-27 7:20 ` Ziyang Xuan
2022-08-27 7:20 ` [PATCH net-next 2/2] can: raw: use guard clause to optimize nesting in raw_rcv() Ziyang Xuan
2022-09-06 6:42 ` [PATCH net-next 0/2] can: raw: random optimizations Marc Kleine-Budde
2 siblings, 0 replies; 4+ messages in thread
From: Ziyang Xuan @ 2022-08-27 7:20 UTC (permalink / raw)
To: socketcan, mkl, linux-can, netdev
Cc: davem, edumazet, kuba, pabeni, linux-kernel
Now, register notifier after register proto successfully. It can create
raw socket and set socket options once register proto successfully, so it
is possible missing notifier event before register notifier successfully
although this is a low probability scenario.
Move notifier registration to the front of proto registration like done
in j1939. In addition, register_netdevice_notifier() may fail, check its
result is necessary.
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
net/can/raw.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/net/can/raw.c b/net/can/raw.c
index d1bd9cc51ebe..9ae7c4206b9a 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -942,12 +942,20 @@ static __init int raw_module_init(void)
pr_info("can: raw protocol\n");
+ err = register_netdevice_notifier(&canraw_notifier);
+ if (err)
+ return err;
+
err = can_proto_register(&raw_can_proto);
- if (err < 0)
+ if (err < 0) {
pr_err("can: registration of raw protocol failed\n");
- else
- register_netdevice_notifier(&canraw_notifier);
+ goto register_proto_failed;
+ }
+ return 0;
+
+register_proto_failed:
+ unregister_netdevice_notifier(&canraw_notifier);
return err;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next 2/2] can: raw: use guard clause to optimize nesting in raw_rcv()
2022-08-27 7:20 [PATCH net-next 0/2] can: raw: random optimizations Ziyang Xuan
2022-08-27 7:20 ` [PATCH net-next 1/2] can: raw: process optimization in raw_init() Ziyang Xuan
@ 2022-08-27 7:20 ` Ziyang Xuan
2022-09-06 6:42 ` [PATCH net-next 0/2] can: raw: random optimizations Marc Kleine-Budde
2 siblings, 0 replies; 4+ messages in thread
From: Ziyang Xuan @ 2022-08-27 7:20 UTC (permalink / raw)
To: socketcan, mkl, linux-can, netdev
Cc: davem, edumazet, kuba, pabeni, linux-kernel
We can use guard clause to optimize nesting codes like
if (condition) { ... } else { return; } in raw_rcv();
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
net/can/raw.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/net/can/raw.c b/net/can/raw.c
index 9ae7c4206b9a..e7dfa3584e29 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -136,14 +136,13 @@ static void raw_rcv(struct sk_buff *oskb, void *data)
/* eliminate multiple filter matches for the same skb */
if (this_cpu_ptr(ro->uniq)->skb == oskb &&
this_cpu_ptr(ro->uniq)->skbcnt == can_skb_prv(oskb)->skbcnt) {
- if (ro->join_filters) {
- this_cpu_inc(ro->uniq->join_rx_count);
- /* drop frame until all enabled filters matched */
- if (this_cpu_ptr(ro->uniq)->join_rx_count < ro->count)
- return;
- } else {
+ if (!ro->join_filters)
+ return;
+
+ this_cpu_inc(ro->uniq->join_rx_count);
+ /* drop frame until all enabled filters matched */
+ if (this_cpu_ptr(ro->uniq)->join_rx_count < ro->count)
return;
- }
} else {
this_cpu_ptr(ro->uniq)->skb = oskb;
this_cpu_ptr(ro->uniq)->skbcnt = can_skb_prv(oskb)->skbcnt;
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next 0/2] can: raw: random optimizations
2022-08-27 7:20 [PATCH net-next 0/2] can: raw: random optimizations Ziyang Xuan
2022-08-27 7:20 ` [PATCH net-next 1/2] can: raw: process optimization in raw_init() Ziyang Xuan
2022-08-27 7:20 ` [PATCH net-next 2/2] can: raw: use guard clause to optimize nesting in raw_rcv() Ziyang Xuan
@ 2022-09-06 6:42 ` Marc Kleine-Budde
2 siblings, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2022-09-06 6:42 UTC (permalink / raw)
To: Ziyang Xuan
Cc: socketcan, linux-can, netdev, davem, edumazet, kuba, pabeni,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 406 bytes --]
On 27.08.2022 15:20:09, Ziyang Xuan wrote:
> Do some small optimizations for can_raw.
Applied to linux-can-next.
Thanks,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-06 6:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-27 7:20 [PATCH net-next 0/2] can: raw: random optimizations Ziyang Xuan
2022-08-27 7:20 ` [PATCH net-next 1/2] can: raw: process optimization in raw_init() Ziyang Xuan
2022-08-27 7:20 ` [PATCH net-next 2/2] can: raw: use guard clause to optimize nesting in raw_rcv() Ziyang Xuan
2022-09-06 6:42 ` [PATCH net-next 0/2] can: raw: random optimizations Marc Kleine-Budde
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).