linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jiri Slaby <jslaby@suse.cz>, Chris Zankel <chris@zankel.net>,
	Max Filippov <jcmvbkbc@gmail.com>,
	linux-xtensa@linux-xtensa.org
Subject: [PATCH 1/8] xtensa: ISS: don't panic in rs_init
Date: Fri, 23 Jul 2021 09:43:10 +0200	[thread overview]
Message-ID: <20210723074317.32690-2-jslaby@suse.cz> (raw)
In-Reply-To: <20210723074317.32690-1-jslaby@suse.cz>

While alloc_tty_driver failure in rs_init would mean we have much bigger
problem, there is no reason to panic when tty_register_driver fails
there. It can fail for various reasons.

So handle the failure gracefully. Actually handle them both while at it.
This will make at least the console functional as it was enabled earlier
by console_initcall in iss_console_init. Instead of shooting down the
whole system.

We move tty_port_init() after alloc_tty_driver(), so that we don't need
to destroy the port in case the latter function fails.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: linux-xtensa@linux-xtensa.org
---
 arch/xtensa/platforms/iss/console.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
index 21184488c277..0108504dfb45 100644
--- a/arch/xtensa/platforms/iss/console.c
+++ b/arch/xtensa/platforms/iss/console.c
@@ -136,9 +136,13 @@ static const struct tty_operations serial_ops = {
 
 static int __init rs_init(void)
 {
-	tty_port_init(&serial_port);
+	int ret;
 
 	serial_driver = alloc_tty_driver(SERIAL_MAX_NUM_LINES);
+	if (!serial_driver)
+		return -ENOMEM;
+
+	tty_port_init(&serial_port);
 
 	/* Initialize the tty_driver structure */
 
@@ -156,8 +160,15 @@ static int __init rs_init(void)
 	tty_set_operations(serial_driver, &serial_ops);
 	tty_port_link_device(&serial_port, serial_driver, 0);
 
-	if (tty_register_driver(serial_driver))
-		panic("Couldn't register serial driver\n");
+	ret = tty_register_driver(serial_driver);
+	if (ret) {
+		pr_err("Couldn't register serial driver\n");
+		tty_driver_kref_put(serial_driver);
+		tty_port_destroy(&serial_port);
+
+		return ret;
+	}
+
 	return 0;
 }
 
-- 
2.32.0


  reply	other threads:[~2021-07-23  7:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23  7:43 [PATCH 0/8] Get rid of old tty_driver functions Jiri Slaby
2021-07-23  7:43 ` Jiri Slaby [this message]
2021-07-23 10:18   ` [PATCH 1/8] xtensa: ISS: don't panic in rs_init Max Filippov
2021-07-23  7:43 ` [PATCH 2/8] hvsi: don't panic on tty_register_driver failure Jiri Slaby
2021-07-23  7:43 ` [PATCH 3/8] tty: don't store semi-state into tty drivers Jiri Slaby
2021-07-23 10:23   ` Max Filippov
2021-07-23 16:37   ` Helge Deller
2021-07-23  7:43 ` [PATCH 4/8] tty: stop using alloc_tty_driver Jiri Slaby
2021-07-23  7:49   ` Samuel Iglesias Gonsálvez
2021-07-23  7:57   ` Christian Borntraeger
2021-07-23 10:16   ` David Sterba
2021-07-23 10:30   ` Max Filippov
2021-07-23  7:43 ` [PATCH 5/8] tty: drop alloc_tty_driver Jiri Slaby
2021-07-23  7:43 ` [PATCH 6/8] tty: make tty_set_operations an inline Jiri Slaby
2021-07-23  7:43 ` [PATCH 7/8] tty: drop put_tty_driver Jiri Slaby
2021-07-23  7:49   ` Samuel Iglesias Gonsálvez
2021-07-23  7:55   ` Christian Borntraeger
2021-07-23 10:16   ` David Sterba
2021-07-23 10:32   ` Max Filippov
2021-07-23 12:50   ` Alex Elder
2021-07-23  7:43 ` [PATCH 8/8] tty: pdc_cons, free tty_driver upon failure Jiri Slaby
2021-07-27 10:18 ` [PATCH 0/8] Get rid of old tty_driver functions Greg KH

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=20210723074317.32690-2-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=chris@zankel.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jcmvbkbc@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux-xtensa@linux-xtensa.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 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).