From patchwork Thu Jan 16 18:22:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu X-Patchwork-Id: 13942128 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 8FAFC22CBED for ; Thu, 16 Jan 2025 18:23:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051786; cv=none; b=DSuuwlwRvrU2/EprYAZweAKGP/s6w3fg0erYBuBXqwoo0ZipIWzrdz/viXsS+hHK2AU3xYhh03ulYObGshSKwtJkly5/TrLG35ZzqEhNEmWHPGlBazv7bP33BDy2BjfFsIjZ5xHb23lT7EsLc3AEYp9h/An9Oo5+nN3VWxQTuAE= 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.43 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-f43.google.com with SMTP id ffacd0b85a97d-385f07cd1a4so1032042f8f.1 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=VCkPQEn5llUy6DbpZJmXX3IUERdASCKHtIb66bIdlNdmYd4KbOZiu3WY1TV8EQNCbB NYZ8ELCB5sGYjtS9c382ypQNCflzyN5nCQMPqUQdkIbXZQObA+sD2Tt4HA4NwlWXxEpQ dNci/pbw7bVZWldFvRqHDMIGpD7dxP9C71UcxXhaVKQFkBBYPR8P877R9zHJBW+T2OWg 86NL0SuRyNJpzIta8nAcFkjrh10X/mWFgwIZXNkn2gUCbbU6cZw8qQSzVERyYKItBtAb OjvdOLA34Q6ktuPEi7yf52lbOKYwjsePVHaKcD78EVmoGYMHSLkce54JBFOtiJb2EKEd mHqw== X-Forwarded-Encrypted: i=1; AJvYcCUK+VjAjNhjVYM8R9iXtrsOLMTlNEiZ5CDU55usLkRu1YULM73bp+5kNvwxSfqiUk/ZpBdsoWpQkhgi5SJX8CjeOQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yzf/oU9j56LcoCagIFvx24lMmMGjXG+oYwDrLBRpUpAZqT7kWMq y0aZ2YaTDDe/mEvku5rFreWv+iaAOyEP3/CsXws2YHQnvVBM1J6iRpBL6iML+s++wRBy5WotAwR m X-Gm-Gg: ASbGncuz18iK6cgdVE9ZCo19CP96X0XATnGWoLKr4E1UtZRqHpnGBp8hdYZwCUBwail sQD7i0HARnjlB+9XJnsM7Qpifau3saDlC5xPPzqe81sTGjPwfyCfOSN47SoniWkrdrg5s6KQCNa dEcnbp6wcxw0nTV8ixoE4apIG0gg5k6QxZczZEVdrvHxicvDq9wnCF3a8b4ShzdyfgtB7asjqMk d6IqEe3P6Fk8dmVjcMhkkwUVQJW9/vUWJpddNJqS/G8bbJiOmDKr1LlrwdSO2Fvgnvh5rT/GOeR IDvLjK821e4= 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-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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_driver, 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; static int __init early_console_setup(struct earlycon_device *device, int type) From patchwork Thu Jan 16 18:22:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu X-Patchwork-Id: 13942129 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 478EA22E40F for ; Thu, 16 Jan 2025 18:23:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051788; cv=none; b=a2lwBQnFk3j6sOrape/vxqgl6CLoKPHYmv+eAfh/eNv6c9WzXW6Ls30z8/ILzueTWbYDyDJaaKmcP9DHnq2AOW7IWMvI+/dqGb6h2BLMTvfJWmoLF58PbbhxdYrTPEQRIh5XZ/n/ZakIbGjYbLiYmajGfKVN4+QnKdkcK4FWVRY= 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.42 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-f42.google.com with SMTP id ffacd0b85a97d-38632b8ae71so998356f8f.0 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=OAWA1SYxESdESaaBxlgR9fHj/cdcV+cPG3v/KVLI11ypjHqaC1XkGsGP2r0QpnDx2x QE3aZ1O1CBVu4mD370ih1j4JwrrfQp0QlTR6J/IxKop121g0cDt/eVhdOsLsojiv8NTY LZMz0hbEMq/2Ppg/Sbhb6LfGo/fP3tSyqgv08du0PvAC0tMBMttc37IlhpwLPi+FEmt0 HbvDj3C1VFBOJO0sy7v4V9RC+O+PbSt3qCIePpoCbN7qTrDubAGtmQIyz9A3iHMh4Yn0 jsGMMU9PmETKDrLqwYFSMdPFb/VXOgL6h83lTEVFQcuiHxM/hjVEW3FK2QHG4N9PmU7T YVRQ== X-Forwarded-Encrypted: i=1; AJvYcCXcGOZl+sXWY7mTyOcveCWm40YoNEIggue3lq/tN5VfMzL7wzijQI0qVofBcLY8TFEjLVk0+MVNqc/ETCd4b4wnKA==@vger.kernel.org X-Gm-Message-State: AOJu0YyAw34UcQc2cFQsV35TXNJuNXujKp3icFEjWbfHRGwxU0GYmFWa 8YhxJdPmYI1u2oY8vlKE7tWr+BHngWgN7yWOm3xDBsPjPS/Mxzji3rkoyJcNDdY= X-Gm-Gg: ASbGnct+3iD8eM9T8HBTRG7uurqJ/uBUvydszCy1HtMz2JzbE4gHmWNzbnbeZGgcfc+ Bp2eEey33ETcs5w+wq121d7l9H8G0IKkCN/yvsNKr7Dt3ESiMUIZdx31o3JZm4ForCQFEHyCab8 ADJq/gGQo4ki2J9M5s1fuC4rBbB7xaGo3iSSEDQ74iCwc+H2iF0NXuGgXsVrgZvctnBW577hiKB 8TRzYeD3QHfVpHhStLHSwLxnzQJkPQTTUxyhEor+yMFNdR3T9VBtWjtXKB16OGsKwLBIwjjqEcu vXeSeumCbwI= 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-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 *dev, ret = sci_init_clocks(sci_port, &dev->dev); if (ret < 0) return ret; - - port->dev = &dev->dev; - - pm_runtime_enable(&dev->dev); } port->type = p->type; @@ -3086,11 +3082,6 @@ static int sci_init_single(struct platform_device *dev, return 0; } -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 ch) @@ -3260,8 +3251,6 @@ static void sci_remove(struct platform_device *dev) sci_ports_in_use &= ~BIT(port->port.line); uart_remove_one_port(&sci_uart_driver, &port->port); - sci_cleanup_single(port); - if (port->port.fifosize > 1) device_remove_file(&dev->dev, &dev_attr_rx_fifo_trigger); if (type == PORT_SCIFA || type == PORT_SCIFB || type == PORT_HSCIF) @@ -3425,6 +3414,11 @@ static int sci_probe_single(struct platform_device *dev, if (ret) return ret; + sciport->port.dev = &dev->dev; + ret = devm_pm_runtime_enable(&dev->dev); + if (ret) + return ret; + sciport->gpios = 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 |= UPF_HARD_FLOW; } - ret = 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); } static int sci_probe(struct platform_device *dev) From patchwork Thu Jan 16 18:22:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu X-Patchwork-Id: 13942130 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 69EC322F39F for ; Thu, 16 Jan 2025 18:23:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051789; cv=none; b=JvJNDOiLKEzS4H2ie4wcuHHqsb13mmA/5urPEob5wwKZsSxSw56vNWHYAwWRJZ7JEEDyPF/nox3d734w6bIiUaZ+xOsVPQERi949k9MAzz/fy5sz3TZPEPcwe31z4/TNiZ5c0OjvKXfH/v1unxPO3EYW8fHHTGEscZ3NcA+pdwY= 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.42 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-f42.google.com with SMTP id 5b1f17b1804b1-436a03197b2so8148215e9.2 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=rN2toNfWjjEB1t3Rh/ASLkEXZNCJOM3Djeoxv/j6Kv2a/kPKjbk+QNIwoNrkYc8KDE +AoTIJvtiOaelb/fTg8Z9y/ItEH/s4PMBciP2pGaJlgDmKRVDEdd1BNRGy6L0rtTksBW c1WxYtwoDUmrphGH2LtVI3XyedzXp5ssCpGjHpUtZPXjO/jaTz6rTTDDwgp8vHNM4sz0 0OA4/FURPaUl5sjxo5QeiwjMFh4ysk/s3GbmME/YM7pvrarwybTHuFgxEcbCkkcL1UXI T4Pc9xKsDJKFMXeGoxefu362d/p5mhgutS8ue0ZSBmBpl0uWHGAj78m5G8h6FGWxcPxk t5eQ== X-Forwarded-Encrypted: i=1; AJvYcCW3emm0f0zF8m4ii8v/hoBjmKwPr0YxfirssdSFlEWdFnAcUmdKxqJeIz8r+iJVf3yjB/sqCKYTLFTWtFsLad9BaA==@vger.kernel.org X-Gm-Message-State: AOJu0YzfQOU/2Hjov/vIi645oQ4yOl8341+ztvTcB5kWfjmirszH6Lzf 7il8XSWfNsTfZ6iSWM7Hb8KobMB5o82EzlIATAMQNtQCX9T1QbyWKWLUeXtn2z8= X-Gm-Gg: ASbGncuTkt0v1+Bfta6gA5DRxHow6212eSJh2vIq6vGTB3wtPyVcxfVF+SValmTR9EG oKj4wRf8Jl+9hzYrE+lLQuGgf/qK9m3z/tzHmCDzY21XpLkpK2Rey9+/dOgWVx7sNgyp1qLwKPK I0KsXKaEA9ZTgYpm3+fhDh/Dnbx3o/ZgbZa1yf1i9LRF9K46+8cNlqDboPNYBCPZ404Uz8i3vQ2 Q7lIfqZx7yvYwENXC7GvBpsux5qKKc25C0HCA5Ird/s3EIR2bxfS3wXS6Xy5z0nnEXpX44JAcUM +eD/EqXGKHs= 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-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 == &sci_ports[0] check in sci_probe() to be sure the code is checking against the sci_port used as earlycon - changed res->start != sp->port.mapbase condition to sp->port.mapbase != 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; static inline struct sci_port * to_sci_port(struct uart_port *uart) @@ -3438,6 +3439,7 @@ static int sci_probe_single(struct platform_device *dev, 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) } sp = &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 = platform_get_resource(dev, IORESOURCE_MEM, 0); + if (!res) + return -ENODEV; + + if (sci_uart_earlycon && sp == &sci_ports[0] && sp->port.mapbase != res->start) + return dev_err_probe(&dev->dev, -EBUSY, "sci_port[0] is used by earlycon!\n"); + platform_set_drvdata(dev, sp); ret = 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 = type; sci_ports[0].cfg = &port_cfg; sci_ports[0].params = sci_probe_regmap(&port_cfg); + sci_uart_earlycon = true; port_cfg.scscr = sci_serial_in(&sci_ports[0].port, SCSCR); sci_serial_out(&sci_ports[0].port, SCSCR, SCSCR_RE | SCSCR_TE | port_cfg.scscr); From patchwork Thu Jan 16 18:22:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu X-Patchwork-Id: 13942131 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 9E533232424 for ; Thu, 16 Jan 2025 18:23:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051791; cv=none; b=Mu+q1O7QQEhiHC28gvh5L7Up9P3w7cRGhlWlcWr2yXJfRBg+8ZJUtS4bebVNS6VrdDMeXHXOVqvk9sjfoWkDnfbR7zUArUVSnaioItqpgy+ChKSmsOprtImtxUVbnYXEKW+xVu96M/V2SK6VNoZ7TMzD43oM/IcHEvVacdJFjUU= 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.128.54 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-wm1-f54.google.com with SMTP id 5b1f17b1804b1-436a39e4891so8403005e9.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=KNnT/wi9pHVswb6KySre49fw3sK2BnrhAPiFySM6GwA0TzDP41Qx+ERgUHjJyp4dfd I3o7RngAdf6Xx+NWS1ghFxvDpol+bukp4kz76G8DYrOw6lUL+5nRx346Gcj0vobAnGAo +tcqIezoZpmeozCNboDq+6PsXDOMDQ13qSyEo3hKgmT5Q9m1Gc/oAUrEG38GyudSwQUQ Pu527+V9jy6Dtoo+0wA2g8eureRlvd1rWbis/2NFMLSVxvwX03sDXUHAsi+T82WnpYZN tt3k+mVTBiMqzL9LzxkKu+GNGkUXFLIh9S61Mq5WfenVOiMWAkhzaeSD/TkbM5Tp5vXd JbOQ== X-Forwarded-Encrypted: i=1; AJvYcCUIH9m7qQYkGd8AnMaI/Evks71isym+4bmy+cJPK4XTiBCUJQ8PPDJsxy2uS5/iBa0F3j6QA9hryfl3HHMEjhiqPQ==@vger.kernel.org X-Gm-Message-State: AOJu0YzCo1LTWJANt3W1uaPK7Jn+tTwKWULqObSx6HdPD9xHpWHWrTHD qmt3DiKsH6kOEnBVkef5n6MhB9P3U5I6R0LsbvuoBqDv0db92jhy1tC+TsVEV5o= X-Gm-Gg: ASbGncsvYuPvitjwqYpjFeYpSP3HPCq/WYr60vD7PacF0IwPGyO8eBp00Zjku18LFr1 v4TCPFiaQCwLNT9qapSi7p6DJP2YVlfFiD1FEPQgC3u8sZOfW/UIvwx4rWmhAGwNxO9wHjRaB4J AhPsr5C566BKvR0CFWvXskN7At4qHo3aIHJ6xTNqtTtPE+u39aYs4phFlsCPbAsYjT/QjHp8Mll ZmqvHOV49LjuhGcK8jkpHV4cL+KFAEr8IQ0s19HBu1X6HdGFSr9YiVPDTnuasxQHazgDV2yfTWL W1V6H7mVVUM= 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-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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] = port B sci_ports[X] = 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 = 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; 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 platform_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; @@ -3433,6 +3435,14 @@ static int sci_probe_single(struct platform_device *dev, sciport->port.flags |= UPF_HARD_FLOW; } + if (sci_uart_earlycon && sci_ports[0].port.mapbase == 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 = true; + } + return uart_add_one_port(&sci_uart_driver, &sciport->port); } @@ -3491,7 +3501,7 @@ static int sci_probe(struct platform_device *dev) platform_set_drvdata(dev, sp); - ret = sci_probe_single(dev, dev_id, p, sp); + ret = sci_probe_single(dev, dev_id, p, sp, res); if (ret) return ret; @@ -3574,6 +3584,22 @@ sh_early_platform_init_buffer("earlyprintk", &sci_driver, #ifdef CONFIG_SERIAL_SH_SCI_EARLYCON static struct plat_sci_port port_cfg; +static int early_console_exit(struct console *co) +{ + struct sci_port *sci_port = &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 = 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); device->con->write = serial_console_write; + device->con->exit = early_console_exit; + return 0; } static int __init sci_early_console_setup(struct earlycon_device *device, From patchwork Thu Jan 16 18:22:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu X-Patchwork-Id: 13942132 X-Patchwork-Delegate: geert@linux-m68k.org 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 79B742361D3 for ; Thu, 16 Jan 2025 18:23:11 +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=1737051794; cv=none; b=Z1RTTAz/pNlV1bCt/1JjE8olyowcfq18dQGkJ3oCmycp1/bfP8Pgkkj1RC2qZrVHOA74dKFBGJ7EuQB/4QjVmeNr3LKqEcvp46YuEGt7cRf/iDtzgHVk49naA67TKCs8aqF2IKEP2gQUaREk29R0ZGrxYuKU9/73oHN/oJ1xGFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051794; c=relaxed/simple; bh=+JZn/ww1FY/kTAFer89gJaTpDgTvbKcrRyepTGJVP18=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iVciyhshjFCFzhQlBCyS385w09eHkQ5Aw8c3NGrIokWugYLaDA/PsrRtxxDbtpJzTZXKQ+wAFMfP2Y2O4Nh+Xj3SdvSjYOhenqyTvkPBB5LBLMYsNzYVVwx+riCVJwci3msE8kNeZ+0deRyTExWiDiTKscYBV13qo3dX6oVxtkk= 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.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="YeUU7cNt" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-385e1fcb0e1so685979f8f.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=XxxergnO2lUJhA9fbITHQQ1lEJmLmTvZ4hpYdgRtQ0M6V04E7EyjX8k8jQXxEmX1bU Qb8KTtwRFmdb6+niuDuC70+jEdH/SRhKURbHdc/td+oVRT4CH5vakNh+w4itcyIMwX7q D7mnSy0whXQuaIxAcZlUxFzqSlEjJzMmBmljlGz8cL/4+b/KbY9FB8/jVoph3ywBaly7 Bp6A28F7myPa2vRVJU2zmhH5QBboSw/kPvcnxJcEV9kA9gcDD0leAdjA+XlwG3NmBS4l 7WoXLWlC6I80lUn6P9aVl78oLazR80jy56xwiakTSUc4VQa+SMa60ik+JnBtp17Swz35 QQGw== X-Forwarded-Encrypted: i=1; AJvYcCW1KeEpVQct6HLIMeS8iodFKsxfnGjyJr2eNXbWM5VbwhU4o5TBGMQ9R2MzlZ6ilBwoCJ1xv619MLaFtN5PA7G7Ow==@vger.kernel.org X-Gm-Message-State: AOJu0Yy3vcUKUiNPbHL6RgizB/rHjBEMsB2dTozsN9snUQ9h3VNPMxRU FlV5nUZdkwRimqWmqjhVwDaYn3CuB8C0ojXvoe4R65XOLjcdgnCsEavuuhUCQqI= X-Gm-Gg: ASbGncvHaplHhYrSrMxEJuS/P6fL+vRtOThNSHV+i9mfsfaw/Rc0iPFob25GQZrb1n6 oYe1uzccZMNpC4SMZCo8OZwU3dioq3mTGtJfucDhU4HKxt5eZ0UAjPs0CvyXImL+h2f+dv68j0d wzkYsQYjh8amLuiH8QLPvzQ2jmyrVnnKkEZyv8w2p3nuQdhVZ4HVR/I9tqjCdSXmEubgGKZADL5 0e7UsXzGxPbu9DpkjZRYgNrZOsFpXNLxWtB03OCV+t8RkPpkzGQ0ilQV2WM4/9c/FN+lHbDjgAG cPfD/4Bdnh0= 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-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 == sci_res->start) - still kept the sci_ports[0].port.mapbase == 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, } if (sci_uart_earlycon && sci_ports[0].port.mapbase == 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.