From nobody Sun Dec 14 08:07:02 2025 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8490022C9EC for ; Thu, 16 Jan 2025 18:23:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051786; cv=none; b=MrFdorBIY5SKy0rIeOWagZ7jWvnTZrlpvdvalpZ8s+i9M2n2hL9q5H9oo6WrDCPiB1ZZa0hXBgzdlOY5a8soBxFgwImcGdrpkfXcuvtL0Shs/qxpb9Zea3Bp8dl3bv4+Aqs4+Laa0DdkIHk02hWjrXxI9wOh2HSFdRO+VJCnWcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051786; c=relaxed/simple; bh=uqq3kMHadr9kGhubJ6WWGg0WLHId0kU6QtAtpj50k6Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dzfw9YoD6hJmH/LD2wUgrxn9UUw2AFa8mKz7uVWYaAe9oSUVONks5LbYA6aUae9jkRwPxz+lJftgP9ejmUVyyRnwE/AW0W+VMoFR4O466Ri0tQM2ALIClODwyoVf8QV5uP+4qmH4er7GmSe9AgEBLYCY2zgpfAIjnswZHBQKE2g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=oXQAN/Hi; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="oXQAN/Hi" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3862a921123so939236f8f.3 for ; Thu, 16 Jan 2025 10:23:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1737051783; x=1737656583; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cgs3q9e5gTha9jyWfeK+tF0kxlh9ork4Uz9d4Avy4Eo=; b=oXQAN/HiP3T7T48S7pEaFc6swfLRNJupBmnpvXcEW8e6CGWfOCaIrx7X27oGt3Ji9L rfEHNs2s885ta972h4JR0FYnG5tQ/gtTNhul1WgPXx4xnPz/hWMDXlL3NUAZLVoxOUOb M0OPxz+0L6nALArwvEKeAe7ILRoRzcE1Du6PC4h/BGfmUbFyG4kuIAPCQMg5CEP4oQmi we7I1W35Zt2eP41G+NwHC0tY+yh8fyhyhR+EuPnac11pHsGxq9kaxnQzWMkQ9C8DP/CQ 2T8+oHHVWOcCRZDtJTdQGzu76OIMO/zB/v1QrrNkbsQO2jFi5cdktx9zuABfaYVIH+BS UWHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737051783; x=1737656583; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cgs3q9e5gTha9jyWfeK+tF0kxlh9ork4Uz9d4Avy4Eo=; b=Lwn5TQoprfU6T6nbpyj9oMzAv20bd4BxviK5TcJlIrwgYp7Gzr2/+y27jpFRDQXQFS Z+9Bn8nUdZteoVz/T68wC/3eH1w5veauOC42sluE0Ol7u/ndRAyPPigPoyHANuE474zy cuBcNsxbaUXyaVW9iI6k6aipVSLID7WjGlEfHJ6n+GMTuIF6BA8AGFGojSvSyBboKzFd jmzh2zNqKryNsw5CQryJmGdbMbISDUe7nimXVdaepm8e6oe9tdXubJunJ0Wd2R7Pieg0 xrPESMaRj5mibZU8RI7wjJiXfkAhHjYDEBoZw5xMldaNn8fiLqxFn5l1Yh4hY1A0QiEt wCdw== X-Forwarded-Encrypted: i=1; AJvYcCWrI1/nh16Fw6w8ZwcQHF6W9VRR+r1bE5N7jV0E607uhw8MoBT8S8BtIL3V6TscIUg6eVRFgXFVdf6HiYQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxJxiatvzuzdWpnBoZ77cOkrHohwWrEQURiYA63jD4ah97rbT2S iFmBfeyo/iE81pNINb3XFVTAnKRA0YNorj+5qDSdyn3BnmbXwqlXJxzVif4B9dE= X-Gm-Gg: ASbGncuksXzlhoO+j3V8fLSJ3LkF9kViexlHMSYKOHKAwPTBStxtolpjAmUmG91PNj4 JEgOjeTZ034Jl5Sf9lkdam6+xT3eYZegRznX9h9qc4a0599H2nNwTsO2wzn9B1xpC+7x4/pTari Hi3htfeGlxdPkTpiL6x9wGZT6RMAwSWDXPfxJFiBme/FiGCEw8YmR3gXDKOWVa+ChILdglwDqox D7hUan5gb1djANlcmQODrHj/D72abxOvo6yzs9doq7mIEZo1q53Gk5XXO7S0cmUHf0ffdtnP/kl 8reudS/C8eo= X-Google-Smtp-Source: AGHT+IFCaynXpEJsQvwRloE6R//x5qfnNbfyNt6NHSxk6VGriZcxNiyTgPIAAL7cLGpfePzKNuczyw== X-Received: by 2002:a05:6000:1847:b0:386:3825:2c3b with SMTP id ffacd0b85a97d-38a87304672mr28732966f8f.18.1737051782923; Thu, 16 Jan 2025 10:23:02 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38bf322a838sm495942f8f.48.2025.01.16.10.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 10:23:02 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, geert+renesas@glider.be, wsa+renesas@sang-engineering.com, prabhakar.mahadev-lad.rj@bp.renesas.com, ysato@users.sourceforge.jp, ulrich.hecht+renesas@gmail.com Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH 1/5] serial: sh-sci: Drop __initdata macro for port_cfg Date: Thu, 16 Jan 2025 20:22:45 +0200 Message-ID: <20250116182249.3828577-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250116182249.3828577-1-claudiu.beznea.uj@bp.renesas.com> References: <20250116182249.3828577-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The port_cfg object is used by serial_console_write(), which serves as the write function for the earlycon device. Marking port_cfg as __initdata causes it to be freed after kernel initialization, resulting in earlycon becoming unavailable thereafter. Remove the __initdata macro from port_cfg to resolve this issue. Fixes: 0b0cced19ab1 ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") Cc: stable@vger.kernel.org Reviewed-by: Geert Uytterhoeven Signed-off-by: Claudiu Beznea --- Changes since RFT: - collected tags - used proper fixes commit drivers/tty/serial/sh-sci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index e0c56c328d10..09e69cb7d798 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -3562,7 +3562,7 @@ sh_early_platform_init_buffer("earlyprintk", &sci_dri= ver, early_serial_buf, ARRAY_SIZE(early_serial_buf)); #endif #ifdef CONFIG_SERIAL_SH_SCI_EARLYCON -static struct plat_sci_port port_cfg __initdata; +static struct plat_sci_port port_cfg; =20 static int __init early_console_setup(struct earlycon_device *device, int type) --=20 2.43.0 From nobody Sun Dec 14 08:07:02 2025 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AF1822E409 for ; Thu, 16 Jan 2025 18:23:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051788; cv=none; b=NpgZ2WUreEX8wzWzgNrnomB+gO6BXsIZDmKxMJVKFVnB8SkmIke7VbmlxUWFUvbkQqKvi845qUOVOEPAdM4QGDJP4ypC3BxU9WUp8iXs8WGVz+0lCDnnbge9bfcA7Z67I7pWmSNmavqhG4JGleJC6uea3ePhGLdmXOuUeiFTPl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051788; c=relaxed/simple; bh=DcF7B55zcAap/muhL1RWLS7OTEtRY63GaX/Ehm6o9BM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y/aKZJI1UYs9VeOICd/i8Ovk+cahQngLuzaxNXpthkLLtn0iSCp1PhcHFs2DRCdbdjX2GWxiYRuWvQTnYx4UIHGzpDRGfKPWbUQtLmSsRwPCvz6m+g6pxvroY0qxeSf+lcA3pbNv+w6I0X+PwyyCKcdQXNhtVnc9UwdEBe+dZQM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=exEIgaJ3; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="exEIgaJ3" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-385e27c75f4so1016111f8f.2 for ; Thu, 16 Jan 2025 10:23:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1737051784; x=1737656584; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xt3X3hJfAKuM+3Yz7HnXtTVzceebTppvDtGkvFMMHoM=; b=exEIgaJ38cv8OjUEyp91/WBHYbQID2WnURX1BKvpKTKyUISH+jUqZuhGDGLoOaCi07 FBTrA6myTT69YuMYUDLKdvJkUpPKn8dRQ91VbbFCZoetOIbb2Ll3NWPQTUNIft6zbagN NBnpu2pxQzgb1SQfzZQDKSIa8oCIczZF+ICS84C1/7gB+izOit2tAYiBolcGdVVLcPHr UewVldw3W1eAyUDUAgV2x1to2CMqkSecin/mqOJNJu8ROQQwKOqFBnb4N7jf33Ueio+j thT5cOXhvayJMle6DJ4p9kH1wMTeIethJa3QWnj4ZN0LNuJg7SlH3tuRzGuw6xFV8yYg vZaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737051784; x=1737656584; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xt3X3hJfAKuM+3Yz7HnXtTVzceebTppvDtGkvFMMHoM=; b=QavunJL0DrxiCbi6+iN2n1o0nsA8yQYBAQO+oFfiVz5fgpiv6xM6KgX79Bnhl1Y2wd nnRKsCdwuiKmt54B1gxxGTfHPWHXNO4qZMD+5BKnyWv4G2UdeelTIxq6IXO8gbpr/u88 Ar2txlJNz/bN83+iTnHNOVb2G0vhf5zZJ9WXyZvIvm8Q5/5qHUpNhtC8Qt98wDR6DslV tqq8WH62z0lhg8semSjyKiZv/L5RqPc1d1PBMHzFiSs6/NPZUcu6blLDTBrTsxfBLL7g Ow/x8gBhUPXm0l29jEGUIkNG/9dF4tvNS+cT58EL8bzh9c3tWbuiD+gcjo/3HMNvcQNq zBhg== X-Forwarded-Encrypted: i=1; AJvYcCWnqeYITUEsyaliRR5wKKLCPTXr0pG6iTVPy/HSJ2kYxgNqhyufFlpwQS2GcEFM/zw87rwul8B+XnsJO0Y=@vger.kernel.org X-Gm-Message-State: AOJu0YxOn6bxyCJkY6zZTXyLcH6ONTGnkdhHpl3rurHM1XlObcCE4Xvu /p51Foxh7DksllLg6tE4CmCHwt7giD+spCDOoU46w9qDYYmUIWjjclsOGMFtfK4= X-Gm-Gg: ASbGncsk5ornBM0BYSOBvBn4AvTntIpuFMOWA13bSUYXWuAoaGl4Pk8I5VkqYGFd5jb tgMLdDI8dL6OGcxd5Sma9PDyVMPPQ1ZryfMKeKF2bJHtVZ1DDoYGD2to3UlFBlt1CcucfnwEaRY dzxDqL/KVn6duWqJa04+Nop3iTXkn8ODX1J+ZKb5baOWLCwCL0tqdvZAi611H40JyZCLQqunMmZ 4nwtj8rvuO5exeGMRSmx41Ku/jFirnDQvzMy+6DD+tS+ANT4AzrWhc4oxl+ugG8xCB0KbAuIx9Z HkqrLzKGhEc= X-Google-Smtp-Source: AGHT+IELCx1Crvm+gMJWnRj/5W/vXDbON9DFubikSRu/WF4Y4wWdLHxE8IaPDSh+SujAoNScHaHbSw== X-Received: by 2002:a5d:6485:0:b0:38b:eb7b:316 with SMTP id ffacd0b85a97d-38beb7b043fmr4040641f8f.47.1737051784352; Thu, 16 Jan 2025 10:23:04 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38bf322a838sm495942f8f.48.2025.01.16.10.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 10:23:03 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, geert+renesas@glider.be, wsa+renesas@sang-engineering.com, prabhakar.mahadev-lad.rj@bp.renesas.com, ysato@users.sourceforge.jp, ulrich.hecht+renesas@gmail.com Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH 2/5] serial: sh-sci: Move runtime PM enable to sci_probe_single() Date: Thu, 16 Jan 2025 20:22:46 +0200 Message-ID: <20250116182249.3828577-3-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250116182249.3828577-1-claudiu.beznea.uj@bp.renesas.com> References: <20250116182249.3828577-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Relocate the runtime PM enable operation to sci_probe_single(). This change prepares the codebase for upcoming fixes. While at it, replace the existing logic with a direct call to devm_pm_runtime_enable() and remove sci_cleanup_single(). The devm_pm_runtime_enable() function automatically handles disabling runtime PM during driver removal. Reviewed-by: Geert Uytterhoeven Signed-off-by: Claudiu Beznea --- Changes since RFT: - collected tags - in sci_probe_single() return directly the ret code of uart_add_one_port() drivers/tty/serial/sh-sci.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 09e69cb7d798..51382e354a2d 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -3056,10 +3056,6 @@ static int sci_init_single(struct platform_device *d= ev, ret =3D sci_init_clocks(sci_port, &dev->dev); if (ret < 0) return ret; - - port->dev =3D &dev->dev; - - pm_runtime_enable(&dev->dev); } =20 port->type =3D p->type; @@ -3086,11 +3082,6 @@ static int sci_init_single(struct platform_device *d= ev, return 0; } =20 -static void sci_cleanup_single(struct sci_port *port) -{ - pm_runtime_disable(port->port.dev); -} - #if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) || \ defined(CONFIG_SERIAL_SH_SCI_EARLYCON) static void serial_console_putchar(struct uart_port *port, unsigned char c= h) @@ -3260,8 +3251,6 @@ static void sci_remove(struct platform_device *dev) sci_ports_in_use &=3D ~BIT(port->port.line); uart_remove_one_port(&sci_uart_driver, &port->port); =20 - sci_cleanup_single(port); - if (port->port.fifosize > 1) device_remove_file(&dev->dev, &dev_attr_rx_fifo_trigger); if (type =3D=3D PORT_SCIFA || type =3D=3D PORT_SCIFB || type =3D=3D PORT_= HSCIF) @@ -3425,6 +3414,11 @@ static int sci_probe_single(struct platform_device *= dev, if (ret) return ret; =20 + sciport->port.dev =3D &dev->dev; + ret =3D devm_pm_runtime_enable(&dev->dev); + if (ret) + return ret; + sciport->gpios =3D mctrl_gpio_init(&sciport->port, 0); if (IS_ERR(sciport->gpios)) return PTR_ERR(sciport->gpios); @@ -3438,13 +3432,7 @@ static int sci_probe_single(struct platform_device *= dev, sciport->port.flags |=3D UPF_HARD_FLOW; } =20 - ret =3D uart_add_one_port(&sci_uart_driver, &sciport->port); - if (ret) { - sci_cleanup_single(sciport); - return ret; - } - - return 0; + return uart_add_one_port(&sci_uart_driver, &sciport->port); } =20 static int sci_probe(struct platform_device *dev) --=20 2.43.0 From nobody Sun Dec 14 08:07:02 2025 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7181622F3A8 for ; Thu, 16 Jan 2025 18:23:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051789; cv=none; b=lJKLDp9kuBSfAE0hap//4DsEAPH4ZC/A4cE5/jBNpjm2G+/gvtScnxmiY2BiSOAX7d3RHn3U7acfS4STbGWAPut3jKO13z5Jpcbg7ShVGDn4hVN23QVyg/TsHhdZJKsx5382JU5BSdJBpN3RuSalGzK0bMvaULAJaSqpR8+CBRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051789; c=relaxed/simple; bh=HlBz3gfd8OIUkMQUN/g2FCl5sNFUwPtUBGa8hY7PvGo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dCAPKZL1qTiRJ+Tw458WVz7m3X5bFWpPAFuP/Luqh0WrhH6OOYsOFlSUzqPX6t00LMGKu+rUgoUNq8ySuD+gz/XK2fS//CCtycXR9uIYkeHwGkTQ1tJHUuNuS8E5kK191E5roxCR7YC70GO4DHETjbJQ0z5JpyZKu0az4BYnn6I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=AwsU5Vk6; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="AwsU5Vk6" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-436326dcb1cso8277645e9.0 for ; Thu, 16 Jan 2025 10:23:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1737051786; x=1737656586; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/F2SV8L8hT5i2mZ7qR6sl3DjzHF148Q2UE5FnnQt0fU=; b=AwsU5Vk6ZcMYDRyx0o3j13MdtxG8nzDn3SRMAYezKgNB8Ndmf+YWlJb3MNW3Ws0edb FZTPW9rXXTGZCylDWiNOOHW0daxLTHjSWlDcOJDWHXLpyFrVoSVcwgTgjV708+SrIBKh JB3DxTDukhdI5tgLrEXwV3JXdNas7+xOyuce3IInAxyTrX2KLexxH03f6NA8s+oNY/V7 1EY5ym4Yy5BLlI9YobLmfXOK8P3RYTrpK9KNoF8loKETUj+m1KRjGqYjNVc2MVRvWbFv QlPEAVY4LEiSXee/ch6si62+MomUKdRajAWSDzdt+ne0qFAxpZFZfc0xmpvaS1t1h0At wfAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737051786; x=1737656586; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/F2SV8L8hT5i2mZ7qR6sl3DjzHF148Q2UE5FnnQt0fU=; b=PrNzJHEAsuCgFEJyezTPBGQ/gDoLCrElV0e21Nn5fdlcEOyIfqutfnkxclVoi0YIfS yEfD+YDGpvQTJ5TVRuBpqV3wWv4DetTFKWhPDiWaizc+sMtte5RnaC4ayl4/iBHo8eLC VMXUI5OXBeAFNed8ACU4FxKjvEIGirBlN5QubUseKXkur9LNQ6bdIHfMhe0gfuFlWTPl e/bGtVyeaUJ5Zz6IFIwdhD7RkQr1OlcWYPs/3iqyeSOmPVmSae+fOhDmlgiAX4R+1hcK QBHJMVbbdI+kcGK7AeSKGdGWXGuntnrKSj+WyqSkOfXP/0177Kt6AWIA5tYNIBayS/sh ovyA== X-Forwarded-Encrypted: i=1; AJvYcCUlgJuNsY7nVJ6DPqlyxAHdAAwg1gWP1IuPSd38UE4GBFeHd+/NEoTyZ6J26ZCuxnzb6P2ysMEq+Rf04no=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/c3ciACjDXp5xbsLvb+hmOL7puEsQQBs91sMPKOHo82SLPgUr UorR2OaoKULfgybb/zQWaYLmTBjtNbgUJDPMqolF0cZGYG0jd1Zi12X9+rYIcqw= X-Gm-Gg: ASbGncv9Ek4IM/npSPJKjRHgD/7iBVb3LI8AckHCifzUHbvExWbo0FEHQuSXHgJhEg9 cnr0L5rQXfsjOH49liS82jvYyfBa/Zofqv/Ok5A5UZx674slxEL+xi6BEXyoeFTqV01oC8QSEw6 aptJZ9V10yLHb5Kuuhv2ek0gAXDdhR47E8eWWq6vOc4lLo2LcSJqeEnJni7VJMCRimGosRgeckq h9OP+N8eYOWS0C9v1+t1LEMRCideg+jgTqnGlliFSnY27ptvzgOW8b5D9iutQXKwbcOYdj6oNKz XjnAvVrH9DY= X-Google-Smtp-Source: AGHT+IF1lBnApPaY87jL/VxiBnx84a/2Bv8/0Zi1V9RrOKuTmAxotcGlNP4QNTccsMRyPKvgBF/Ftw== X-Received: by 2002:a05:600c:4586:b0:431:44fe:fd9f with SMTP id 5b1f17b1804b1-436e26f041bmr286561865e9.23.1737051785759; Thu, 16 Jan 2025 10:23:05 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38bf322a838sm495942f8f.48.2025.01.16.10.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 10:23:05 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, geert+renesas@glider.be, wsa+renesas@sang-engineering.com, prabhakar.mahadev-lad.rj@bp.renesas.com, ysato@users.sourceforge.jp, ulrich.hecht+renesas@gmail.com Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH 3/5] serial: sh-sci: Do not probe the serial port if its slot in sci_ports[] is in use Date: Thu, 16 Jan 2025 20:22:47 +0200 Message-ID: <20250116182249.3828577-4-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250116182249.3828577-1-claudiu.beznea.uj@bp.renesas.com> References: <20250116182249.3828577-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea In the sh-sci driver, sci_ports[0] is used by earlycon. If the earlycon is still active when sci_probe() is called and the new serial port is supposed to map to sci_ports[0], return -EBUSY to prevent breaking the earlycon. This situation should occurs in debug scenarios, and users should be aware of the potential conflict. Fixes: 0b0cced19ab1 ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea --- Chances since RFT: - converted the earlycon member of struct sci_port to a local variable - added sp =3D=3D &sci_ports[0] check in sci_probe() to be sure the code is checking against the sci_port used as earlycon - changed res->start !=3D sp->port.mapbase condition to sp->port.mapbase !=3D res->start to use the same pattern as used in patch 4/5 drivers/tty/serial/sh-sci.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 51382e354a2d..b85a9d425f7e 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -165,6 +165,7 @@ struct sci_port { static struct sci_port sci_ports[SCI_NPORTS]; static unsigned long sci_ports_in_use; static struct uart_driver sci_uart_driver; +static bool sci_uart_earlycon; =20 static inline struct sci_port * to_sci_port(struct uart_port *uart) @@ -3438,6 +3439,7 @@ static int sci_probe_single(struct platform_device *d= ev, static int sci_probe(struct platform_device *dev) { struct plat_sci_port *p; + struct resource *res; struct sci_port *sp; unsigned int dev_id; int ret; @@ -3467,6 +3469,26 @@ static int sci_probe(struct platform_device *dev) } =20 sp =3D &sci_ports[dev_id]; + + /* + * In case: + * - the probed port alias is zero (as the one used by earlycon), and + * - the earlycon is still active (e.g., "earlycon keep_bootcon" in + * bootargs) + * + * defer the probe of this serial. This is a debug scenario and the user + * must be aware of it. + * + * Except when the probed port is the same as the earlycon port. + */ + + res =3D platform_get_resource(dev, IORESOURCE_MEM, 0); + if (!res) + return -ENODEV; + + if (sci_uart_earlycon && sp =3D=3D &sci_ports[0] && sp->port.mapbase !=3D= res->start) + return dev_err_probe(&dev->dev, -EBUSY, "sci_port[0] is used by earlycon= !\n"); + platform_set_drvdata(dev, sp); =20 ret =3D sci_probe_single(dev, dev_id, p, sp); @@ -3563,6 +3585,7 @@ static int __init early_console_setup(struct earlycon= _device *device, port_cfg.type =3D type; sci_ports[0].cfg =3D &port_cfg; sci_ports[0].params =3D sci_probe_regmap(&port_cfg); + sci_uart_earlycon =3D true; port_cfg.scscr =3D sci_serial_in(&sci_ports[0].port, SCSCR); sci_serial_out(&sci_ports[0].port, SCSCR, SCSCR_RE | SCSCR_TE | port_cfg.scscr); --=20 2.43.0 From nobody Sun Dec 14 08:07:02 2025 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4718232438 for ; Thu, 16 Jan 2025 18:23:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051791; cv=none; b=aBqjztLKJHfUpNr6kPOEsUge5mUAzmu4gLa3yn23r6CspNb474dDkJmhuzKDHNZGBuinMgEiDD6tvvfvqi2ROMSrp+OlVDowkmi/+gwRgc0mTgVnGXdw9jnVmumdVtDcAHJ+pOHd4JS9X61jPmPwPtYheObl1VIuFxnjkDuYO3g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051791; c=relaxed/simple; bh=4o76eL3JN8Rw/PF8oYl6df0FpGa0o1Kgqe00X1TGqRA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AMcqrhCxx/N3qhedlhA3ocRNj3lbhjVcrp/7PNu8/Jj5URrM8TM91fcmItbx/oIVxV5fWVsN77EFcNcFuDK4SIDGz/XB7jq1LJOYYPcP3ojwNSEVT1qJwwzGW5fZUrNzJa1qWkjBma6z8eqPO5rlzPN4k2TypwlTmJYz/oTOqbc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=nyG6k9WB; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="nyG6k9WB" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-386329da1d9so706716f8f.1 for ; Thu, 16 Jan 2025 10:23:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1737051788; x=1737656588; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BSWSInwqzRrvj358vgmNewsmiwlVd1V3Egd84Fq6+DE=; b=nyG6k9WBZn694dEj5tKi8s8XArmuRWF0gC7KukTluh7UDc/Adiys65eMkrsy4VLxca dmW1ly2CWI48rhsrVR8ksVwRacjGNF2rL8OdFudqdF8XJLHg2Kw+bEYbDjmBaBm1c+bR YW/JqKV2d8wvAB2rXKqyt9PS6jCUFloBjIrenFXE5Nfrpyp2dsL4dhCqvT6MEmTpOKR7 UoFtdM8B1z+BC5kBiFgaSYMGD/bURp0qPUf549H1qU0Rykr+9xJAPcfr7QH80dPCg0nj E7ApXfLiynbLvzohQHKwOJcBrSMTPn/P1Ax7R+UtuZn46XhY86I1IZ3ktBsirv8zRBn3 uLGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737051788; x=1737656588; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BSWSInwqzRrvj358vgmNewsmiwlVd1V3Egd84Fq6+DE=; b=jnDd+nPjUKvukqYTjgo8Oz2MHl9mGQ+mXonLmauaWUkroDiBtD/6/zleeD03gosg9v XcZvLM7isk5JZXQVKVqztaPBAhlmbTexPNduqD6wEm8Dtu10l8dX79wS02PD/JWfQ0mz 3Ja13gfO3+n0O2qKk8AtQ8YVJHdJTCM7WqPSsvZykDn44vFGduPmTMbLABxWjM1boOKH dBZe1Nzw+pHrNVImKh+W6cVgrvikTiFIwp7Drlr2dpju2NoPouN1kBNCQH+y9Q/0WnMT 3AL10suMoWXmwg96FQmt7BgZYaggW5F+ZKsZPt1B1fGnyVR//AP7yoNTSizoQb7VaXZd 7j+Q== X-Forwarded-Encrypted: i=1; AJvYcCWZz1MqMowx6qaWlt2ACS+h3KVxOIYiCL/O3Vzt/qWoCwB3bFsNqjkQJxBEtEwxtHqHQhcdXuGGcAduPNg=@vger.kernel.org X-Gm-Message-State: AOJu0YzOlMuID2eZVoU9fsk89cdBUiUwIvqPaad9F1rryjm9ibPy8Kn5 AfGSMeZjrfL58mXO3MBlGrjPvz/MegpLpomzaeLyv97erOely4sKrInZ42PIqAs= X-Gm-Gg: ASbGnct/Z1+9KZRMGAMDlL6Hh+Y9xdIRVkJve855pqHzb+DwO6tZhAl8TfpLQV5qhoq aKC/9kUiJdDGAt0DHUhH3hDrHjn/BYmFNh6V2P6YhlEWZTeG/YATSQo906xI+fuilN9zogL8X+b 5MlvZYsWrMGxkFOtk7pjJZDq/XcH3m8y7BLIw8RciQsiqHPPfJf7thiz+QAlkWZw9JgDZs0O1JQ w2DYY59p1g2l/F6ZxzitsxQXIy761lfFjP+zJouGRdKquZU5OeFZKI02euHOJuukyiNF6IztJ8P hRc777FPqWo= X-Google-Smtp-Source: AGHT+IGUweqinG8rg/Sf2hD0L9NG7qTG0owwOTsCQGrrCdsjg/K0rXhjdPlmSjQhzJYk3zjmQ5mU2A== X-Received: by 2002:a5d:64af:0:b0:38a:8e2e:9fcc with SMTP id ffacd0b85a97d-38a8e2ea11cmr28412330f8f.45.1737051787816; Thu, 16 Jan 2025 10:23:07 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38bf322a838sm495942f8f.48.2025.01.16.10.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 10:23:06 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, geert+renesas@glider.be, wsa+renesas@sang-engineering.com, prabhakar.mahadev-lad.rj@bp.renesas.com, ysato@users.sourceforge.jp, ulrich.hecht+renesas@gmail.com Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH 4/5] serial: sh-sci: Clean sci_ports[0] after at earlycon exit Date: Thu, 16 Jan 2025 20:22:48 +0200 Message-ID: <20250116182249.3828577-5-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250116182249.3828577-1-claudiu.beznea.uj@bp.renesas.com> References: <20250116182249.3828577-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The early_console_setup() function initializes sci_ports[0].port with an object of type struct uart_port obtained from the struct earlycon_device passed as an argument to early_console_setup(). Later, during serial port probing, the serial port used as earlycon (e.g., port A) might be remapped to a different position in the sci_ports[] array, and a different serial port (e.g., port B) might be assigned to slot 0. For example: sci_ports[0] =3D port B sci_ports[X] =3D port A In this scenario, the new port mapped at index zero (port B) retains the data associated with the earlycon configuration. Consequently, after the Linux boot process, any access to the serial port now mapped to sci_ports[0] (port B) will block the original earlycon port (port A). To address this, introduce an early_console_exit() function to clean up sci_ports[0] when earlycon is exited. To prevent the cleanup of sci_ports[0] while the serial device is still being used by earlycon, introduce the struct sci_port::probing flag and account for it in early_console_exit(). Fixes: 0b0cced19ab1 ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea --- Changes since RFT: - converted "probing" member of struct sci_port to a local variable (named sci_uart_earlycon_dev_probing - used sci_uart_earlycon instead of sci_port::earlycon from RFT version - dropped the double "up" in the added comment - changed the cleanup condition in early_console_exit() to if (!sci_uart_earlycon_dev_probing) - set sci_uart_earlycon =3D false in early_console_exit() drivers/tty/serial/sh-sci.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index b85a9d425f7e..e64d59888ecd 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -166,6 +166,7 @@ static struct sci_port sci_ports[SCI_NPORTS]; static unsigned long sci_ports_in_use; static struct uart_driver sci_uart_driver; static bool sci_uart_earlycon; +static bool sci_uart_earlycon_dev_probing; =20 static inline struct sci_port * to_sci_port(struct uart_port *uart) @@ -3386,7 +3387,8 @@ static struct plat_sci_port *sci_parse_dt(struct plat= form_device *pdev, static int sci_probe_single(struct platform_device *dev, unsigned int index, struct plat_sci_port *p, - struct sci_port *sciport) + struct sci_port *sciport, + struct resource *sci_res) { int ret; =20 @@ -3433,6 +3435,14 @@ static int sci_probe_single(struct platform_device *= dev, sciport->port.flags |=3D UPF_HARD_FLOW; } =20 + if (sci_uart_earlycon && sci_ports[0].port.mapbase =3D=3D sci_res->start)= { + /* + * Skip cleanup the sci_port[0] in early_console_exit(), this + * port is the same as the earlycon one. + */ + sci_uart_earlycon_dev_probing =3D true; + } + return uart_add_one_port(&sci_uart_driver, &sciport->port); } =20 @@ -3491,7 +3501,7 @@ static int sci_probe(struct platform_device *dev) =20 platform_set_drvdata(dev, sp); =20 - ret =3D sci_probe_single(dev, dev_id, p, sp); + ret =3D sci_probe_single(dev, dev_id, p, sp, res); if (ret) return ret; =20 @@ -3574,6 +3584,22 @@ sh_early_platform_init_buffer("earlyprintk", &sci_dr= iver, #ifdef CONFIG_SERIAL_SH_SCI_EARLYCON static struct plat_sci_port port_cfg; =20 +static int early_console_exit(struct console *co) +{ + struct sci_port *sci_port =3D &sci_ports[0]; + + /* + * Clean the slot used by earlycon. A new SCI device might + * map to this slot. + */ + if (!sci_uart_earlycon_dev_probing) { + memset(sci_port, 0, sizeof(*sci_port)); + sci_uart_earlycon =3D false; + } + + return 0; +} + static int __init early_console_setup(struct earlycon_device *device, int type) { @@ -3591,6 +3617,8 @@ static int __init early_console_setup(struct earlycon= _device *device, SCSCR_RE | SCSCR_TE | port_cfg.scscr); =20 device->con->write =3D serial_console_write; + device->con->exit =3D early_console_exit; + return 0; } static int __init sci_early_console_setup(struct earlycon_device *device, --=20 2.43.0 From nobody Sun Dec 14 08:07:02 2025 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 813572361DB for ; Thu, 16 Jan 2025 18:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051793; cv=none; b=FmhG6jqiaDC5fkp/Jcqwt1T/OezcPtQtKFSngm78h+za+uKBEM2vphuvUw0BnlzyOXvWaBhclN4k0wYLeXYjeVVAw4I0cGK7GmWms1//i22hmluo5I5OVad8sm2R655+TyX7MmHa1v9b8bQG28E/dA/bZJOwg/o3rBr+y5ie7JI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051793; c=relaxed/simple; bh=+JZn/ww1FY/kTAFer89gJaTpDgTvbKcrRyepTGJVP18=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Eu2pqKBvWnKcFzceqKhyUez4jIzxyLz4r0FZOp4QWtd6o46qsn44LCwsSxqXSJmrVt/lXe9AN9VTkmdHbzabJ4hECgeDj5uhpGWYurkyi4noXSgmq5TRlq28QdJN0JI3czMCJXC1s5ymdHz62rnnStJN43bevdY7hw8kTbIurbk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=YeUU7cNt; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="YeUU7cNt" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-385e1fcb0e1so685981f8f.2 for ; Thu, 16 Jan 2025 10:23:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1737051790; x=1737656590; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jmtKKaWRtLl2vifGgcWTXPqXE2lcLz7qOiG2GbtoKk4=; b=YeUU7cNtxyYGjobOoDN8dw1YAkZTfwMsyPu+JSlpT4eS5qcxDlxUymNWWDfZNwD+7U CmZR2k0Y6pColT9i8J5vUsNobVwqxCzUgd+8aARt6VeH6R7tPNfiHvX2Lr/vnxV6lVPk +nPrWIWQJApJqPMsLtymLbeTFbIjjfp6jllbGHshBwEK56cRVOyxtmHMZBty4ZgFWVK6 XNhdWJgem5+EC4EbeFgx0Vos6SLMpBf0xcMMy2tsFatfb/5BKxyg0isCBbYSM3TzVglB f3kSNGav4gDWgEdBmBim4CtPvAzWLeGq/CvxdW7+MGOqGb6hY1AfqwIJ5UeqIwgeF3AQ yg9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737051790; x=1737656590; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jmtKKaWRtLl2vifGgcWTXPqXE2lcLz7qOiG2GbtoKk4=; b=VMtEpXQF+uRxRs+B8bbg60tFeKl1umXqxCIK6F5LMTHdiPFngJNQDMe2BdyfqvqVDO JyXM05bbKEF2uBlpRUigkxXAhWD6eNn65dZAkdrGVOoLnwCsagNLzr+54SiuMPWM4/yH hHnUZMQpm2JGd5PgumNraotsvhivxKw3UEO3F7SgESzgwqYbEdjexBqH1HSXmoxjV1Tw 3RLx4l7c8eIKyATetV2hDDK6xRU9vbcgeSHdcdpudHbTUFS/rYGvKtNPOr5ZOA4eVbFP lLagMc3dQ82nv7jYhytsb54hcwDukl6nuy7Ta9QiZeJmJgWUVsR7qW2wLmpbCBqnJvol csFg== X-Forwarded-Encrypted: i=1; AJvYcCW/PK1bkCKPqdCHo70mM7ZjXca9QIjp+5Wh7/w5qiTC9qbe1SdL3xYEOuRRyqnSu0drDGBA0izTsyPTEEI=@vger.kernel.org X-Gm-Message-State: AOJu0YydE+WY6pbZ9JQeiR++FXzs6wOoSDR8Pnji4AwPByRX2XY1VVYI C4ygh8CW9D5xxmEVGbkG5SL62Jueu1IyT28D49rvut21fNPJEoqZiAAxjeOns+U= X-Gm-Gg: ASbGnctoCCkDPinrOUqShzITwrsAfKORUGmJtmxjqhAuGaP4IPZtI+qgcOYOQ3vYg1J 4VOVsuQQAvubyWWPuIoNEdbJrbcd718kQETGjbX20G9V501kWXXPJ7kCT1B0W3fOEREJ/qmKjAz fiDELHfGtTjr4L6JNNJoBCFqaPd0LfUMIzo+lLtoIHlliOQM3ISUBGF0hm7GAl7338AiSvMeWeA r3Fg8oQFeek4U8pQaROCDq2P8RvMz0xHMZJtjBb31MOkECvT0Ve2WSdqwq1VhD4KcQyLj1Pnoxr dSrxtMxjFVw= X-Google-Smtp-Source: AGHT+IHTCLzWRVHhlR7lW8GYQyylUAfvSBIe2YvKqor2RF/6OYe8hunZYeSsvJPm4KC/0CLZzX9ROQ== X-Received: by 2002:a05:6000:184d:b0:38b:ef22:d8ba with SMTP id ffacd0b85a97d-38bef22da4emr3656439f8f.44.1737051789820; Thu, 16 Jan 2025 10:23:09 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38bf322a838sm495942f8f.48.2025.01.16.10.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 10:23:08 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, geert+renesas@glider.be, wsa+renesas@sang-engineering.com, prabhakar.mahadev-lad.rj@bp.renesas.com, ysato@users.sourceforge.jp, ulrich.hecht+renesas@gmail.com Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH 5/5] serial: sh-sci: Increment the runtime usage counter for the earlycon device Date: Thu, 16 Jan 2025 20:22:49 +0200 Message-ID: <20250116182249.3828577-6-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250116182249.3828577-1-claudiu.beznea.uj@bp.renesas.com> References: <20250116182249.3828577-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea In the sh-sci driver, serial ports are mapped to the sci_ports[] array, with earlycon mapped at index zero. The uart_add_one_port() function eventually calls __device_attach(), which, in turn, calls pm_request_idle(). The identified code path is as follows: uart_add_one_port() -> serial_ctrl_register_port() -> serial_core_register_port() -> serial_core_port_device_add() -> serial_base_port_add() -> device_add() -> bus_probe_device() -> device_initial_probe() -> __device_attach() -> // ... if (dev->p->dead) { // ... } else if (dev->driver) { // ... } else { // ... pm_request_idle(dev); // ... } The earlycon device clocks are enabled by the bootloader. However, the pm_request_idle() call in __device_attach() disables the SCI port clocks while earlycon is still active. The earlycon write function, serial_console_write(), calls sci_poll_put_char() via serial_console_putchar(). If the SCI port clocks are disabled, writing to earlycon may sometimes cause the SR.TDFE bit to remain unset indefinitely, causing the while loop in sci_poll_put_char() to never exit. On single-core SoCs, this can result in the system being blocked during boot when this issue occurs. To resolve this, increment the runtime PM usage counter for the earlycon SCI device before registering the UART port. Fixes: 0b0cced19ab1 ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea --- Changes since RFT: - used spaced instead of tabs in the call trace from patch description - moved the comment in the code block started by if (sci_uart_earlycon && sci_ports[0].port.mapbase =3D=3D sci_res->start) - still kept the sci_ports[0].port.mapbase =3D=3D sci_res->start check as I haven't manage to find a better way drivers/tty/serial/sh-sci.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index e64d59888ecd..b1ea48f38248 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -3436,6 +3436,22 @@ static int sci_probe_single(struct platform_device *= dev, } =20 if (sci_uart_earlycon && sci_ports[0].port.mapbase =3D=3D sci_res->start)= { + /* + * In case: + * - this is the earlycon port (mapped on index 0 in sci_ports[]) and + * - it now maps to an alias other than zero and + * - the earlycon is still alive (e.g., "earlycon keep_bootcon" is + * available in bootargs) + * + * we need to avoid disabling clocks and PM domains through the runtime + * PM APIs called in __device_attach(). For this, increment the runtime + * PM reference counter (the clocks and PM domains were already enabled + * by the bootloader). Otherwise the earlycon may access the HW when it + * has no clocks enabled leading to failures (infinite loop in + * sci_poll_put_char()). + */ + pm_runtime_get_noresume(&dev->dev); + /* * Skip cleanup the sci_port[0] in early_console_exit(), this * port is the same as the earlycon one. --=20 2.43.0