From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 73741446A1 for ; Mon, 19 Feb 2024 18:21:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708366907; cv=none; b=ghDzVXo1gIDtCTTEMQj0g2jrQhkcjDAvZNzuLJdYVzTsdKkBhTW2yvfo+mpEpchGk5cZXvdUVYfF318aMvkMnbW7ZzDj15BR1hr6fnMaWxHV90+9HGm/4bFLPycPyXr5YhFY/U24t1WN5arDD3oz+HkHC/53f8MtMz8zD/EcIvQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708366907; c=relaxed/simple; bh=gKwXljfVk1hvgFiatrSq9tf11KMtWNZ5Kge5FLb3rFQ=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=DsE1tIaDrQQH7jhPMcpQN4mPql/+/5A1e2grA7BG/GPsuiNQJwY/S2XDQbh7hz77K9IRnZzKJOrThpH4R3r2dhyvUq+3tzB8Ned6E+Siqhrb/INzVLz9X+BJkd2T1YdPE6Y86lcSHE6pPSoC/i+WwFT/1amO5NfDTWKuuBukm6g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vCraqmDe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vCraqmDe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4C3CC433F1; Mon, 19 Feb 2024 18:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708366907; bh=gKwXljfVk1hvgFiatrSq9tf11KMtWNZ5Kge5FLb3rFQ=; h=Subject:To:Cc:From:Date:From; b=vCraqmDeOHGcJWuWVKjOgCJl4np34hg1yl5pzK79tuUaTzh5HxflWCER52N7ckCMu 4TERu8XBSk8I34Ccj1X6Epyfo1bNJgk18Su+Jo/kOEDjmwE7XYVkQ2Ghrg+Rnx0oQW rdOXtAW8NRnH3EhE+RGZAMqL28jeFaasZiRjKFyQ= Subject: FAILED: patch "[PATCH] serial: max310x: prevent infinite while() loop in port" failed to apply to 4.19-stable tree To: hvilleneuve@dimonoff.com,gregkh@linuxfoundation.org Cc: From: Date: Mon, 19 Feb 2024 19:21:31 +0100 Message-ID: <2024021931-frisbee-commence-08ec@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 4.19-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-4.19.y git checkout FETCH_HEAD git cherry-pick -x b35f8dbbce818b02c730dc85133dc7754266e084 # git commit -s git send-email --to '' --in-reply-to '2024021931-frisbee-commence-08ec@gregkh' --subject-prefix 'PATCH 4.19.y' HEAD^.. Possible dependencies: b35f8dbbce81 ("serial: max310x: prevent infinite while() loop in port startup") 93cd256ab224 ("serial: max310x: improve crystal stable clock detection") 0419373333c2 ("serial: max310x: set default value when reading clock ready bit") 6ef281daf020 ("serial: max310x: use a separate regmap for each port") 285e76fc049c ("serial: max310x: use regmap methods for SPI batch operations") c808fab604ca ("serial: max310x: Make use of device properties") b7382c73b2d7 ("tty: max310x: Don't pass stacked buffers to SPI") 3a10e3dd52e8 ("serial: max310x: Fix to avoid potential NULL pointer dereference") f233ea4327d7 ("serial: max310x: Correction of the initial setting of the MODE1 bits for various supported ICs.") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From b35f8dbbce818b02c730dc85133dc7754266e084 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Tue, 16 Jan 2024 16:30:01 -0500 Subject: [PATCH] serial: max310x: prevent infinite while() loop in port startup 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: stable@vger.kernel.org Signed-off-by: Hugo Villeneuve Link: https://lore.kernel.org/r/20240116213001.3691629-5-hugo@hugovil.com Signed-off-by: Greg Kroah-Hartman 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 +/* 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 struct max310x_devtype *devty goto out_clk; for (i = 0; i < devtype->nr; i++) { + bool started = false; + unsigned int try = 0, val = 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 struct max310x_devtype *devty /* Wait for port startup */ do { - regmap_read(regmaps[i], MAX310X_BRGDIVLSB_REG, &ret); - } while (ret != 0x01); + msleep(MAX310X_PORT_STARTUP_WAIT_DELAY_MS); + regmap_read(regmaps[i], MAX310X_BRGDIVLSB_REG, &val); + + if (val == 0x01) + started = true; + } while (!started && (++try < MAX310X_PORT_STARTUP_WAIT_RETRIES)); + + if (!started) { + ret = dev_err_probe(dev, -EAGAIN, "port reset failed\n"); + goto out_uart; + } regmap_write(regmaps[i], MAX310X_MODE1_REG, devtype->mode1); }