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 Beznea X-Patchwork-Id: 858105 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 8766522CA1C for ; Thu, 16 Jan 2025 18:23:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051786; cv=none; b=msDqtKPj3RpQeKQ4gcVCopYh+hJtY1DkRkPOBSQa5XoVNgXqxTdFEPQjXY0xCsIiW5As0vPETQnKINT5YjA320NIWzPgl9xDBo66b2kyWYaAXft01awFFRF57BUtRE0WdCV6x8CHnBHSl7Jvjh1TVaBnIjZ1THIlpZWqH7uvit8= 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.49 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-f49.google.com with SMTP id ffacd0b85a97d-385de59c1a0so760216f8f.2 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=Yjy1ES42OP0KcA50/iJVfMRo6fBppwbDE4fnXQanAcLOuaslQysqtMQX94YIg4A3rZ gMUg3BVdpDzuPJi9sYUjblAhyC0GD3p1H/HTjYD54rvlwW3Mjvz0KyzbAVRjmb7NbO4K C6rhk7/Uu61xYjGkDMqLxA3dq04a6uGuZM0CF7GUEL2KExEExsRSWqGz8l+CYO6cac66 yWRkxRSSajNnqeKgYtT1VZPyFJ4NKy8ksnF1q38N6HBO+kddGCgMi8brRbeZ41buPSIT Jy3KDP03LbM/P+/NYcNBGVfGpjeY6xQmRFg0JIBl7WJm/KPnshTOHn0rAh7gh9b9LT22 AB+g== X-Forwarded-Encrypted: i=1; AJvYcCVXsJy9Ai/fuqH6XW0p8XLXkpGuGYvdkASI9dyz8+o3rM7jlcgcr63Dv6OC86XL6hLD9U6pK5DPAgVR2H8=@vger.kernel.org X-Gm-Message-State: AOJu0YyAX/ufykNam0+5BsMSR7Ay1eePiKwcghjebatfraaM0WquYL0l xbWkJKtyTQl5jcNQ1CWK0e3bQsT/+sSul8wDzOdxgwUxQnlWJ3L5pP+jgSHyijc= X-Gm-Gg: ASbGnctOF+J1iF7ClQWTsx2dRFRGDBS+lh0CRs42X/jL1icsL1s9QNqANK58ua/X+0n 80z898V0HklhoVOlIZu0k7zuoPdDWyvcPWhktIEt3LAXW8F5MkQrOvmiyMLpwV801xj3OPs06VE gbdYVHMiLpT9Tqv4KoDF02Iv5H+CFUEXZGyHyjrtG7ECz61PbTkSpbEYErtmaEqhhCVP5t/rbxi MzFZlkVbxaNR0VxzeANRqIoIJIGlgnuTELyMAiGymwPrkGau1uro6HOI5WBnftmSgs5rNmi5FZF afVcpDFdEdg= 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-serial@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 Beznea X-Patchwork-Id: 858647 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 24443190685 for ; Thu, 16 Jan 2025 18:23:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051788; cv=none; b=G7AQEDAxLcxJ/WHW7tJGll0NuWOOzoCkaPWUaC6KqrWY2HJ3OikCrh52W1hyuFa6KlFdA+7mG0bWvnBg8SQGhuPBFfSyy/Y+KOkshyiSQsa8WhF9ylo/h2M/VgTLkINUhqGMOJ5yNdfQPqxokJkC5T0R1HT1C8OScq1xIrPDfyI= 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.49 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-f49.google.com with SMTP id ffacd0b85a97d-3863c36a731so1078575f8f.1 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=mrTRekApL7REsNdMTl6h5WrPVyKBeHj7ER5EnkpCjYt7HRgas3Ly8kXgub3Mgg1dez dikTr06FLplX4jGyJEsszClY5EkH1ZQfX/hKNt3FuX6JgPPLy6e7sc4NqUPplPnyl7/Q ROmPQ+mnAAKZSFl7AgSI8m0xKdGYo8kg9tQ3M/gU+QhhDVEmVl3ysJ61Xt6YoysFOEtC CgqOmZYFev+q1qSVMJ7VXn2PMod2x7TluMHCKCTyZO2KyggFS7OLYI2awO3c/NYABw0W DmGySwvHz5uzti6HQIfUhEumGmmFvbjReRn3oZQ0FkMkHWqNBwcKuCDdzx5Mcg1GpKnY KFnw== X-Forwarded-Encrypted: i=1; AJvYcCVBXQUhoAiNQn6FKSH/Cpz95atib6UV78hl+7dRikNtI8hPSoI6FdZImDHjz7/QGnuZSWBOXs14ORClMBA=@vger.kernel.org X-Gm-Message-State: AOJu0Yxn2q/Lh4wkm8HDoQh2iBgBAOj0JDFoOLV3HT49glvJkzBtdck3 vRJRvLyW25I+9qCwqSssfRjskh17IyegJAVwVPvhNiuMdYZrG1GAdm9gqJl6lUE= X-Gm-Gg: ASbGncuBKD/qzNxWGiW0n03Mh7QvqTT9fgQZwTiH9LDwyd5E/7NysDdbI66b17DZuBO K5hSg6/UD0iYQOwPoRQFjizdhhXQ7Lc70kRO8JEuEBc2Kp2OxgIrAARsJbdHcPFInTwn7w2PRLi 5hyhjI3YIX8jXndPcEvPUHScXc9BMEqPlk2xwdfr5aWjY2E740gA52sf2p/FRFKgt1oCtaYyYmi kRBoig7drxZzHcL4l+kwUPnKKhM2rQa5gLL+RV0Ygu946gF/ibHRTTSDUH4Dgdiv2AOfIvvyoyY bmcJ3hFckgI= 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-serial@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 Beznea X-Patchwork-Id: 858104 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 A441022D4D5 for ; Thu, 16 Jan 2025 18:23:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051789; cv=none; b=c8DzsdpLg4DmzQaqwoYb+rVGXv5DuLxr83+75GZsKVMXI3WeCVz4Pn4vThSCZefsdmtrh1jvBD7M1AMbUE+AK5tX2Arbf8y7qD179OKvIfw9suXeM7ZO0N/9lfJQiLKqV6/lSwtrMqNNk1pjYHZD+DWix7vPsx3zbLh1L6X3dfg= 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.52 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-f52.google.com with SMTP id 5b1f17b1804b1-4361815b96cso8197065e9.1 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=DcP6qEwERMf/6vpBhxYf79DJZIyD3Sq5j9xeKTTNuMmZlrixkozNnyFfEM8kFtpuBz MIct+QfE3FnD35GGdNPhKmE+WAk2uX7a3vmyCietrsO/VGSZHUQ1qTZRDs4DZg0XjzhV 0IeTgdLiXgbPUaPoF/9kjNiZlo2Eh3ZuN7YcuOE7ZiobZFr3y9kRXWkY+8blD1FrfAob 7CYQmKLJFSbc4TetUIdKSYHiT6CQQZ7t8+7whPf+7tXv7QImwoxaC+kGlq2MtxbRGjfd iifAGMyO2vnyUKCbJLVBJpPtMVuHnBbqxvw4sa9Pgod87olNK93UXnfPfLvTrZ7R7FCR TkQg== X-Forwarded-Encrypted: i=1; AJvYcCVENasFMlTCGLQYZIpidindBBCzmfydzCgefJwYyo/la2k6LcN6oX/acTCR1/YNS+a+pdYELQX5SvWIUFk=@vger.kernel.org X-Gm-Message-State: AOJu0YwMB2gX8+xLh14oOT7MD8A2FGDo6KN7zUodDBmcSl2jzs2Kvsqf gaOq2msDWdVl0pyRxwQuY+Wy57q8KhWRFZ+GMOQux9CbhAMKVUoveIUsKgjS7yQ= X-Gm-Gg: ASbGncvPXCZFNNlh7QkPjEjRNoRCHAKFCQiZffoaW/RiMGMJl8ZAE1xfVj/KcIwkwVV MHqsRhZRE+sPPgi1S5Ysn9k8dK8yV0VrvJbvXJJhBzblYR5P7F1rYyur3Ja5c7J0h+VOAvMsmlY zm24RjKwVigHen7kTPLbbkBDSX29t8z4mEAoX5rCj1GFaQGmLdcTqTR4zTYTfEOVkFiq+AXheb1 f32BXg5Pv2EqJObEgUR+OzgjFH0Phkm7CmPVgHx7Bmn+GTd+RNVsuEn2jkhNrlwPuDOJFQ4Lfzw GYH4Tm+ZszQ= 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-serial@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 Beznea X-Patchwork-Id: 858646 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 CD0BF233532 for ; Thu, 16 Jan 2025 18:23:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051791; cv=none; b=F7bEKl6FRYfK75CVgCZXJ2rX/V1W22suoFBw9UXo8oZA7Z/kXwLAX9DPC8f0UUz+QCDP0iUTDgFQr75psVcwA3NAH2I4Bcsq0/4QT9vajoLYXGFsS+Ro1HBvoRmPyxdtINMehpgJ+nMNIPQHRnRl/68GXBC22jWcXtxb3G0jvWQ= 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.44 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-f44.google.com with SMTP id 5b1f17b1804b1-436249df846so8343935e9.3 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=tNuhr6RYYgkWAA5Fa4fYTxIGe/zsSPdmCFpJ5bStGEVmBQnhyNBV5o/Zt1SXgvpT0K 4gzQSIv1OG/CQBo9ekXY5J4tu5XcQIhOv2ig0h2i7sGMtvdA1y71bw4wnRA9KajTTpIL rcsFN7lioX4BhryRWwTYmEQwIdO4ipOCHbIzjohXLoZgCpJrFoyuV08LwfueQyv2xiY/ 8gr8MwW2bWhH2Z0DWDNlRfa6PwrM6SAGiwfD3fsm9JhO8AaZt4YvVcuQWy58BV0afmNM 9w/Cup1BQmOcd7vEuPRJgBiYFRVRmYZSFUCCZQYTR4bSiLERplF6dx9LerTZb4SQPQYi 7Jng== X-Forwarded-Encrypted: i=1; AJvYcCWC/O/1GWtMWbbSLP2SD7XtKaIEyUisQPcZn2H7qdXkNx0urbTPe1/YCEPKFfZZ9C9E2d/zzxgo59E7pw8=@vger.kernel.org X-Gm-Message-State: AOJu0Yxt+AX7JQgnCgwL/EdcRScaBqsX7pPO9ERiDELiPWjamMvXfGHb KIoSKJXwcGll5ucIfaiK1xjBO+mUClg6JqxRh+uLKCfsn7+c5/gjI9OHzegh7as= X-Gm-Gg: ASbGnctMAVe4j8jPUEkg9dAnLLg+nmYxT2txGSZBckCVriPUOE0zMjtfGYMUs7EazVi HWxk+0zNMPa+xR3ZD60ZzanDiLMXOmpqTVnr7kUtJjLB11spp8fL+PNbQ6hUTeHCZ8ZojpyUVfu EBsskypCqZcU37mBGiPRgrYFtakztij2IL7peUMXSTyjwlW5SJPO53oWwf2Kn5+3KMM0Me8NQqP 0uc7c+jnk8Xk5203qxztteyzKwotb0GVGJPmC9w3KjRXpeYD+IuPkjWNWOaMSca6V75PxgMfKdT ZFfx5qDTOYI= 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-serial@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 Beznea X-Patchwork-Id: 858103 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 7F3AD2361DA for ; Thu, 16 Jan 2025 18:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051794; cv=none; b=bhMNC2cj0SsBg+MprqDHnk4njNl+hPHsGZjygm46kuvW1u8bH2+9oCZ/N1fcM8+W7V8fDQGA1S1NrQlzAp6yCX3tWd20vRMTI1pbe/4aa4wWCQxXWHGcw9smvPebL3i+dTBa90nraHu8EBaOZQTev3C8mGX4ojNV/WHRmPLdkUw= 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.52 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-f52.google.com with SMTP id ffacd0b85a97d-385dece873cso770137f8f.0 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=NTatGxMIGhZyiP2JOsOUaVKI8ZfeW9VVYj5nsq/kf2onbaTv785BX40ph+fRucWplH WZf8F85EUQwd8Mx+aYBhkdH8jza9ju4sQa0mXaLMUjkGd6WLuto13xRxKUbAk9kzVsoW w3wNXTO7HMfAgBweNGnowyMdyyBS3nIkDGx6QQkZpSUJX5rzA+H88+qn59/kndO/ljCw b39mMLqa9yHMCmG5nvjUs2zn/lZts4T4IIOmTbx8LxQ5CvqSBkuu/UZ7ZIqJjk0X0FdN k8BYYFwNqCyzd+3/rBszEXNDJi9WjAMRnqXZUJ74Ych/tRjWBUJ71b0orguSVhW0A6tx SajQ== X-Forwarded-Encrypted: i=1; AJvYcCVp4Q8uR5xLpWJsDlY4GkQpU5Sc2/9O2w+KOvFDfBxcBTjTtULYpiospWovFZA4JwSWpMROa6X4inFJ8PY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0+cZ/Ef4efheum02xOjW1qeATaMEjb4JfHVV+X1oPnuE+nqyb 5OSHBjrITrPoiBpcBAmiwphQpyiWFx9sK43Lk/KhR+cjOtysDrw+DQn2eVtQgKc= X-Gm-Gg: ASbGncvzr3Q1+WmCxCOG4c+3DbPtyASyWzLJK7Qs+pkVZSh7ruriLLKdjQxsAjs8Jo4 1AoHJFFYNXmZDaZI6QPmu1N5NUL8arQLWs32xjI8z0+Ql0oM71SpRs2/U6tJKNMQ9XQBCrghMAR EvdWbAEMLouOtMJyeD7cZdZ+LlaCT0k3Oo+nGXLiwB9OOHdiWWv5YZozXuBdOAjzmIAynC7q1Z7 p+Qh033gdeGHINu6zO9iXQQABQlDshUDuy+sHnwJuQ5dHXfUHqmym4FU4BC7HpKHulf74B/MfMu jQ354KBW9Rg= 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-serial@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.