All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zheng Yongjun <zhengyongjun3@huawei.com>
To: <jreuter@yaina.de>, <ralf@linux-mips.org>, <davem@davemloft.net>,
	<kuba@kernel.org>, <linux-hams@vger.kernel.org>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH -next] net: ax25: Fix error path of ax25_init()
Date: Sat, 31 Jul 2021 07:27:32 +0000	[thread overview]
Message-ID: <20210731072732.103631-1-zhengyongjun3@huawei.com> (raw)

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


WARNING: multiple messages have this Message-ID (diff)
From: Zheng Yongjun <zhengyongjun3@huawei.com>
To: jreuter@yaina.de, ralf@linux-mips.org, davem@davemloft.net,
	kuba@kernel.org, linux-hams@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH -next] net: ax25: Fix error path of ax25_init()
Date: Sat, 31 Jul 2021 07:27:32 +0000	[thread overview]
Message-ID: <20210731072732.103631-1-zhengyongjun3@huawei.com> (raw)

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


             reply	other threads:[~2021-07-31  7:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-31  7:27 Zheng Yongjun [this message]
2021-07-31  7:27 ` [PATCH -next] net: ax25: Fix error path of ax25_init() Zheng Yongjun
2021-07-31  9:25 ` kernel test robot
2021-07-31  9:25   ` kernel test robot

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=20210731072732.103631-1-zhengyongjun3@huawei.com \
    --to=zhengyongjun3@huawei.com \
    --cc=davem@davemloft.net \
    --cc=jreuter@yaina.de \
    --cc=kuba@kernel.org \
    --cc=linux-hams@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ralf@linux-mips.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 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.