Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp1078016lqh; Fri, 29 Mar 2024 06:44:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVMG8b749nHmaApqnfHhc69OOrF2e78IQtkgFw4gak+RlH+07ZJK5sJgFMSMSmuj5RuVhTWnL/cZehwTEnpMGnMgDtQF7Fd1HgDVtIVJg== X-Google-Smtp-Source: AGHT+IF4GXOqEQgegnBzpmEiO2uklU74RvxOm1gRzMWPVTdX4Ht3Yi9U7GIQ4GpkdYcZ0AxuHeyp X-Received: by 2002:a05:6a00:1955:b0:6e6:9af4:409a with SMTP id s21-20020a056a00195500b006e69af4409amr2602154pfk.33.1711719842230; Fri, 29 Mar 2024 06:44:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711719842; cv=pass; d=google.com; s=arc-20160816; b=pEEiC7VyOyWHyx1iitxrYRpt1lVyZ78XmDmfn7mOANjx6f4J13YhTEd07vBYwSjk/a mWCQ20TZoKe4VeIE9DY17b3lj1mD1x2+aN6p7fG6814m6gj9HxMmmQLKeyYdTi0z2WUw I/RpDEDh4kXHIu4TV3BSWqtcx2FByYpiuVAB5oYZIzB9J4pJuR59D5we2sZG/086cMrf GT1gWsG/h/3wLftE3fjpyrDNgbDEzrB5sAHLVj+V5nnRWWr2is8RK7NYrF8MA1ErSp6a T4G45nbKRYf519NZMmQeb2nTpJn2C4RVz6MyESkm+76XXO3dfdfmSDQWZaPT+P3bNNzJ nThg== 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=7eQKwf0Z+/IU8P6FzXPXgNYGM69mSrUpyYay8JCX58M=; fh=vTG8Hrj85GyHwzdEf2Y9As8Rjt2PZdTSAYgqUAjkQ+0=; b=Pt5PZ0taX7cA5EkmpvT+Kpwqj0P8QKCT6v+YDu74SrglPjAkf2B/4FGcUavU8mF3/9 mwh6EXqf1Z58WsdzTDCv0SaXLWJMdW5uAeA2yWi5C6yxsnVa2yPYTpnFXLcpy7JTKoa+ 5w4/rxqEjgQfd28KpSH54LCaMlV8DezL+PGE/G21i84LOJVfQyy8MSRj/oE7cbntZaEl u/XkILfaSHWZIIUeswFPhzxi8fYWKRXb6cUURiY/l0hogDoStv7hVI7iiwmtuxHzYl5l bldhKMd+pkh6ekg84PPJw1N0KBaQZwFA5t11Qn3PH0UCgueyKdXun3U2vqVftmjjKJLb ktKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NrZKtPVt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124737-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124737-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 lb23-20020a056a004f1700b006e650049479si3672906pfb.96.2024.03.29.06.44.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 06:44:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124737-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=NrZKtPVt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124737-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124737-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 98A70283F0A for ; Fri, 29 Mar 2024 13:38:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44DB7179216; Fri, 29 Mar 2024 12:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NrZKtPVt" 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 67CA8179201; Fri, 29 Mar 2024 12:40:51 +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=1711716051; cv=none; b=fsIBZz3Dtmsw4jaB0IWZA5aUGD2FdnUfwYlajBFJKJd2414kp4sdOkktPk9mM1/N9KLnqmOIjv2LkgPqlD0MURF9CoJQJObMzNNjtnEV3xqP0yYgGynAd2ekm5y4w/zfQ08V1W9rCzWsA1ybSfyyg2xmrIRBtWQAFR4WUSv8nr4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716051; c=relaxed/simple; bh=uRO9hNSHchqspmCb1F6je6akXTN4Hy8qBEMg95DG9jg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MxpwZyMmtovYw7hVynB4z2n62Egex+M6Z/63D2tUSlcL3dPERQ8+ByUGS7MvUpdShV9J7rmkZQB5HCbzZ4dqPJ37WjP1jXaMJ7M5j+4MViWrO4pSU2088kIsUmehiM3Zsevpn2gedPTZLW3sS73qsdOThKmHmV1aaIzl1/E8Tec= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NrZKtPVt; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95DACC43390; Fri, 29 Mar 2024 12:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716051; bh=uRO9hNSHchqspmCb1F6je6akXTN4Hy8qBEMg95DG9jg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NrZKtPVtBxsI1CXM7WGuCkhix7O9SUgBdXFPSSxc0cTFh1+nJm+2RvxxChlUc0ct1 q2UvZyv2UNtrYBMz2ybacAxfrR3meAKJUl4+EaxJEQLbzIgbCw555SMumiHpwRC/Sb sTyysz5wmC0YDXiD6bEpftRrY4wEYF0ImWn74cKzxX5nmF3A9EpdSmdwKFdDzCovjD R5xc2ZtDLUHKvKgopKgX8d14QNHOzdF93mj+35Yfae8pSNahMsS51VQ70Cp4BK+u3e phahzODtPeGYVfv47i1tquE1CRDUAyV8R+RcOUZYeGXraW0qtE4g3A3ItuADBcWVat vjS0wA0QkFF7w== 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.8 28/98] cpuidle: Avoid potential overflow in integer multiplication Date: Fri, 29 Mar 2024 08:36:59 -0400 Message-ID: <20240329123919.3087149-28-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329123919.3087149-1-sashal@kernel.org> References: <20240329123919.3087149-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.8.2 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 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