Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3988423rwb; Sun, 9 Oct 2022 15:23:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6U5t6uO97Y+J4rO8c1jNFgZnolwcMD3PXO40D38RsoIpGMVuGQbxH7Z/9RFCCf4r8/s7pP X-Received: by 2002:aa7:ce02:0:b0:459:4833:380a with SMTP id d2-20020aa7ce02000000b004594833380amr15144985edv.359.1665354202734; Sun, 09 Oct 2022 15:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665354202; cv=none; d=google.com; s=arc-20160816; b=QBRCtDqGYFLSMWqUAnTPbPKnqYq33XPcDK7FTVqHJOH65r8LzfSpR40/PAhMgtu2EI lqDyueKCZTv51eaKKuNvyWPrir/oo6RJpgbRSkEtWHj/8674dGJXcsv5z7nJC1wdv0uk P0rEutYoTlW5u35t//D2lDWsEWCUlixY/A+Vt+voI62mUHPDtTssytgFJpEWijOMdWau LYEFsCoELvOWXbY/9zC+h9qaT8pYOkJczScH1WxRUhCJb2sWyD9ucjLR2VSHkhLQADMq hAoN2cg6mAP1D2JKH4Bisl7DvvI9Xh1ZEkXWmyVIf+DB8/cGVkiRviBuHxqNZc6hX86F b7TQ== 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=j54LxoE0bbC3aDOjIHAmzD1Sy1EUsR1wlh666B/z1+U=; b=Kw94Q6T7ppx1DRHDw8YXli88QWAsRzODu/oMD9RAgDIN8EOSdGjj+vb+ZJ8B3wpQZo pdJqWysToOvDrCIy6yKU3wtKpIay8BMTSg7vtZtu7X+AVqFXRynJNY31rcuwAqAgQGI0 mMNP8PHHf206N2KXeKkG/bBaUInO5C2I2McfcmmcHbKvCXd6hS/DaRiovNqTmsABZi4p wmKZeUCqngTCJ99GAO4b70LEvYZqHzP2mBta7GkUIsZWR4MRyNhHhNxxlzOqYVmBfYFM //pkd/u+dWdA4EuY3C5y138L5JJBPg2qZqVzo1l26PQCOrz9hsRHyBxkYmlT9Kj1uv5u q5ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kf8M1s2Q; 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 cx17-20020a05640222b100b00458fd857c9esi7124751edb.381.2022.10.09.15.22.56; Sun, 09 Oct 2022 15:23:22 -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=kf8M1s2Q; 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 S231577AbiJIWUk (ORCPT + 99 others); Sun, 9 Oct 2022 18:20:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231820AbiJIWT1 (ORCPT ); Sun, 9 Oct 2022 18:19:27 -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 D35533CBD2; Sun, 9 Oct 2022 15:16:39 -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 1F5C3B80DDC; Sun, 9 Oct 2022 22:10:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F485C433B5; Sun, 9 Oct 2022 22:10:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665353454; bh=7+9iLh8rQ4HHyOSIN1Pqo+gNYTzhMkFpZiwMptBxaMw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kf8M1s2QSpVqLGB8ksUz/OHQIstUakTC0kvGdXAvdbxKLuHpbzokMEzJ7PsF0C6et u2v4KDqA60ERmQcPzf/N84o7n1Mz9kCNIZVorJ8CfJSMEpPdki0ztB3OxHytvGgR/t LYzAFJH1RhoFeShKOTsGteUW5PyOwvIQYvr/xmP+DNpE4HM6cETPUP18yQJKoBxtFe v4+XOJtIGrRmpaafVE/RzPBrZKLEgTlwCpHZ+viPy+2IugqzX4lxk2M2V5RxwELeq4 hFk7KUgZ1dpqpU/rki1pdnWuX1ZoUKjGItxH9xK5ky4vgFqTYloXayWdxAtu68vDT4 wI5oiDzy3LCoQ== 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 6.0 39/77] regulator: core: Prevent integer underflow Date: Sun, 9 Oct 2022 18:07:16 -0400 Message-Id: <20221009220754.1214186-39-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009220754.1214186-1-sashal@kernel.org> References: <20221009220754.1214186-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 d3e8dc32832d..c3871565fd7d 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2681,7 +2681,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