From nobody Mon Jun 15 06:30:21 2026 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 07E6F24DD15 for ; Wed, 8 Apr 2026 14:21:10 +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=1775658074; cv=none; b=Y1/OIQFmW0mw945zShZ1o9zSc7DzRLybKPo2LBOUFsz3aee0Gy6NqyDz6ezFxvYrPuk5Zks/l/bJVm02SF0eE843zQvZBhDODBFumyCcPVuJ5cQr/0dPyMUui2BsrwOvpZIHkA/J/Z49u8UgvgD+f4/+g2wYSzs9Dy7Ci7fMAYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775658074; c=relaxed/simple; bh=62Mob0LE3sWA1dLdXfSheWhD/xPqahp1LlfQRWC9iC0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LRH003RLpBsMTE8xU15QVJm6+Q/Vb8zPqDXBpd+HoMzYr/T7VncPh4msyxy74czSgFTfI+7uiJfAckbnStKAyv/ZjsnSycoaPgP9x0zowJCgXBXq5x9rVtr+lSKJX8mT+9putDY90rL7UsAI6K7UP/cAFiWnTB1RXZzmEBwndvA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FGUeC0qT; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FGUeC0qT" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-43cf73bbfbdso3752961f8f.1 for ; Wed, 08 Apr 2026 07:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775658069; x=1776262869; 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=dR5e0/e1aBEXjk8lZ27PYAez4UpdVKh/yDZiJgFVL94=; b=FGUeC0qTokb2e1w1lXNnv+ondKabpl/wwRUlkK0cqeJNm7B9wmpQFYfz9wffQ+V2tf 0NTcBR3cg227+lJTcU0LBscwB1ZfS7M5uQnm359dQXUKLbu0HSyQjWm9/rzurw94KgT0 FJ0khpa4CSzJcgfidKQj7eWgXVzdlZNsPRmTTfk/2Oeq7ych39agknc3iJiKcC8Se+Uw hpEeExusf0WVB+0oZYWo8DMjs7+HdrLkObWRMZJWDUiODS9Z7lFKBlslQniMMxLkqcCL byjcCDK7XwRHMPDNgsrqDUFxorsANF5IFNvwwls5EkzYfMMfYyZMAoUjTTQCXUcu38BL M0Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775658069; x=1776262869; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dR5e0/e1aBEXjk8lZ27PYAez4UpdVKh/yDZiJgFVL94=; b=HMfgMURVVbHymuMHCx0J4nzXt1W9oHBAd/doZmc+McOdGG/SslUA7PfIUyi5pOmOLQ alCFviTzOeLRVqcZExBDAdfS2RrMEuJl1BpFf304yOY+w9b2zqRCwqYfPziddzlDTqt/ 7luEsWzMz1Rw/0FV7GqfNx/Knyv/d4vXOENHOwnlbinCQJE358mRbUwzBe3n4+YjIwzg y3ccn8trOwwhMmbwcYw8V93OLkneQ8s8Oa50Ns+IT4yOxzWTmwXclzpDTu0HRPzaWgN3 XHlz/Fkb6oIHbn+v71W8AMP+TOUEvutYd+tK0WgJMe1IdB4+C6Pg7AZ7UBB7uKfDS2uw 60kg== X-Forwarded-Encrypted: i=1; AJvYcCUuAkrVvNEhOtzw4ycTT1Y22VUhpVsIPrt7pHaNq6fKhMz7JIi2TTNkz4l2JKjKlt+PkQGFuRT0StlEq0I=@vger.kernel.org X-Gm-Message-State: AOJu0YzgCMQvdp5t2Dz9U4oSkFpAnkjjyPdqCGHDadPu/LEDEdaBzQmV q3mvy+z+6eY/83cn7eUeUbS+srz99/hpzk5zAu8SwPDscA2LfhL7T7Ud X-Gm-Gg: AeBDieupPljBBRtJjQ8OJrDg7+qrZJrQTmBk9pbHGFaBEulFiML2OW6fPrIIwFqmU9i PMZ24yugHFu3n5XMxDzhwcsHydLIlA+xuZhULjrDojiYyngpfI8DFiY0l1AzEEidwpuAWPNaloH cEmhvZ9R4lbPFu9FUgPrvVj7KAbUgHkZjCN0fxcIuAIhPCBmAOu1aZqD1DwDUGQjVmFTXonsLrw GQuTe17kfK+eHTyIHU8KnHHYIQxFy3E4gr56s75qJ7IjGQClQcgr0nmVeKUVXjgbU81rryPq/BS IXnqk4/ct/TwjkbQwCtODxRczl2jy50kwpXUnMO9v1r9nlxPYMIbuiGME7ZUPv/ftywmNcvYZiK +QVQkUlFaXYYIyWyPsjIBHjMOqCdMRcBqnvs630+MVg9JDtJVbYmBD0ckN8eVMeJYwSCkwoUmkC xjkdyLyb1ujzTp9Fk/R88haweto/d5VdEWCu7hDvepmLrWAtI= X-Received: by 2002:a05:6000:4023:b0:43c:f52b:8003 with SMTP id ffacd0b85a97d-43d292ff3d8mr28536857f8f.36.1775658069291; Wed, 08 Apr 2026 07:21:09 -0700 (PDT) Received: from localhost.localdomain ([2a00:23c4:a758:8a01:f65c:8080:131a:202]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d1e1fe0b0sm60474467f8f.0.2026.04.08.07.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 07:21:08 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: Greg Kroah-Hartman , Jiri Slaby Cc: Biju Das , Geert Uytterhoeven , Thierry Bultel , Wolfram Sang , Lad Prabhakar , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Biju Das , linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 1/2] serial: sh-sci: Avoid divide-by-zero fault Date: Wed, 8 Apr 2026 15:20:58 +0100 Message-ID: <20260408142105.310210-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260408142105.310210-1-biju.das.jz@bp.renesas.com> References: <20260408142105.310210-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Biju Das uart_update_timeout() computes a timeout value by dividing by the baud rate. If baud is zero =E2=80=94 which can occur when the hardware returns an unsupported or invalid rate =E2=80=94 this results in a divide-by-zero faul= t. Signed-off-by: Biju Das --- v2: * New patch --- drivers/tty/serial/rsci.c | 3 ++- drivers/tty/serial/sh-sci.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/rsci.c b/drivers/tty/serial/rsci.c index b00c9e385169..a0858bab0822 100644 --- a/drivers/tty/serial/rsci.c +++ b/drivers/tty/serial/rsci.c @@ -286,7 +286,8 @@ static void rsci_set_termios(struct uart_port *port, st= ruct ktermios *termios, sci_port_enable(s); uart_port_lock_irqsave(port, &flags); =20 - uart_update_timeout(port, termios->c_cflag, baud); + if (baud) + uart_update_timeout(port, termios->c_cflag, baud); =20 rsci_serial_out(port, CCR0, ccr0_val); =20 diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 6c819b6b2425..429e89106ee3 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -2805,7 +2805,8 @@ static void sci_set_termios(struct uart_port *port, s= truct ktermios *termios, =20 sci_reset(port); =20 - uart_update_timeout(port, termios->c_cflag, baud); + if (baud) + uart_update_timeout(port, termios->c_cflag, baud); =20 /* byte size and parity */ bits =3D tty_get_frame_size(termios->c_cflag); --=20 2.43.0 From nobody Mon Jun 15 06:30:21 2026 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 0F2153D3482 for ; Wed, 8 Apr 2026 14:21:11 +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=1775658073; cv=none; b=jmasvCE67Dnv0s9+w5VEwgwuLUhI3OcwHDUMfVJIPV48rJlXmDsXoA5/khixvEedSVt68vqEiqsjaB4rQP/LjbI+rihXJlGiPLTasdN+vpiaRbsNs7g8RmDYArEoancoQsG4uvQFUt4fykjlQaKEt++WAL/NvRukdZLVDS3liew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775658073; c=relaxed/simple; bh=ddrfr3rql9m/sbOnBCJC/YlBY3/WX7/HgB5dY7+ixvU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mpvILY7Y5x42V3xb78ifbIdIJlwz4hkVSWpD7TtfVhQAOtzrf1shcndn3sWlt29sq5aJbbDfNLCm1RRL0jE3dYCvxdphtpXaRK4V2aUARvALllDij0BRuOZbvf+fpYpVZsHeHqepGzAFfZNLk7+H2wfcVcTu/HvJXqA8QcKN+zw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BBVsyJrb; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BBVsyJrb" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-488a041eae5so34080605e9.1 for ; Wed, 08 Apr 2026 07:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775658070; x=1776262870; 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=xt7/zv+UwHJyWIBrUUqp/D/ZXiUTMuYqdObuX9zLVHA=; b=BBVsyJrbKPFtcy2Rz7Hey1WwovPgkvZo0SNnfjnoz7ULn3mZ9b2p9FMFDo1ODG68pL kT0IRnGeh6RKsujwalXC79uC00tL4TBmRJ7GjNYBp7/7vbqOe20CGoClunKp8vh157bQ 02Ult0lXYwTr/CxYzCv08r7zOBheaw59tUo9R+vOTUthMzKLMgwyiyzDE6rUhawQ5m1d f1GHt9tTcySsDNuAOtMKNkNA97UxQiV5etToZwM4SeCT+HaqUEtLMRKqeO586ltdG4eI M2hfYwaCQbYplzs8nSBUnEhdLRAf2HI3yjU8sf6QqtrcubFbyCbsg8CURLJI1YNM6d06 5rmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775658070; x=1776262870; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xt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XOdSsBPl6zgRrNgorQlXyZE Nk7uPTT/VmThF/nU8EKGEl1ieITsJ9YgGamxIqoD8Ke7Ppe89U4APKGml7bQ== X-Received: by 2002:a05:600c:a318:b0:480:3ad0:93bf with SMTP id 5b1f17b1804b1-488997dd54fmr202593925e9.24.1775658070197; Wed, 08 Apr 2026 07:21:10 -0700 (PDT) Received: from localhost.localdomain ([2a00:23c4:a758:8a01:f65c:8080:131a:202]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d1e1fe0b0sm60474467f8f.0.2026.04.08.07.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 07:21:09 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: Greg Kroah-Hartman , Jiri Slaby Cc: Biju Das , Geert Uytterhoeven , Thierry Bultel , Wolfram Sang , Lad Prabhakar , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Biju Das , linux-renesas-soc@vger.kernel.org, Pavel Machek Subject: [PATCH v2 2/2] serial: rsci: Remove goto and refactor baud rate clock selection Date: Wed, 8 Apr 2026 15:20:59 +0100 Message-ID: <20260408142105.310210-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260408142105.310210-1-biju.das.jz@bp.renesas.com> References: <20260408142105.310210-1-biju.das.jz@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: Biju Das Replace the goto done pattern in rsci_set_termios() with a positive conditional block. When baud rate is zero, the clock selection logic is now simply skipped rather than jumping to a 'done' label, eliminating the goto entirely. Since RSCI only uses a single clock source (SCI_FCK), the multi-clock tracking variables (best_clk, min_err, brr1, srr1, cks1) are redundant and removed. ccr0_val and ccr4_val are likewise dropped, replaced with hardcoded 0 at their write sites, as they were never modified from their initial zero values. No functional change intended. Reported-by: Pavel Machek Closes: https://lore.kernel.org/all/abPpZULsXhRmXTX9@duo.ucw.cz/ Signed-off-by: Biju Das Reviewed-by: Geert Uytterhoeven --- v1->v2: * Dropped the check (abs(err) < abs(min_err) as it is always true. * Dropped the check (abs(err) < abs(min_err) as it is always true. * Dropped variables best_clk and min_err as they are no longer needed. * Dropped intermediate variables brr1, cks1 and srr1; results are now written directly into brr, cks and srr. * Moved dev_dbg() inside the if (baud) block. * Dropped ccr0_val and ccr4_val, replaced with hardcoded 0 at their write sites, as they were never modified from their initial values. * Scoped variables err and srr locally within the if (baud) block. * Updated commit description. --- drivers/tty/serial/rsci.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/drivers/tty/serial/rsci.c b/drivers/tty/serial/rsci.c index a0858bab0822..c2440fd5c02d 100644 --- a/drivers/tty/serial/rsci.c +++ b/drivers/tty/serial/rsci.c @@ -217,16 +217,13 @@ static void rsci_set_termios(struct uart_port *port, = struct ktermios *termios, const struct ktermios *old) { unsigned int ccr2_val =3D CCR2_INIT, ccr3_val =3D CCR3_INIT; - unsigned int ccr0_val =3D 0, ccr1_val =3D 0, ccr4_val =3D 0; - unsigned int brr1 =3D 255, cks1 =3D 0, srr1 =3D 15; struct sci_port *s =3D to_sci_port(port); unsigned int brr =3D 255, cks =3D 0; - int min_err =3D INT_MAX, err; - unsigned long max_freq =3D 0; + unsigned int ccr1_val =3D 0; + unsigned long max_freq; unsigned int baud, i; unsigned long flags; unsigned int ctrl; - int best_clk =3D -1; =20 if ((termios->c_cflag & CSIZE) =3D=3D CS7) { ccr3_val |=3D CCR3_CHR0; @@ -265,23 +262,15 @@ static void rsci_set_termios(struct uart_port *port, = struct ktermios *termios, } =20 baud =3D uart_get_baud_rate(port, termios, old, 0, max_freq); - if (!baud) - goto done; - - /* Divided Functional Clock using standard Bit Rate Register */ - err =3D sci_scbrr_calc(s, baud, &brr1, &srr1, &cks1); - if (abs(err) < abs(min_err)) { - best_clk =3D SCI_FCK; - ccr0_val =3D 0; - min_err =3D err; - brr =3D brr1; - cks =3D cks1; - } + if (baud) { + unsigned int srr; + int err; =20 -done: - if (best_clk >=3D 0) + /* Divided Functional Clock using standard Bit Rate Register */ + err =3D sci_scbrr_calc(s, baud, &brr, &srr, &cks); dev_dbg(port->dev, "Using clk %pC for %u%+d bps\n", - s->clks[best_clk], baud, min_err); + s->clks[SCI_FCK], baud, err); + } =20 sci_port_enable(s); uart_port_lock_irqsave(port, &flags); @@ -289,7 +278,7 @@ static void rsci_set_termios(struct uart_port *port, st= ruct ktermios *termios, if (baud) uart_update_timeout(port, termios->c_cflag, baud); =20 - rsci_serial_out(port, CCR0, ccr0_val); + rsci_serial_out(port, CCR0, 0); =20 ccr3_val |=3D CCR3_FM; rsci_serial_out(port, CCR3, ccr3_val); @@ -298,7 +287,7 @@ static void rsci_set_termios(struct uart_port *port, st= ruct ktermios *termios, rsci_serial_out(port, CCR2, ccr2_val); =20 rsci_serial_out(port, CCR1, ccr1_val); - rsci_serial_out(port, CCR4, ccr4_val); + rsci_serial_out(port, CCR4, 0); =20 ctrl =3D rsci_serial_in(port, FCR); ctrl |=3D (FCR_RFRST | FCR_TFRST); --=20 2.43.0