From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50C3AC433F5 for ; Thu, 9 Sep 2021 11:46:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3BB9E61242 for ; Thu, 9 Sep 2021 11:46:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240590AbhIILsD (ORCPT ); Thu, 9 Sep 2021 07:48:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:47118 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239070AbhIILpq (ORCPT ); Thu, 9 Sep 2021 07:45:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A471861246; Thu, 9 Sep 2021 11:42:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187767; bh=KMk49yov0aAIJvFdbrdKIwR8Zc6m977asTdDdJtRt4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YB+m17rRJWmjbkrvhgJKdxIBEoHEj9KcF3g5zleqpevWDFO1uIHPrL3WkGbrNU044 yq4j7nok1z02nCslXttJeJHbAIhatcBrdGPNTBBXN0BKn9vCyVQe4+cYlaudnYWRz0 dSh4vocAigfhU/+xWO5gtL0RAM5L3A+NKS4WZOUswxl3exSqBt2JL8o7PxRh+U/gNj oLkZqMPAMfn160FRwp9LiMizeVmBxtaayZaR7BOTCABlkomFv052tTrWKx6uSCumVr QINyaTS5kqxz85Ez11Pdof1bpHZBAjshxeFkBe4AnNAbS/j/LLIXnKYSWFkg6xPGcB SH6TkMYAwH8dA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jiri Slaby , Chris Zankel , Max Filippov , linux-xtensa@linux-xtensa.org, Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 5.14 079/252] xtensa: ISS: don't panic in rs_init Date: Thu, 9 Sep 2021 07:38:13 -0400 Message-Id: <20210909114106.141462-79-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Slaby [ Upstream commit 23411c720052ad860b3e579ee4873511e367130a ] 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. Cc: Chris Zankel Cc: Max Filippov Cc: linux-xtensa@linux-xtensa.org Acked-by: Max Filippov Signed-off-by: Jiri Slaby Link: https://lore.kernel.org/r/20210723074317.32690-2-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- 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.30.2