Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2348841pxb; Mon, 20 Sep 2021 19:41:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAtVk0d7oCg/ZPJlpc2i6Y2toFp75+hZQxIMDM/nwyvfgZy8JCqqSwWdUpuz/3Cr65Ecl1 X-Received: by 2002:a17:906:3486:: with SMTP id g6mr33124962ejb.71.1632192110256; Mon, 20 Sep 2021 19:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192110; cv=none; d=google.com; s=arc-20160816; b=GzF7KhZgg/Omj97Gyf3dxwqAFp3kMRURsnos+E0qT0xV/hRSF8oLIir9dnqNh38WXK XeK0pKH9+L84BGY1kbTopfEXbsyLLeRiIJxtzbJdUzPpyAJe2YJrhlJgzN4KvMULOclm jG3jR26QEPDSvksAKB6WVcdSK3zLLtG2buqF8oFnVQPF4iLaoiHeubdsmLcRW7kEEM7S a6Oj2R15VDqyXHqPenLZzx2798VW75bT62vi+7dYCBS7RW2d4jg0jv1WZAePpFzQ3ylT wP6n5xreU/c218S1a0HMRK49v1wOCYHj2Q09aDuc9QWzi7yRNzgqqh9L28UIn4N+44Sk +DjA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5si5wqIDxUewRj5cPx1T/sGxphPRF7DZGYQhR/tfPas=; b=Ddlu5yCJNW9P0wqvy6Wsp1nC3TMoqsxXcAfuX3Uae4H9+WIkVGx4mFGikxE8Ne4A6y BYT8RybFft5/cMYdA983DmNCigddHyg/Fd0ftz257NFl8evv/OsWAAYvumW0sB2ZGw8D wM19zcNA3YydaTjJhBfXF3pVicmW1Ie0sGsxhgQWyX/Byva10Qnx6SVBqboyYG2BTgHq vLTfSu6acdtM2Lm1sYCSP6ydANLSNylf/jiA/D9sONPvBaFm81qVzOCpoMjVC8lZcJ0W efuwHcp5NMiFia0SuRRxRAxSnr0TF0hLC9byBHnLLv/MHg3iVpDzdFPy4HFCmzcEuMoC XTDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="kGl/tAAj"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r5si17837659edy.450.2021.09.20.19.41.26; Mon, 20 Sep 2021 19:41:50 -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=@linuxfoundation.org header.s=korg header.b="kGl/tAAj"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377031AbhITSPF (ORCPT + 99 others); Mon, 20 Sep 2021 14:15:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:33260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358883AbhITSIq (ORCPT ); Mon, 20 Sep 2021 14:08:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 704C76325D; Mon, 20 Sep 2021 17:18:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158329; bh=76eGioPcotaQYkVwzDjxwSd4GCkgGhVHJKyA11UTrHI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kGl/tAAj9ucriPD5M8NHv9enW/r6Lm74qBdNFMi9fkGAZQWwLlKJjrdcVFjBl/CDs n1nhJsMepoacp+xob+57E9QbPCkz2w5gI4bvqFQ1/alVT62F0ulyJc2rdUNhBubvSL 2cGCwBHhSw3SBpqCpU1rUgBusS+PPoJ+uPzFHi7U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Zankel , Max Filippov , linux-xtensa@linux-xtensa.org, Jiri Slaby , Sasha Levin Subject: [PATCH 5.4 106/260] xtensa: ISS: dont panic in rs_init Date: Mon, 20 Sep 2021 18:42:04 +0200 Message-Id: <20210920163934.732277723@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 af81a62faba6..e7faea3d73d3 100644 --- a/arch/xtensa/platforms/iss/console.c +++ b/arch/xtensa/platforms/iss/console.c @@ -168,9 +168,13 @@ static const struct tty_operations serial_ops = { 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); pr_info("%s %s\n", serial_name, serial_version); @@ -190,8 +194,15 @@ 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