All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] net: ax25: Fix error path of ax25_init()
@ 2021-07-31  7:27 ` Zheng Yongjun
  0 siblings, 0 replies; 4+ messages in thread
From: Zheng Yongjun @ 2021-07-31  7:27 UTC (permalink / raw)
  To: jreuter, ralf, davem, kuba, linux-hams, netdev, linux-kernel

This patch add error path for ax25_init() to avoid possible crash if some
error occurs.

Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
---
 net/ax25/af_ax25.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index 2631efc..4edc322 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -1977,17 +1977,32 @@ static int __init ax25_init(void)
 {
 	int rc = proto_register(&ax25_proto, 0);
 
-	if (rc != 0)
+	if (rc)
 		goto out;
 
-	sock_register(&ax25_family_ops);
-	dev_add_pack(&ax25_packet_type);
-	register_netdevice_notifier(&ax25_dev_notifier);
+	rc = sock_register(&ax25_family_ops);
+	if (rc)
+		goto out_proto;
+	rc = dev_add_pack(&ax25_packet_type);
+	if (rc)
+		goto out_sock;
+	rc = register_netdevice_notifier(&ax25_dev_notifier);
+	if (rc)
+		goto out_dev;
 
 	proc_create_seq("ax25_route", 0444, init_net.proc_net, &ax25_rt_seqops);
 	proc_create_seq("ax25", 0444, init_net.proc_net, &ax25_info_seqops);
 	proc_create_seq("ax25_calls", 0444, init_net.proc_net,
 			&ax25_uid_seqops);
+
+	return 0;
+
+out_dev:
+	dev_remove_pack(&ax25_packet_type);
+out_sock:
+	sock_unregister(PF_AX25);
+out_proto:
+	proto_unregister(&ax25_proto);
 out:
 	return rc;
 }
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-31  9:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-31  7:27 [PATCH -next] net: ax25: Fix error path of ax25_init() Zheng Yongjun
2021-07-31  7:27 ` Zheng Yongjun
2021-07-31  9:25 ` kernel test robot
2021-07-31  9:25   ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.