Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp446540pxb; Thu, 9 Sep 2021 04:47:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKSwb42qDzgQQMSv/OrJE0WWjrKuGEovPpGFsibgwY1Su/Mx46QzbdAGQDUjUq4OWXsQ52 X-Received: by 2002:a6b:3f02:: with SMTP id m2mr2240482ioa.136.1631188068783; Thu, 09 Sep 2021 04:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631188068; cv=none; d=google.com; s=arc-20160816; b=c6Ictemva7XjM3RutA6X3PMpe16GxClMgAB/pw8GnyGYVRjQ9sciKAtgbEzWrRSuV/ JXEBJZLVeQ1aSWZ8l8j6qekkDr65kEhJ+sOzDI1POHl/W7HNsDfLYm/J79nDQmq3HNhS G/Yq6o3zSIUkcCQ2BsbguvyJhUVHPWV3bbMJxxsb3CdXKEp+2DI5WgErvV9I1BHH5qSg +nPVr9yATek8u9q0ftOaa1mUz+hIU9z39s5RLg8spa3xXA3FAadkfVQLV61bwm7oczV3 WJih6b0A0Paz/lhCTFT1HMvNYFYEjrqgjTaIaFozaJ8Qe+GX2nNYbvF9jPFjDAx9g4hu K1XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gzLd8n8ODfrDumMitooF4mwFKMHpKbkSthVdPBXxkzc=; b=zYKU780w3/HmkeWeXyQL09eF3uu8z8de/wXrYYcFIw/oTBZQvUP2rD9tXVyb3LPz6R k9LRZ1l4fnze0jWXX1xaHAanv+QG0FInIfgZHAkQP8WvJfLDY7jj0XaeY5ZSmVc+6gOJ 27iDV2ye+41apBI0xHRBbmTkMcc5irjkyQsY2/4Nv1I4l3kUx5prB3Wm9tBX1f5L+wjd i6UTlgVlv6c7/DPIBOK/08BOq+HwtuqLEIXQGxdnnXSLKKLehdITR/Fuq/CHfmXSGDRr utO5k7o+OzPB6CG766JXBxigAYf15MAeidHPHX5/xaFZUd8d1HkYxA7qww9m3oCvPZl5 6Csg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YB+m17rR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p6si1419742ilj.154.2021.09.09.04.47.37; Thu, 09 Sep 2021 04:47:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YB+m17rR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241823AbhIILsC (ORCPT + 99 others); Thu, 9 Sep 2021 07:48:02 -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