From nobody Wed Dec 17 08:12:39 2025 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 77E2434CF3; Tue, 16 Jan 2024 21:30:20 +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=1705440621; cv=none; b=IdZAkFHWpeA02kmyQGA2AQhSjkIF9qOgelPSOrzbw8PNwupsvP+mKCocqMqYRDXNdipF3KG+N8vVPnNaNh95fpZMlFkRTvPajdsVM2k+ijA+oA8H0seadMMsB339RZobnl14wPqe5UZfml+fkz0rDSYcfanyi22bWvagaPc7p3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705440621; c=relaxed/simple; bh=9mBTImWWy3SGrRbzyE15IxTVRNYtD8T+YpnHzJ2/24s=; h=DKIM-Signature:Received:From:To:Cc:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: X-SA-Exim-Connect-IP:X-SA-Exim-Mail-From:X-Spam-Checker-Version: X-Spam-Level:X-Spam-Report:X-Spam-Status:Subject:X-SA-Exim-Version: X-SA-Exim-Scanned; b=fZqZfLm2W6EyAKd84iXCFpAvvlBjwx6VMZH2jBrGvHZEXDyJR6zpqw54x8quaegtOWozODLaOjZZxcN2dV1Bnb6NRxS5//2Si0H+UviECSPoylzrfozJ/lS+pBSmGtp7FBp7BINRL3OVtrdPBAy/1jG4SoJMTr6WDBk8XejJnxo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=BAnTcFXe; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="BAnTcFXe" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Cc:To :From:subject:date:message-id:reply-to; bh=LO5AMJoi4lTGu7m9IP/Mq7nyuFtod3doZ0XW/a9gDtY=; b=BAnTcFXeeaFHwk54f77LfkYZmJ k4LXbCe4HPNJFQMZM+XdJNn/8RbVJt9kE+YlYPaRkS26/J2gDg/gxptBEZdMZiDbOHJv+STz+1EPj nbpNRnwx2mYKbaH2Tioi0rD8O3WY3YpQqeN3q08XXJvpIt2XvDhZaO8TOxnT1dHcpbHw=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:47418 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1rPr0X-0002ia-Ky; Tue, 16 Jan 2024 16:30:06 -0500 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, jirislaby@kernel.org, jan.kundrat@cesnet.cz, shc_work@mail.ru Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve , stable@vger.kernel.org Date: Tue, 16 Jan 2024 16:29:58 -0500 Message-Id: <20240116213001.3691629-2-hugo@hugovil.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240116213001.3691629-1-hugo@hugovil.com> References: <20240116213001.3691629-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-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Level: X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * -0.0 T_SCC_BODY_TEXT_LINE No description available. Subject: [PATCH 1/4] serial: max310x: set default value when reading clock ready bit X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) Content-Type: text/plain; charset="utf-8" From: Hugo Villeneuve If regmap_read() returns a non-zero value, the 'val' variable can be left uninitialized. Clear it before calling regmap_read() to make sure we properly detect the clock ready bit. Fixes: 4cf9a888fd3c ("serial: max310x: Check the clock readiness") Cc: Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/max310x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index f3a99daebdaa..b2c753ba9cbf 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -641,7 +641,7 @@ static u32 max310x_set_ref_clk(struct device *dev, stru= ct max310x_port *s, =20 /* Wait for crystal */ if (xtal) { - unsigned int val; + unsigned int val =3D 0; msleep(10); regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &val); if (!(val & MAX310X_STS_CLKREADY_BIT)) { --=20 2.39.2 From nobody Wed Dec 17 08:12:39 2025 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 758B934CF0; Tue, 16 Jan 2024 21:30:20 +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=1705440622; cv=none; b=Hg1PkwLCYZlIbIi39d3ap5ISM8W7nek50teQMVTBr8feSeN5TK2CLd2Y/4QsoCc2yEz2Efhekk5P4+eNkkmnKyFaQouQ9LS7tsZlF+7MZfCNW+gbVh5xmXqvKN76XOp5J9qM9WbYyDiAflA+lNRFPwGUbGLzzEbvHAMV0dOiEdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705440622; c=relaxed/simple; bh=VfjDaVrNHIZjHx8ySkfQYoBgJn6qpwyh+qoBkvGRiD8=; h=DKIM-Signature:Received:From:To:Cc:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding:X-SA-Exim-Connect-IP:X-SA-Exim-Mail-From: X-Spam-Checker-Version:X-Spam-Level:X-Spam-Report:X-Spam-Status: Subject:X-SA-Exim-Version:X-SA-Exim-Scanned; b=a/kSOcGjAWbg9ICyN6qLyrz4hTOTOYmoks2AFIpyCDNg6D6vqYukbEugFsYI0itgVfHGLmyt5KJPw2mRB3MbHXhNDaX8z3d35hJH8lLh6a2JnEG2UXMGbK9/5nVNto/K2vMgVoR6rDT64bh0cJJIiF7QlUCAZS+sVoogQHBWCsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=JCRlSrLw; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="JCRlSrLw" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Cc:To :From:subject:date:message-id:reply-to; bh=zHExVb//VxV60TXMxheiwn+m4dfdcjotGwWrtMmqQZ4=; b=JCRlSrLwSFOwGc/wvvdiSsEEG5 TR3/2SvQE44rp7NbnUlEjtrfOgm8SvrAupSwFwEsHFX3RcGvyRIacR8wXhagRrdrg9xd7Ew6o7jQd FIqCThLemyawwXCxvwqnzHP5+TyvcCd9aJYOoASZveFDfE60eQH/HAugjNHXdscY4Ytw=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:47418 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1rPr0Y-0002ia-ML; Tue, 16 Jan 2024 16:30:08 -0500 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, jirislaby@kernel.org, jan.kundrat@cesnet.cz, shc_work@mail.ru Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve , stable@vger.kernel.org Date: Tue, 16 Jan 2024 16:29:59 -0500 Message-Id: <20240116213001.3691629-3-hugo@hugovil.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240116213001.3691629-1-hugo@hugovil.com> References: <20240116213001.3691629-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Level: X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * -0.0 T_SCC_BODY_TEXT_LINE No description available. Subject: [PATCH 2/4] serial: max310x: improve crystal stable clock detection X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) From: Hugo Villeneuve Some people are seeing a warning similar to this when using a crystal: max310x 11-006c: clock is not stable yet The datasheet doesn't mention the maximum time to wait for the clock to be stable when using a crystal, and it seems that the 10ms delay in the driver is not always sufficient. Jan Kundr=C3=A1t reported that it took three tries (each separated by 10ms)= to get a stable clock. Modify behavior to check stable clock ready bit multiple times (20), and waiting 10ms between each try. Note: the first draft of the driver originally used a 50ms delay, without checking the clock stable bit. Then a loop with 1000 retries was implemented, each time reading the clock stable bit. Fixes: 4cf9a888fd3c ("serial: max310x: Check the clock readiness") Cc: Suggested-by: Jan Kundr=C3=A1t Link: https://www.spinics.net/lists/linux-serial/msg35773.html Link: https://lore.kernel.org/all/20240110174015.6f20195fde08e5c9e64e5675@h= ugovil.com/raw Link: https://github.com/boundarydevices/linux/commit/e5dfe3e4a751392515d78= 051973190301a37ca9a Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/max310x.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index b2c753ba9cbf..c0eb0615d945 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -237,6 +237,10 @@ #define MAX310x_REV_MASK (0xf8) #define MAX310X_WRITE_BIT 0x80 =20 +/* Crystal-related definitions */ +#define MAX310X_XTAL_WAIT_RETRIES 20 /* Number of retries */ +#define MAX310X_XTAL_WAIT_DELAY_MS 10 /* Delay between retries */ + /* MAX3107 specific */ #define MAX3107_REV_ID (0xa0) =20 @@ -641,12 +645,19 @@ static u32 max310x_set_ref_clk(struct device *dev, st= ruct max310x_port *s, =20 /* Wait for crystal */ if (xtal) { - unsigned int val =3D 0; - msleep(10); - regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &val); - if (!(val & MAX310X_STS_CLKREADY_BIT)) { + bool stable =3D false; + unsigned int try =3D 0, val =3D 0; + + do { + msleep(MAX310X_XTAL_WAIT_DELAY_MS); + regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &val); + + if (val & MAX310X_STS_CLKREADY_BIT) + stable =3D true; + } while (!stable && (++try < MAX310X_XTAL_WAIT_RETRIES)); + + if (!stable) dev_warn(dev, "clock is not stable yet\n"); - } } =20 return bestfreq; --=20 2.39.2 From nobody Wed Dec 17 08:12:39 2025 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 507385D8E7; Tue, 16 Jan 2024 21:30:21 +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=1705440622; cv=none; b=o5Qgv1ywjbDlt92MOPYH+abhPIRMkhTrSB9m2EHOmyIRm0Y2llkrte+3tUgob1IyS4d9lfLMcKQJRkYiJINsR8NAqpA4oXSBZZ77wd2FxZTs4XIk+U2fXaCK6BTogoHft6+gxiCip/dMA5V3mm8WrbjPx/ScEjCk9KWb2m6TywQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705440622; c=relaxed/simple; bh=qfWpiAZWc51PNON/7H4gWESdB83W8BeHuWuTrG4mWSQ=; h=DKIM-Signature:Received:From:To:Cc:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding:X-SA-Exim-Connect-IP:X-SA-Exim-Mail-From: X-Spam-Checker-Version:X-Spam-Level:X-Spam-Report:X-Spam-Status: Subject:X-SA-Exim-Version:X-SA-Exim-Scanned; b=iGSoREPnSaNFOjOlDdcg5To47DFGY226BZh7bpovDSBkRFzXhb7F2ShfVcWSXWek1iEIgoXYRNNL5YLhgVJD6PsI88euQTmKDP/wSsSqJcDTbpTOG36t0trFzv3VBTaBLpzvgHgREqiYongouA5Ck/AM4qCpKQRMxE8/w22PO5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=ypT7x83j; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="ypT7x83j" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Cc:To :From:subject:date:message-id:reply-to; bh=dp5Cc9ruebVIkKrRs2yItMyH2vpyeqAmCbQfPwWXZXw=; b=ypT7x83jAEpsRMTAiRnVOhqYKw yrOVI7qwCjA3yBjLVbS/c514cGcZUwcDzerrKCjTml9uEdyl9i1AYlKGwDpyL+sqUNPv9NmOGBeqv eamXxzwmF9mxfOc0oXPJormSmROgvHCgOz43aIpXDjtwKGWotP7M4NcPmdkbxv+LXb5o=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:47418 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1rPr0b-0002ia-B1; Tue, 16 Jan 2024 16:30:10 -0500 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, jirislaby@kernel.org, jan.kundrat@cesnet.cz, shc_work@mail.ru Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve , stable@vger.kernel.org Date: Tue, 16 Jan 2024 16:30:00 -0500 Message-Id: <20240116213001.3691629-4-hugo@hugovil.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240116213001.3691629-1-hugo@hugovil.com> References: <20240116213001.3691629-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Level: X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * -0.0 T_SCC_BODY_TEXT_LINE No description available. Subject: [PATCH 3/4] serial: max310x: fail probe if clock crystal is unstable X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) From: Hugo Villeneuve A stable clock is really required in order to use this UART, so log an error message and bail out if the chip reports that the clock is not stable. Fixes: 4cf9a888fd3c ("serial: max310x: Check the clock readiness") Cc: Suggested-by: Jan Kundr=C3=A1t Link: https://www.spinics.net/lists/linux-serial/msg35773.html Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/max310x.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index c0eb0615d945..552e153a24e0 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -587,7 +587,7 @@ static int max310x_update_best_err(unsigned long f, lon= g *besterr) return 1; } =20 -static u32 max310x_set_ref_clk(struct device *dev, struct max310x_port *s, +static s32 max310x_set_ref_clk(struct device *dev, struct max310x_port *s, unsigned long freq, bool xtal) { unsigned int div, clksrc, pllcfg =3D 0; @@ -657,7 +657,8 @@ static u32 max310x_set_ref_clk(struct device *dev, stru= ct max310x_port *s, } while (!stable && (++try < MAX310X_XTAL_WAIT_RETRIES)); =20 if (!stable) - dev_warn(dev, "clock is not stable yet\n"); + return dev_err_probe(dev, -EAGAIN, + "clock is not stable\n"); } =20 return bestfreq; @@ -1282,7 +1283,7 @@ static int max310x_probe(struct device *dev, const st= ruct max310x_devtype *devty { int i, ret, fmin, fmax, freq; struct max310x_port *s; - u32 uartclk =3D 0; + s32 uartclk =3D 0; bool xtal; =20 for (i =3D 0; i < devtype->nr; i++) @@ -1360,6 +1361,11 @@ static int max310x_probe(struct device *dev, const s= truct max310x_devtype *devty } =20 uartclk =3D max310x_set_ref_clk(dev, s, freq, xtal); + if (uartclk < 0) { + ret =3D uartclk; + goto out_uart; + } + dev_dbg(dev, "Reference clock set to %i Hz\n", uartclk); =20 for (i =3D 0; i < devtype->nr; i++) { --=20 2.39.2 From nobody Wed Dec 17 08:12:39 2025 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 8BFE95D8F1; Tue, 16 Jan 2024 21:30:21 +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=1705440623; cv=none; b=daSwaaNY0EzbWz0u99kVyfQPftSKNaX5AIiJM8aIK8OOdj73EDTlWemyM2gqJHSp9RL0QysxH/Vqn8eZWMWkuLjhZzHrwCYIbEw5ECxkqRFOjFXT57Qb2496ggrqPn2uayLz6csY+ao0dk9McSOQYYmMWSpbsza9faIi2/nvkDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705440623; c=relaxed/simple; bh=Ekm1pWojkGVN85gQNWE1XXW2dWBTUCiXzPsg832oXl4=; h=DKIM-Signature:Received:From:To:Cc:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: X-SA-Exim-Connect-IP:X-SA-Exim-Mail-From:X-Spam-Checker-Version: X-Spam-Level:X-Spam-Report:X-Spam-Status:Subject:X-SA-Exim-Version: X-SA-Exim-Scanned; b=Wp4KJUYKNg8KyLH1xxPlPXMDDj8Ut+kN/SxTeXjHAiDROADSUzRQepKdq439LZqN4NfiizPLkzoV1diDVuNCx1er4IWbvli4PqWPhX8cZmg0nJRMfIw61NTXYZ7L/YDM50HFmnpy00qxqr+mjlKy2PUx4wOhiUEN/do5OJrUshM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=iZCshsRW; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="iZCshsRW" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Cc:To :From:subject:date:message-id:reply-to; bh=99qxuCnYU+0nTighHkHeSz50qP2ibLYD2/rfjv4LZXY=; b=iZCshsRWGamXZd6WywC48e+8RC fbgHxn6qeLjqo0ZPMrNwzvbuzLpakbp6J+KwYRQqY9i+jHpx/wUeFwN/N+Caejoeaig5+6rMVhF6O PGhV4wv8qGHeJ+HYHr8J7DQXzpHVjSIbATqzUAuMOnhpK2FsvErq8F5jmU5HwWNWqlqE=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:47418 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1rPr0c-0002ia-K7; Tue, 16 Jan 2024 16:30:11 -0500 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, jirislaby@kernel.org, jan.kundrat@cesnet.cz, shc_work@mail.ru Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve , stable@vger.kernel.org Date: Tue, 16 Jan 2024 16:30:01 -0500 Message-Id: <20240116213001.3691629-5-hugo@hugovil.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240116213001.3691629-1-hugo@hugovil.com> References: <20240116213001.3691629-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-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Level: X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * -0.0 T_SCC_BODY_TEXT_LINE No description available. Subject: [PATCH 4/4] serial: max310x: prevent infinite while() loop in port startup X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) Content-Type: text/plain; charset="utf-8" From: Hugo Villeneuve If there is a problem after resetting a port, the do/while() loop that checks the default value of DIVLSB register may run forever and spam the I2C bus. Add a delay before each read of DIVLSB, and a maximum number of tries to prevent that situation from happening. Also fail probe if port reset is unsuccessful. Fixes: 10d8b34a4217 ("serial: max310x: Driver rework") Cc: Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/max310x.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index 552e153a24e0..10bf6d75bf9e 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -237,6 +237,10 @@ #define MAX310x_REV_MASK (0xf8) #define MAX310X_WRITE_BIT 0x80 =20 +/* Port startup definitions */ +#define MAX310X_PORT_STARTUP_WAIT_RETRIES 20 /* Number of retries */ +#define MAX310X_PORT_STARTUP_WAIT_DELAY_MS 10 /* Delay between retries */ + /* Crystal-related definitions */ #define MAX310X_XTAL_WAIT_RETRIES 20 /* Number of retries */ #define MAX310X_XTAL_WAIT_DELAY_MS 10 /* Delay between retries */ @@ -1346,6 +1350,9 @@ static int max310x_probe(struct device *dev, const st= ruct max310x_devtype *devty goto out_clk; =20 for (i =3D 0; i < devtype->nr; i++) { + bool started =3D false; + unsigned int try =3D 0, val =3D 0; + /* Reset port */ regmap_write(regmaps[i], MAX310X_MODE2_REG, MAX310X_MODE2_RST_BIT); @@ -1354,8 +1361,17 @@ static int max310x_probe(struct device *dev, const s= truct max310x_devtype *devty =20 /* Wait for port startup */ do { - regmap_read(regmaps[i], MAX310X_BRGDIVLSB_REG, &ret); - } while (ret !=3D 0x01); + msleep(MAX310X_PORT_STARTUP_WAIT_DELAY_MS); + regmap_read(regmaps[i], MAX310X_BRGDIVLSB_REG, &val); + + if (val =3D=3D 0x01) + started =3D true; + } while (!started && (++try < MAX310X_PORT_STARTUP_WAIT_RETRIES)); + + if (!started) { + ret =3D dev_err_probe(dev, -EAGAIN, "port reset failed\n"); + goto out_uart; + } =20 regmap_write(regmaps[i], MAX310X_MODE1_REG, devtype->mode1); } --=20 2.39.2