Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4055870rwb; Sun, 9 Oct 2022 17:00:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM59qEWoxFrHx39R8TRNNIalVFn0NJqEVdSABuqAONsDMtspBwfCS/NJlFCNXeZO0ZodNyId X-Received: by 2002:a17:90b:1d8c:b0:20d:3180:3e8a with SMTP id pf12-20020a17090b1d8c00b0020d31803e8amr5234205pjb.68.1665360004030; Sun, 09 Oct 2022 17:00:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665360004; cv=none; d=google.com; s=arc-20160816; b=EkmUl5N+M8WVh2lzrQbYTruqr7AOWsERotyCqPnpJu1IuNic0m87vl+BxulPfzZjyg 4uFdOHRL+sty33cwv+unChlZnV9DBag7q+R/zDOhqOI4Mc4LyQa3z0hy+USyDcZDDgQk GAhO6A2tX6bQ75jilf9w5lfpBh8VTYgbsigQS/l99zZoZ0x1Pts9msVBzpgod50vdllf Z+aMpO+g4saC2AOOsg3myFbCrPDJYoW0XH5qiphU1x/XsWPoysDp5rkOaO+hfV2fA83i DVjcdCN7IEnOjPFPICsugH33HfIYX9kqmKUqRDzWcKwChe14I7HV2fxqHOOTc9hOysy2 xQKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MS1/oJx9VSDkkg70x51KWEtO7x7lndaVvIDnXsbp9s0=; b=S1fmbE8KNJHxdIBGQnYct55jHfhWZomZSzqw7oZa9NE3ocbgdN6xAnd7X2lbTtQxF+ K/+boYPegZRbYBqQSelnMo9itlqcA2LOpROmyENisXrJc8vrfdfHkg/9woPcjRK7vhm9 E8SqMl4K014YY3CkSeXc3ae2H2V54DIb3S3mzTk+O4kqkganvIvlrm0Uz8BZaggp+Dk8 OzUuFCErTf6SRxAIdvh+4hFa94fOOfIyeNRoE7MdBvjznxunJbw8hIQVl2kE1+8ZPDAr XkS/N2+NMc83Hfar8Ozj3ZlKXJNQmhXPfaTEVQ5VVSHkjpbUVcgjTF7VbwR7OEJX4cqI raEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YPVcpICM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a170902f30500b00176db576db9si7930869ple.275.2022.10.09.16.59.48; Sun, 09 Oct 2022 17:00:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YPVcpICM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232185AbiJIW2W (ORCPT + 99 others); Sun, 9 Oct 2022 18:28:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231933AbiJIW0C (ORCPT ); Sun, 9 Oct 2022 18:26:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F421A3DBF2; Sun, 9 Oct 2022 15:18:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D6577B80E07; Sun, 9 Oct 2022 22:17:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E89BCC433D6; Sun, 9 Oct 2022 22:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665353837; bh=e69ynLJuqC7qhUEJrETi/PJwrTuWrNPBE7bGAuEbq7s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YPVcpICMDhDg7kyqFYyfs5MEwip1H7kk/euv8Y16PdoXwv6+7EJ0wVVg8YN2XIqgK cBvzLMXftlgGHV33QsysdMXZoDYNHEK2ZdokwEaJkLIxdIyj+4C8KTeR2YvsFOuL/G //8ZUPjTc8P5vLKAbDLx6cRkI5fJUORxfkG/GSaGVvE3j/JEo1U0wdYoqDH14K2Xdy 1TqG8IW1yLWwJtQh+pmiErXhOQwztjpCNCyZMRAdT0T4/60kcXfLtY10oTnTuo/OXC +A5xlQDkvDCU2CTTH0rmaBjbrDzbZjV2ANjJPPjOqSW5VcRwhEujYROHXAhTsGWg5B zWvrTeZdgMSzg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Patrick Rudolph , Mark Brown , Sasha Levin , lgirdwood@gmail.com Subject: [PATCH AUTOSEL 5.19 36/73] regulator: core: Prevent integer underflow Date: Sun, 9 Oct 2022 18:14:14 -0400 Message-Id: <20221009221453.1216158-36-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009221453.1216158-1-sashal@kernel.org> References: <20221009221453.1216158-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Patrick Rudolph [ Upstream commit 8d8e16592022c9650df8aedfe6552ed478d7135b ] By using a ratio of delay to poll_enabled_time that is not integer time_remaining underflows and does not exit the loop as expected. As delay could be derived from DT and poll_enabled_time is defined in the driver this can easily happen. Use a signed iterator to make sure that the loop exits once the remaining time is negative. Signed-off-by: Patrick Rudolph Link: https://lore.kernel.org/r/20220909125954.577669-1-patrick.rudolph@9elements.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/regulator/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index a9daaf4d5aaa..9567d2fc3f00 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2680,7 +2680,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev) * return -ETIMEDOUT. */ if (rdev->desc->poll_enabled_time) { - unsigned int time_remaining = delay; + int time_remaining = delay; while (time_remaining > 0) { _regulator_delay_helper(rdev->desc->poll_enabled_time); -- 2.35.1