* [PATCH v2 0/2] can: bcm: can: bcm: random optimizations
@ 2022-09-15 1:55 Ziyang Xuan
2022-09-15 1:55 ` [PATCH v2 1/2] can: bcm: registration process optimization in bcm_module_init() Ziyang Xuan
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Ziyang Xuan @ 2022-09-15 1:55 UTC (permalink / raw)
To: socketcan, mkl, davem, kuba, linux-can, netdev; +Cc: linux-kernel
Do some small optimization for can_bcm.
---
v2:
- Continue to update currframe when can_send() failed in patch 2.
- Remove ‘Fixes’ tag in patch 2.
Ziyang Xuan (2):
can: bcm: registration process optimization in bcm_module_init()
can: bcm: check the result of can_send() in bcm_can_tx()
net/can/bcm.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] can: bcm: registration process optimization in bcm_module_init()
2022-09-15 1:55 [PATCH v2 0/2] can: bcm: can: bcm: random optimizations Ziyang Xuan
@ 2022-09-15 1:55 ` Ziyang Xuan
2022-09-15 1:55 ` [PATCH v2 2/2] can: bcm: check the result of can_send() in bcm_can_tx() Ziyang Xuan
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Ziyang Xuan @ 2022-09-15 1:55 UTC (permalink / raw)
To: socketcan, mkl, davem, kuba, linux-can, netdev; +Cc: linux-kernel
Now, register_netdevice_notifier() and register_pernet_subsys() are both
after can_proto_register(). It can create CAN_BCM socket and process socket
once can_proto_register() successfully, so it is possible missing notifier
event or proc node creation because notifier or bcm proc directory is not
registered or created yet. Although this is a low probability scenario, it
is not impossible.
Move register_pernet_subsys() and register_netdevice_notifier() to the
front of can_proto_register(). In addition, register_pernet_subsys() and
register_netdevice_notifier() may fail, check their results are necessary.
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
net/can/bcm.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/net/can/bcm.c b/net/can/bcm.c
index e60161bec850..e2783156bfd1 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -1744,15 +1744,27 @@ static int __init bcm_module_init(void)
pr_info("can: broadcast manager protocol\n");
+ err = register_pernet_subsys(&canbcm_pernet_ops);
+ if (err)
+ return err;
+
+ err = register_netdevice_notifier(&canbcm_notifier);
+ if (err)
+ goto register_notifier_failed;
+
err = can_proto_register(&bcm_can_proto);
if (err < 0) {
printk(KERN_ERR "can: registration of bcm protocol failed\n");
- return err;
+ goto register_proto_failed;
}
- register_pernet_subsys(&canbcm_pernet_ops);
- register_netdevice_notifier(&canbcm_notifier);
return 0;
+
+register_proto_failed:
+ unregister_netdevice_notifier(&canbcm_notifier);
+register_notifier_failed:
+ unregister_pernet_subsys(&canbcm_pernet_ops);
+ return err;
}
static void __exit bcm_module_exit(void)
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] can: bcm: check the result of can_send() in bcm_can_tx()
2022-09-15 1:55 [PATCH v2 0/2] can: bcm: can: bcm: random optimizations Ziyang Xuan
2022-09-15 1:55 ` [PATCH v2 1/2] can: bcm: registration process optimization in bcm_module_init() Ziyang Xuan
@ 2022-09-15 1:55 ` Ziyang Xuan
2022-09-15 5:21 ` [PATCH v2 0/2] can: bcm: can: bcm: random optimizations Oliver Hartkopp
2022-09-23 12:12 ` Marc Kleine-Budde
3 siblings, 0 replies; 5+ messages in thread
From: Ziyang Xuan @ 2022-09-15 1:55 UTC (permalink / raw)
To: socketcan, mkl, davem, kuba, linux-can, netdev; +Cc: linux-kernel
If can_send() fail, it should not update frames_abs counter
in bcm_can_tx(). Add the result check for can_send() in bcm_can_tx().
Suggested-by: Marc Kleine-Budde <mkl@pengutronix.de>
Suggested-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
net/can/bcm.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/can/bcm.c b/net/can/bcm.c
index e2783156bfd1..a571c8d4338b 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -274,6 +274,7 @@ static void bcm_can_tx(struct bcm_op *op)
struct sk_buff *skb;
struct net_device *dev;
struct canfd_frame *cf = op->frames + op->cfsiz * op->currframe;
+ int err;
/* no target device? => exit */
if (!op->ifindex)
@@ -298,11 +299,11 @@ static void bcm_can_tx(struct bcm_op *op)
/* send with loopback */
skb->dev = dev;
can_skb_set_owner(skb, op->sk);
- can_send(skb, 1);
+ err = can_send(skb, 1);
+ if (!err)
+ op->frames_abs++;
- /* update statistics */
op->currframe++;
- op->frames_abs++;
/* reached last frame? */
if (op->currframe >= op->nframes)
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/2] can: bcm: can: bcm: random optimizations
2022-09-15 1:55 [PATCH v2 0/2] can: bcm: can: bcm: random optimizations Ziyang Xuan
2022-09-15 1:55 ` [PATCH v2 1/2] can: bcm: registration process optimization in bcm_module_init() Ziyang Xuan
2022-09-15 1:55 ` [PATCH v2 2/2] can: bcm: check the result of can_send() in bcm_can_tx() Ziyang Xuan
@ 2022-09-15 5:21 ` Oliver Hartkopp
2022-09-23 12:12 ` Marc Kleine-Budde
3 siblings, 0 replies; 5+ messages in thread
From: Oliver Hartkopp @ 2022-09-15 5:21 UTC (permalink / raw)
To: Ziyang Xuan, mkl, davem, kuba, linux-can, netdev; +Cc: linux-kernel
On 15.09.22 03:55, Ziyang Xuan wrote:
> Do some small optimization for can_bcm.
>
> ---
> v2:
> - Continue to update currframe when can_send() failed in patch 2.
> - Remove ‘Fixes’ tag in patch 2.
For this series:
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Many Thanks!
>
> Ziyang Xuan (2):
> can: bcm: registration process optimization in bcm_module_init()
> can: bcm: check the result of can_send() in bcm_can_tx()
>
> net/can/bcm.c | 25 +++++++++++++++++++------
> 1 file changed, 19 insertions(+), 6 deletions(-)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/2] can: bcm: can: bcm: random optimizations
2022-09-15 1:55 [PATCH v2 0/2] can: bcm: can: bcm: random optimizations Ziyang Xuan
` (2 preceding siblings ...)
2022-09-15 5:21 ` [PATCH v2 0/2] can: bcm: can: bcm: random optimizations Oliver Hartkopp
@ 2022-09-23 12:12 ` Marc Kleine-Budde
3 siblings, 0 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2022-09-23 12:12 UTC (permalink / raw)
To: Ziyang Xuan; +Cc: socketcan, davem, kuba, linux-can, netdev, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 405 bytes --]
On 15.09.2022 09:55:54, Ziyang Xuan wrote:
> Do some small optimization for can_bcm.
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] 5+ messages in thread
end of thread, other threads:[~2022-09-23 12:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-15 1:55 [PATCH v2 0/2] can: bcm: can: bcm: random optimizations Ziyang Xuan
2022-09-15 1:55 ` [PATCH v2 1/2] can: bcm: registration process optimization in bcm_module_init() Ziyang Xuan
2022-09-15 1:55 ` [PATCH v2 2/2] can: bcm: check the result of can_send() in bcm_can_tx() Ziyang Xuan
2022-09-15 5:21 ` [PATCH v2 0/2] can: bcm: can: bcm: random optimizations Oliver Hartkopp
2022-09-23 12:12 ` 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).