From nobody Mon Jun 15 13:46:21 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B73CC3E8676; Fri, 10 Apr 2026 15:20:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775834447; cv=none; b=CG0PA28vzsF112Pg0+2lofO1hBsHqHoxbbVRQSQtzxk/pxJu5rX5/82I71ejmzJvfuLq32ysnTvERVrcl5iH7ZrF1DY+TNTfNkpJdU7ffrgtYQlbwJ8ca8eoCOCslWMqzpYZRufRGeAUmeZqSgW10uGVBdzRZmDwVmHgkhoSwmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775834447; c=relaxed/simple; bh=mRlKMaYbmvEt/EhhUAqfvw/bHBc5DdnsELRV/lnGmdI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nlTbwTPMi/043GrVy2tXbt4cwrg9PNy2qsl0lsG3MKmKQIqjHlucUa/14m0gWpCG0Ol2b3OM0yhWhwfZDoy5q+pE5ou6og8ugpNBeKBbZsq25BCty60YqHYGo/Se2ZJCbRfXtgCeVVvI64Tzs52Se+mTaj4xMKROGapbALqrMnA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=ZJ2duZyL; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="ZJ2duZyL" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject :Cc:To:From:subject:date:message-id:reply-to; bh=frUl2/N5c8FQBGdAuzQFsb9h+FkYcMGoBn9caKJfRxs=; b=ZJ2duZyLsdowmDvYpjbLASauWs j7xOEoJoHkWlDbtaPQ3W/SmYcFShZtv7r+r7oS3zhVsvrxT3hrhpcddhzevFbU8SdvpBFil/Uqb+U YwwyMzXHGQMhGgashKQgM3G0WPuFE3pv2RtnMEwhjeoMHVyZAuV0LNbBQaz7uJH/9SeI=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wBDex-000000008Ub-1fUE; Fri, 10 Apr 2026 11:20:40 -0400 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: hugo@hugovil.com, biju.das.jz@bp.renesas.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve Subject: [PATCH 1/5] serial: icom: remove check for zero baud rate from uart_get_baud_rate() Date: Fri, 10 Apr 2026 11:20:09 -0400 Message-ID: <20260410152022.2146488-2-hugo@hugovil.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260410152022.2146488-1-hugo@hugovil.com> References: <20260410152022.2146488-1-hugo@hugovil.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 X-Spam_score: -1.0 X-Spam_bar: - Content-Type: text/plain; charset="utf-8" From: Hugo Villeneuve The minimum baud rate supported by this driver is 300, so even for the B0 case, uart_get_baud_rate() will return 9600, not zero. This check predates commit 16ae2a877bf4 ("serial: Fix crash if the minimum rate of the device is > 9600 baud") and is no longer necessary so remove it. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/icom.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/tty/serial/icom.c b/drivers/tty/serial/icom.c index bcdc072084860..b6399d86a0bc3 100644 --- a/drivers/tty/serial/icom.c +++ b/drivers/tty/serial/icom.c @@ -1396,8 +1396,6 @@ static void icom_set_termios(struct uart_port *port, = struct ktermios *termios, baud =3D uart_get_baud_rate(port, termios, old_termios, icom_acfg_baud[0], icom_acfg_baud[BAUD_TABLE_LIMIT]); - if (!baud) - baud =3D 9600; /* B0 transition handled in rs_set_termios */ =20 for (index =3D 0; index < BAUD_TABLE_LIMIT; index++) { if (icom_acfg_baud[index] =3D=3D baud) { --=20 2.47.3 From nobody Mon Jun 15 13:46:21 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92A1E3E8684; Fri, 10 Apr 2026 15:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775834448; cv=none; b=nBK4BOY01xPWa0el9bNBll4ibI78ZfmbSsiEppDWLt4l67wmdh0QA4AyE1boDz8CwA+UCj5g+VFkew+9xXIMlE9Zg0dPzpixmJWW6fGOolsIYzvddeIeQSoDuCtqacckeZFrbUYUmezZ5rPeUHdhFNvsWiQZxxa4kS1Oo4i6yyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775834448; c=relaxed/simple; bh=3e34Elp4oZaPgMcs2nANuLRhg9ZhtfPsbrpA4+0I0e0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hkJ0y3hWKBWWdIAsWQXH/zM4sJljnRQGJyQ+JGaGL11PyHm4WYUQyfK9G3IUBADhqT8ywrVTe35Xfr7uVH3ep9+IyTEFzchP2SV/kPvbTmzBUlr7E7d2DbURqR3i5IIJ/UZ9l6EkTt75py8WDoxbxd4LnMSII92ok44QWq2GbLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=IipzORVM; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="IipzORVM" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject :Cc:To:From:subject:date:message-id:reply-to; bh=ZGC9oG8zfUwIe9KviJHYFjpLKRoWK8HAakJygSJlWvw=; b=IipzORVMKL9yHRFoV91a1A55cg 6tOyCBvQlLSfUP8UqVYhHLNWDc5qwGfgQRaZizIg/dW+zpmvp5siqddawij5yZ28PaPYuGZ+xeDdU Hcx7W43gsbkoU3t/lbzZfj4IZewl4Qc7QvIVhDm/vPfez5D6LCA15NKfhSrRsLNTDztE=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wBDey-000000008Ub-0ycw; Fri, 10 Apr 2026 11:20:41 -0400 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: hugo@hugovil.com, biju.das.jz@bp.renesas.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve Subject: [PATCH 2/5] serial: apbuart: remove check for zero baud rate from uart_get_baud_rate() Date: Fri, 10 Apr 2026 11:20:10 -0400 Message-ID: <20260410152022.2146488-3-hugo@hugovil.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260410152022.2146488-1-hugo@hugovil.com> References: <20260410152022.2146488-1-hugo@hugovil.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 X-Spam_score: -1.0 X-Spam_bar: - Content-Type: text/plain; charset="utf-8" From: Hugo Villeneuve The minimum baud rate supported by this driver is 0, so even for the B0 case, uart_get_baud_rate() will return 9600, not zero. This check predates commit 16ae2a877bf4 ("serial: Fix crash if the minimum rate of the device is > 9600 baud") and is no longer necessary so remove it. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/apbuart.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/tty/serial/apbuart.c b/drivers/tty/serial/apbuart.c index 3e46341cfff8a..afb04d727203e 100644 --- a/drivers/tty/serial/apbuart.c +++ b/drivers/tty/serial/apbuart.c @@ -210,8 +210,6 @@ static void apbuart_set_termios(struct uart_port *port, =20 /* Ask the core to calculate the divisor for us. */ baud =3D uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); - if (baud =3D=3D 0) - panic("invalid baudrate %i\n", port->uartclk / 16); =20 /* uart_get_divisor calc a *16 uart freq, apbuart is *8 */ quot =3D (uart_get_divisor(port, baud)) * 2; --=20 2.47.3 From nobody Mon Jun 15 13:46:21 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92AB33E8685; Fri, 10 Apr 2026 15:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775834448; cv=none; b=iiH5SgKcEtZY4CnFEdSwuExZU6hhh+c7ISChT4vP1P0+Y/HhbOUVSk2jIt0/LWhz28EJOnhOeK2WNCLJ7oHPNUB9Aro99Fq3nc+AwhamqY04s8NtYR8P2hSVMhteWcQfduFfgLj3tsl6BDGWxzYmuryqfBPduo+bc6nKBDPEwYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775834448; c=relaxed/simple; bh=qre5QTp0oNYNYr1fhvtH0HflUbdsUpmXg9OzasaI5B8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=izfQm/IIE+SreVH2cLiSzg5dSK1y7+1slQXS+2JhP3roRzxsfC/vS302J1GnMpqt/Xfepx35Nm8dHI6OqszStmF7p9zRIvEzUI5Y1MIg8WUUNCdSe729zv8cp8rSB3GDPphVKhb9StN0Uf2rhpREyJ0i/4uVPRA1db99VNcX3+8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=rksytO81; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="rksytO81" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject :Cc:To:From:subject:date:message-id:reply-to; bh=9fp0mmxsvJwLah/tysG889Bb62eYEDk3dVb++99VmJk=; b=rksytO8191iqAg17ks4Cx2+DmV yTGctO1bVonP3zcbAsFcxXn2ohCrzN8SRqKtMqNTnfaUjQYt1FbzSl2c4pEgGC8W2SzPpC3nluw8X N/tSgSENrBXTzNDL2Z2Do2LiTOVoYDx9uudwzy2tre9LmjXSafIDZdjLNQ21k97P2fKE=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wBDez-000000008Ub-077x; Fri, 10 Apr 2026 11:20:41 -0400 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: hugo@hugovil.com, biju.das.jz@bp.renesas.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve Subject: [PATCH 3/5] serial: core: update uart_get_baud_rate() obsolete comments Date: Fri, 10 Apr 2026 11:20:11 -0400 Message-ID: <20260410152022.2146488-4-hugo@hugovil.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260410152022.2146488-1-hugo@hugovil.com> References: <20260410152022.2146488-1-hugo@hugovil.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 X-Spam_score: -1.0 X-Spam_bar: - Content-Type: text/plain; charset="utf-8" From: Hugo Villeneuve Update obsolete comments to match the actual code. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/serial_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_c= ore.c index 89cebdd278410..e6a8ab40442d9 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -465,7 +465,8 @@ EXPORT_SYMBOL(uart_update_timeout); * baud. * * If the new baud rate is invalid, try the @old termios setting. If it's = still - * invalid, we try 9600 baud. If that is also invalid 0 is returned. + * invalid, clip to the nearest chip supported rate. + * If that is also invalid 0 is returned. * * The @termios structure is updated to reflect the baud rate we're actual= ly * going to be using. Don't do this for the case where B0 is requested ("h= ang @@ -523,7 +524,7 @@ uart_get_baud_rate(struct uart_port *port, struct kterm= ios *termios, return baud; =20 /* - * Oops, the quotient was zero. Try again with + * If the range cannot be met then try again with * the old baud rate if possible. */ termios->c_cflag &=3D ~CBAUD; --=20 2.47.3 From nobody Mon Jun 15 13:46:21 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EBCD3E8C5B; Fri, 10 Apr 2026 15:20:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775834449; cv=none; b=SgZwYRVn17xqiX4rsnW0Sjcfl3dUVZv31uaku6ZGcOXTwk1fzxWbCsw2aPPq7be3fUnWb+2f2dzI32NgxIfv4gbgYVwin91HKTVaE4Oo5fwQfTtv5oo4iqq6t/MoSq0WcQ+MPycxrJQcZ/ceTLq2zKVy5cDkMOidZBLvddD5lM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775834449; c=relaxed/simple; bh=EmqzxCeH3+2cTIzPaxzH6HVZPgBKe3xmaPvy+SMJkNA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ArpQzKvYnn0JtrAWiHIAEN8s0OtmOmOLXbw899LX/hZrgQ3M/nA3Ues5FbA56qyVfzF9Z4g5ItjxjkrisWFQg9lMIRvUdE688YHYMKxdrgib6iOaliboN80Yse6pKyhOHupancPNXmuVWELarZ08sMSa/w+3r063eo80L8WCP/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=Sw2OLsWf; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="Sw2OLsWf" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject :Cc:To:From:subject:date:message-id:reply-to; bh=nE+1kczXySniW6DFK8K0g6Io+rAOnMYlKgGQ6sCTGC4=; b=Sw2OLsWfvJiHGg7tTCgi9R6llI +eBCGOM8Wm8vf+vwt4Y1umjSEMu3WnlQBNMeLTYcIOeYSJfYayoUOiSIhUtH7gzPI6wUi1zzriT5H RozMaiC1UgG0JUi3nx5NIySBKozGU5+gjji7hxq6ZVAMpSn7fLeqngDsXMu3b+X4nyvQ=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wBDez-000000008Ub-3UQp; Fri, 10 Apr 2026 11:20:42 -0400 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: hugo@hugovil.com, biju.das.jz@bp.renesas.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve Subject: [PATCH 4/5] serial: core: simplify clipping logic in uart_get_baud_rate() Date: Fri, 10 Apr 2026 11:20:12 -0400 Message-ID: <20260410152022.2146488-5-hugo@hugovil.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260410152022.2146488-1-hugo@hugovil.com> References: <20260410152022.2146488-1-hugo@hugovil.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 X-Spam_score: -1.0 X-Spam_bar: - Content-Type: text/plain; charset="utf-8" From: Hugo Villeneuve Simplify the clipping logic in uart_get_baud_rate() to improve code readability. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/serial_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_c= ore.c index e6a8ab40442d9..f89c0dc295163 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -543,11 +543,11 @@ uart_get_baud_rate(struct uart_port *port, struct kte= rmios *termios, */ if (!hung_up) { if (baud <=3D min) - tty_termios_encode_baud_rate(termios, - min + 1, min + 1); + baud =3D min + 1; else - tty_termios_encode_baud_rate(termios, - max - 1, max - 1); + baud =3D max - 1; + + tty_termios_encode_baud_rate(termios, baud, baud); } } return 0; --=20 2.47.3 From nobody Mon Jun 15 13:46:21 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B52C3DE42A; Fri, 10 Apr 2026 15:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775834448; cv=none; b=E+Sdw5UwsXp8n0lCxTjib8g6TQ+aV3MyAVP+ZVWnSPiR/xRsbLXufWAaUu+uNCtgH5ZyrIgl1E2yDPKIeZICiruMS1PeV+SYkU8anHnq44p5xL+DISW6VejsecxPgiB/6urlWgjDGhwG6lHEB8x218DQXJZCDL5iLXNVj4DTmMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775834448; c=relaxed/simple; bh=QveXexA4o7SM9TI5LRX3Uh2TZeTp9LlHWhBIWjkh37c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r/BdXLQWSdLiFLBrayZOVfi5//sxiKwskysKCLn50aHaAo68UqCF/FogedoD7pNlpfhzc+sNn/C5mvE2DvSJEemb0DmXdb2XvXVpwILSKoyQFx40MGbTkOJe8obfic9hjCSG3Ennn3nzq4XbrhRBgw6TLsnntSv0JbVWc47vGDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=unyzzCnG; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="unyzzCnG" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject :Cc:To:From:subject:date:message-id:reply-to; bh=hBXgaigVMOcZAj/jA49x+8oTS2DDyRSbq9xTUIlauvY=; b=unyzzCnGM7z1+QHAFSXLIjk57d fWF5XoDl7AVg70XiRW7W+zXQqCFAaBM/tjROanesL9wP4/MkuJ/fAuqbV3lY6STwkl0w1NA4SlVP5 0egi2i4+cZEUROM2nVJ8aDCThzv/hP117zRMzeml1VVCFZPVsWHkfndGQd0/f2c2RgeI=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wBDf3-000000008Ub-3TnZ; Fri, 10 Apr 2026 11:20:46 -0400 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: hugo@hugovil.com, biju.das.jz@bp.renesas.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve Subject: [PATCH 5/5] serial: core: prevent division by zero by always returning non-zero baud rate Date: Fri, 10 Apr 2026 11:20:13 -0400 Message-ID: <20260410152022.2146488-6-hugo@hugovil.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260410152022.2146488-1-hugo@hugovil.com> References: <20260410152022.2146488-1-hugo@hugovil.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 X-Spam_score: -1.0 X-Spam_bar: - Content-Type: text/plain; charset="utf-8" From: Hugo Villeneuve If a device has a minimum baud rate > 9600 bauds, and a new termios baud rate of 0 (hang up) is requested, uart_get_baud_rate() will return 0. Most drivers do not check this return value and call uart_update_timeout() with this zero baud rate, which will trigger a "Division by zero in kernel" fault: stty -F /dev/ttySC0 0 Division by zero in kernel. ... Fix by returning the larger of 9600 or min for the B0 case. This now ensures that a non-zero baud rate is returned, and greatly simplifies the code. Signed-off-by: Hugo Villeneuve --- Tested with the sc16is7xx driver by setting the minimum baudrate to 19200. If a "Fixes" tag is needed, this would probably be: Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") This would also imply, probably, to merge this patch with the previous ones (touching serial_core.c) to make porting easier to stable trees... --- drivers/tty/serial/serial_core.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_c= ore.c index f89c0dc295163..075a69164aa7c 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -462,11 +462,10 @@ EXPORT_SYMBOL(uart_update_timeout); * * Decode the termios structure into a numeric baud rate, taking account o= f the * magic 38400 baud rate (with spd_* flags), and mapping the %B0 rate to 9= 600 - * baud. + * baud or min argument, whichever is greater. * * If the new baud rate is invalid, try the @old termios setting. If it's = still * invalid, clip to the nearest chip supported rate. - * If that is also invalid 0 is returned. * * The @termios structure is updated to reflect the baud rate we're actual= ly * going to be using. Don't do this for the case where B0 is requested ("h= ang @@ -481,7 +480,6 @@ uart_get_baud_rate(struct uart_port *port, struct kterm= ios *termios, unsigned int try; unsigned int baud; unsigned int altbaud; - int hung_up =3D 0; upf_t flags =3D port->flags & UPF_SPD_MASK; =20 switch (flags) { @@ -515,10 +513,8 @@ uart_get_baud_rate(struct uart_port *port, struct kter= mios *termios, /* * Special case: B0 rate. */ - if (baud =3D=3D 0) { - hung_up =3D 1; - baud =3D 9600; - } + if (baud =3D=3D 0) + return max(min, 9600); =20 if (baud >=3D min && baud <=3D max) return baud; @@ -530,9 +526,7 @@ uart_get_baud_rate(struct uart_port *port, struct kterm= ios *termios, termios->c_cflag &=3D ~CBAUD; if (old) { baud =3D tty_termios_baud_rate(old); - if (!hung_up) - tty_termios_encode_baud_rate(termios, - baud, baud); + tty_termios_encode_baud_rate(termios, baud, baud); old =3D NULL; continue; } @@ -541,15 +535,16 @@ uart_get_baud_rate(struct uart_port *port, struct kte= rmios *termios, * As a last resort, if the range cannot be met then clip to * the nearest chip supported rate. */ - if (!hung_up) { - if (baud <=3D min) - baud =3D min + 1; - else - baud =3D max - 1; + if (baud <=3D min) + baud =3D min + 1; + else + baud =3D max - 1; =20 - tty_termios_encode_baud_rate(termios, baud, baud); - } + tty_termios_encode_baud_rate(termios, baud, baud); } + + /* Should never happen */ + WARN_ON(1); return 0; } EXPORT_SYMBOL(uart_get_baud_rate); --=20 2.47.3