From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CADB6C6FD1F for ; Fri, 29 Mar 2024 12:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=T6AkJWzPSdYnBgQ37LcxnW53LRpzi2FnwepwUHS6R0o=; b=aEvCgpcgqr13Cz 54mRbm1XaTeMsjB+dmc1YZhsO5zPLH9s6jlxccMrtx9uyuZK1m5uhO0IN6ZWevWci/CmTxQxxfFfE 2UlaSv4SKNrb7sx98z2hZSnVSjQ6HiMfe5aC+LOxqSsqxHHhQXhyvwxBJb903s9Xu67zB2x30Neps Ev34kbztvwUiLlZ/i+4cRvy3+VAtO6hzEsav+bv/OUpHI6Xzw3Q+bhifXvsJal04+acw4Bs5HEcqy v5PzNlZDx8UfVmO010pE7cqYLqXsiaaMeyWlapnSJXzn7I4fdEXBpabt67eqeAUd+pg5aUMBUFcRu yHj34vBrLjWiQ3lBxmCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rqBcN-00000000Rx0-18Y0; Fri, 29 Mar 2024 12:45:59 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rqBaY-00000000R8X-21WD; Fri, 29 Mar 2024 12:44:10 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id CEA96CE2F9E; Fri, 29 Mar 2024 12:44:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B417DC43390; Fri, 29 Mar 2024 12:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716243; bh=uRO9hNSHchqspmCb1F6je6akXTN4Hy8qBEMg95DG9jg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EJQEsp6oISBucig7g+0diMfjpNLFzX1OYjSonZmhrMT0pzLYGa9hL2nzJ9zAY/eoq lGoFw/BSdtDyKj2Ysef1jOWyBY+lckjc8yoi2PcallQOIQYTX0/YW2lToESRJOgyMH lYw7AA7TU8elRVnnr8p8HlHmw9aVA8GQvEAmAeFitjCzOIUT2yTucgj0ZiqLQP1v++ xpxqgMitQ4jYTpakLOEyBnBvdH1UuRBeAyDGhiHoezpw0e6S1qQz2SbQYKg2RZUF+/ 1toAtbTQMKG9OAwNaJXPVehLWyUYvzUx7Sl4h0C2yqU+8pdRe6BemJmUxP0txNrrQ6 M89ILP7PQWK6g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: C Cheng , Bo Ye , AngeloGioacchino Del Regno , "Rafael J . Wysocki" , Sasha Levin , rafael@kernel.org, daniel.lezcano@linaro.org, matthias.bgg@gmail.com, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH AUTOSEL 6.6 18/75] cpuidle: Avoid potential overflow in integer multiplication Date: Fri, 29 Mar 2024 08:41:59 -0400 Message-ID: <20240329124330.3089520-18-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329124330.3089520-1-sashal@kernel.org> References: <20240329124330.3089520-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.23 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240329_054407_531750_A399A191 X-CRM114-Status: GOOD ( 13.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: C Cheng [ Upstream commit 88390dd788db485912ee7f9a8d3d56fc5265d52f ] In detail: In C language, when you perform a multiplication operation, if both operands are of int type, the multiplication operation is performed on the int type, and then the result is converted to the target type. This means that if the product of int type multiplication exceeds the range that int type can represent, an overflow will occur even if you store the result in a variable of int64_t type. For a multiplication of two int values, it is better to use mul_u32_u32() rather than s->exit_latency_ns = s->exit_latency * NSEC_PER_USEC to avoid potential overflow happenning. Signed-off-by: C Cheng Signed-off-by: Bo Ye Reviewed-by: AngeloGioacchino Del Regno [ rjw: New subject ] Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/cpuidle/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c index d9cda7f6ccb98..cf5873cc45dc8 100644 --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "cpuidle.h" @@ -187,7 +188,7 @@ static void __cpuidle_driver_init(struct cpuidle_driver *drv) s->target_residency = div_u64(s->target_residency_ns, NSEC_PER_USEC); if (s->exit_latency > 0) - s->exit_latency_ns = s->exit_latency * NSEC_PER_USEC; + s->exit_latency_ns = mul_u32_u32(s->exit_latency, NSEC_PER_USEC); else if (s->exit_latency_ns < 0) s->exit_latency_ns = 0; else -- 2.43.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel