Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp19743lqz; Fri, 29 Mar 2024 07:21:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWN/V5oCQ8xhBOFCqgjIFRmUbZhJPWPqm8n5rjZTFIwjdC9LFGV10jESMCKLqs+mTOqr1EtP960Of5Dubc4f/naE8hH7PBPcRRohmdfow== X-Google-Smtp-Source: AGHT+IEQw8/69kSggQBtF0MmKiA8xo7mylOH0d7o8+7IC9xKGhD8Jybht7gs2lll3h2qdKp6JpPy X-Received: by 2002:a05:6358:5294:b0:17f:58a1:12ef with SMTP id g20-20020a056358529400b0017f58a112efmr3148513rwa.4.1711722085263; Fri, 29 Mar 2024 07:21:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711722085; cv=pass; d=google.com; s=arc-20160816; b=YgBxyTnfu61H6BNopE1EBLHyqVYCfJslppzPENYEIwKdv8HLsQGsPlH1W7fOBthvcr EbeVC2Mh3JWrQQNLHhU+S/C0xVz9htfauO2e3Fgz/YGpn599yU1J0x5r7NEOYxm3NN3t NAmpGDcoBO67AxwpsqH+7HXQfuw20QHEAcDUscuEd/vg81mR9Lv0EAXkQEmvmqoFWpjR o33UqpsT6165VCkU8a+KzODMYLdqYkYcoDYsgHoNcinnQ67PCDWeWu921B3yiBvUXvKf qIKAxrwd0lQ1PxO78+UyEQYXDL2lcr9xX788yXrdACQVxLRs/1AUw9JVhCNde81CY/Es Nkvg== 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=pwS1ON/JJah49cVCqcFkCazDcULif+FnoEQQ3ZD7xPM=; fh=vTG8Hrj85GyHwzdEf2Y9As8Rjt2PZdTSAYgqUAjkQ+0=; b=TMYcLWtI4jLKDLxUaihlsNOwE4RJhwnQ2sXUZSJV4kyFV69lp1LHd2vYKTWMDN21Mj 4tvpZJ54gW+zmSMiKUusaCFMz2mGbuF6xc2nY7Z+t17JsDKooHr/cUSyF0zXxfTuG0Zx K0dWSU3DrsNT3maItpz6V3+Oj0LP5WWLwDtGuwP6HwiUPu/jDG4LDfMIld204L1iJgYp 3eD+sVgvDArpJYQCPY7JA4jzh25i3Pa3rpPTkAz4G31KrI+nbtD+kBBsm8h3ansVCe3W y2sucHbTXBaj7mnZFB9HpwE+6H+1v8UBGbW2rYEGlzfQnCHcCbQ96f5sF2UaI8awTqhd 5aOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sLLRPfom; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124898-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124898-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e14-20020a65648e000000b005f05de51489si3576438pgv.440.2024.03.29.07.21.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 07:21:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124898-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sLLRPfom; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124898-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124898-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 E401A2830F0 for ; Fri, 29 Mar 2024 14:21:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D25E238183; Fri, 29 Mar 2024 12:46:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sLLRPfom" 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 A182B14B08A; Fri, 29 Mar 2024 12:46:30 +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=1711716390; cv=none; b=I2a/Ux+42jRTmpsascIZ820KvcUUlVASmV5EgLfh1I5kkCqtjBKNhFG9pRJdL3Ev7se6orELViOIWCbpVyULOd1sNTdsIf8fWf5NPkyCqdKyjN8k4fLTjLlH0QLw2F5a6n0F9syBlIsxy9VJoq9UpupgMUBCwjT7mlzWGVPLMyU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716390; c=relaxed/simple; bh=Kx+1H+QtnuCB8ciX29fyhB79zT4Lxwy5pONlNfKxAiY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W1hkYimQFEmIAEpk9MdX0X4+JK1V/jOvljmcJBu1E02FrxFBikOs35dIKzuVhFqvSnGmaqt4uBvVjOx9ighAVd/z5qqrQDXrRQukHmnlnayqCyfGwVU3UZLylVSC3Rn4Y4FVJvqLqLvAyJLbyajDWs/KBa91DhQwjzhwX1PUFsM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sLLRPfom; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2963EC433C7; Fri, 29 Mar 2024 12:46:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716390; bh=Kx+1H+QtnuCB8ciX29fyhB79zT4Lxwy5pONlNfKxAiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sLLRPfomblxWnL5E8qu46AJV+9GDc72gVoeF7+a7nr8txIB2Yx7pQEKiudlo/IIen 03jmk9Ws8E5CEsMqpaJtIe2nAEYYJFk4BOCisHENYNHQsx3NlMQ3DEVYnzd2fd6G1R HEjkOjB9wK20w0iHUmB4Bg0nPJ4DnUVY0LZM9wMkaJFzH8392K0XypK51K7ErWCB0m syFs8kn5l7PZ3ZTp+Z0EhgnDJmwPgr+qyfFC504zNnF3+SOH8IXDvvBjDC0pRlXjDZ 820BrgWqvVk0KXaNkZBRyHyG5JnoP91toMOttPmHhNOpuDLv/4KpfJ8GqEyqC8GGa5 ffKdNLBFx+J3g== 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.1 14/52] cpuidle: Avoid potential overflow in integer multiplication Date: Fri, 29 Mar 2024 08:45:08 -0400 Message-ID: <20240329124605.3091273-14-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329124605.3091273-1-sashal@kernel.org> References: <20240329124605.3091273-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-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.83 Content-Transfer-Encoding: 8bit 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 f70aa17e2a8e0..c594e28adddf3 100644 --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "cpuidle.h" @@ -185,7 +186,7 @@ static void __cpuidle_driver_init(struct cpuidle_driver *drv) s->target_residency_ns = 0; 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; } -- 2.43.0