Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1878677lql; Wed, 13 Mar 2024 10:33:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW82GcCjnwiXBAIwO1ARImR1wFWMJoHWJJUHVquTRAPg/ZOFgyc1/NnC35EqJiW3fnQN5wpSWKf+gwm3r9sjeIiGMe3/yJg/E4nNmULQw== X-Google-Smtp-Source: AGHT+IE/0eifj1/wcNbIauUOA/w93ZsmNbsgYGaO6dvsRn68dtP9HvEN3CwJjAyIcjL0HG17V41f X-Received: by 2002:a17:903:2283:b0:1dd:8ff9:40b1 with SMTP id b3-20020a170903228300b001dd8ff940b1mr4952863plh.59.1710351220625; Wed, 13 Mar 2024 10:33:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710351220; cv=pass; d=google.com; s=arc-20160816; b=QqfwI+heYqoNWsU6KySho0UWgPpW5NEiYwS+kd6OkLt1pTF5zlJ2Bb8llP8VBj3Shn dAAJnEfkXrAPTyBiNbH7pFC1NGEU9V1G95QY1lQHbu9ua5lQ9QEEGkedfR+85jI8syUq nxveYUQjmfq+8inrsWb3/+sK7P3FLNyLeHgWqIByY10NYNceCRVLHwbybyRsgmUAbNZS pYh+yEWPiFudEN/DrQ56+qymVrkiCMH0qvouucc7JWcopLD1u1hiEkRt6UaEdzXjxw2p AOyR1JoAc5vZpBu9Io5GQiHOdmwcOkmBCf119SAFKCwCaNdVvLSrQn6/oN/Q+amWwcSH UXBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=wvquNXfgFFg/E+vxIATvrS+wrLfbHC/on2OcnTKmuC8=; fh=GXXPxb05ZPditWdice/wA45B8vHPf8gD2inLfB6RkR8=; b=aOULqsyfLP0MYuJbRXh4xlftfRrjf7Qah66dfJWj+wcrj01Cz6aKSVqB95WWR7aP2O PpdIQPQPzl1quNmE8JHgbBXOikTYe8uIya7oowZ+eirRCLzXU6jeZA7uh3cmYZn9xaxJ KfJlssLXdn8uuN2/bWS+4e7gk8A58ouJhyAZ+4k8Fq2+ebuKIG5T68VIod9msgtqG2E0 +v1hp5bQc8MsLf4ARUTkk9picdevB+cRoq0ZRQgW+JoBjFm3dknN0ggk4GPuGMiySTqn BoNOw3cHxPY2GOzVArcwHRuL1JE8J9kwFFIF/J4+2aYoVgzmQt+Sq5MZkEQfhFmJb7WW cEtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RfQX2Qdo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101990-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101990-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q13-20020a170902c9cd00b001dd04d1f3afsi9048563pld.516.2024.03.13.10.33.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:33:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101990-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RfQX2Qdo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101990-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101990-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 918092818DA for ; Wed, 13 Mar 2024 17:33:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7383149396; Wed, 13 Mar 2024 16:43:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RfQX2Qdo" 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 D6344149019; Wed, 13 Mar 2024 16:43:21 +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=1710348201; cv=none; b=r6VAkfG8KpZvUNP4xCdEzzfM9Vx/1rc7QDBR/E6b81AVUYxyHyeX8P+hbyjMF9ppZbtN15EXw5X1GznqN4Ml3iKTpb+Ec4j/2v3JAnIO/E9RFx6BXdw36Gdw47Qfl4CV49GOv8UPi3vCOil8771sDalQMP9NhlFyLYAzRwthvR4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348201; c=relaxed/simple; bh=E+O2824pnAebbyG8An1Pn9KJS1r4lPV+GKukQp0+tR4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qzo6Go7FwAKUNCvtAoH/+9y86KAr+jq6T7oQB8mofHwIuZadhir/5Gb118ZCbe4UN0V5XxP5IQKajomRPHSmOwpDVUo0K+infoLSDWpDPvaRdWTyDDheqkwsa5nk1uM0xh/nfXfBxQMLYUjicfFx4ZyEFCMtXfoEqRSP686ZRLg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RfQX2Qdo; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07CF4C433F1; Wed, 13 Mar 2024 16:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710348201; bh=E+O2824pnAebbyG8An1Pn9KJS1r4lPV+GKukQp0+tR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RfQX2Qdor89Ccr7z4rO+ILZB74KkMWL2jzSgQ9tuyphUDng4EsGjOiapl8C8qoA8k /JaObncRMoXf1FADuXKWwhqDa4ELbcfgt1lHxtXX78dYf+ACleuvBeW/Nct/KfmXMq 4SPu+9LLgV61n3vXqA4Z20cobKg5DkMN/r0D6Sben5yigC0juf5yleKCXTL6ckmAsc mbMzNOTkqHrErG9kbf+RHmETbPBkwtdUhMvjv8w45nwoajjvXqcsxTe8/LHT+dh7xZ f3TOKuCaMtBntNItZNvYFuRgz8sM3PoHHIwQw3gXZ7hyGEBiEaYKvQCE8KLnMfLcwy 2Klz3aqWSXd4g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hugo Villeneuve , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 5.15 50/76] serial: max310x: prevent infinite while() loop in port startup Date: Wed, 13 Mar 2024 12:41:57 -0400 Message-ID: <20240313164223.615640-51-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313164223.615640-1-sashal@kernel.org> References: <20240313164223.615640-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.152-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.15.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.15.152-rc1 X-KernelTest-Deadline: 2024-03-15T16:42+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Hugo Villeneuve [ Upstream commit b35f8dbbce818b02c730dc85133dc7754266e084 ] 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 Signed-off-by: Sasha Levin --- 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 d61e8a6bc99dd..41251fdf7c845 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -235,6 +235,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 */ @@ -1312,6 +1316,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); @@ -1320,8 +1327,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); } -- 2.43.0