can: raw: random optimizations
Subsystems (4)
cover can: raw: random optimizations
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(-)
Signature · 1 line
2.25.1
PATCH 1/2 can: raw: process optimization in raw_init()
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.
--- net/can/raw.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
net/can/raw.c +11 -3
@@ -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; }
Signature · 1 line
2.25.1
PATCH 2/2 can: raw: use guard clause to optimize nesting in raw_rcv()
In reply to Ziyang XuanWe can use guard clause to optimize nesting codes like if (condition) { ... } else { return; } in raw_rcv();
--- net/can/raw.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
net/can/raw.c +6 -7
@@ -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;
Signature · 1 line
2.25.1
Quoted 1 line · Ziyang Xuan
Do some small optimizations for
can_raw.
Applied to linux-can-next.
Thanks,
Marc
Signature · 4 lines
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 |