Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp6405lqz; Fri, 29 Mar 2024 07:02:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUkbvnK0/8xXO0dS6vOaCVvKZ7AoLuXg+LBfTG0VirM9Vf44H4kJUFr8YJH3kbvcJJxgAyMM72Qpvx2pjwCRIriuBsd/m6mlCmk7DUV1w== X-Google-Smtp-Source: AGHT+IEtqXWzZ3F5Bo4EgBMDJvA2azkXpkTOkwJA1iqI3cPsnV2uue6U4qkTsWTekOFQR4q0pBtJ X-Received: by 2002:a05:620a:3901:b0:787:f9ba:1d5b with SMTP id qr1-20020a05620a390100b00787f9ba1d5bmr3001248qkn.19.1711720949262; Fri, 29 Mar 2024 07:02:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711720949; cv=pass; d=google.com; s=arc-20160816; b=SgTmkCfkaXzwJduzptkhTsO23p/PYeGQi/ZhfODHf58XPjNGgTurY4szF7FlrlgBeu 9aslTei9drNRDN2YKGh2ORaVFntJxHJx7aPIRMtz/gdNZ/R/Kr+krDUutXexb2GBifNu 2Cjs3t1N23tb9VF9YZbDVkabVWflh/MFDxm6v7etCK6p9ramXvGTyQFsr8vDrN+DwFnR 7yEp2/3kMZsETtJKjPa15aI4sUxekRSeeuNewXqt7CAh8F1/gpoP/55uHcAg6JzXOtOz fkBMUTL+8FUSi18Vt24veXf1mHWe1ZwrJGoFbDGGJmDpCqIylwlXmOJ81E6f4aSQgUtq 0KWg== 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=l+1qno8+cnjw263RB0ykX/T91n5XpBlv2ZvQZZ7HqxQ21O1lOrLic+1El43vR0gGLc ODMrLUSk8fOV/8k6w1xGsgV2u5kIweYB7etl2zS+MeI3/9e8mTQn/2rOkOHesJIa/ux+ MMDykGOtA35ADH67VLWWZB9UyAlCjwGLZ0ssKRNYZvXBh0pd3npJaelrjPWoFZOTmEdB GJ2gDqD8RZL0U2SNfUF6/FfHvv+Dp6bWRXD6ToBgWU/0AMZ26Z0/8DgN1tjiQSwDrIUx utcoVebPXwGyQk/tKtK6WdxXd1i4V4reJMtN/10TAgE87e/pbjTBcdUgo59GjGdMYtR1 G5rw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EJQEsp6o; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124827-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124827-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z4-20020ae9f444000000b00789f61c0ac8si3723508qkl.457.2024.03.29.07.02.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 07:02:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124827-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EJQEsp6o; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124827-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124827-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id F3D561C2147E for ; Fri, 29 Mar 2024 14:02:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 108871B48A1; Fri, 29 Mar 2024 12:44:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EJQEsp6o" 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 347441B251D; Fri, 29 Mar 2024 12:44:03 +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=1711716243; cv=none; b=TFU635Ax58a5UCtRnYd7gsTAZ58aLoDJ/hLqwynHbe3gcDlhlYB5/HU7vq+UwineU23RXKIpllTv/gxQHRRAznj8EF0lLV7QgwjJE3ue0rXBXWI01YqbJIBQSFUP/fPlGav93eHhYTF82qTTWGMdQsXDm1YttBRhahdZbDSCiRo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716243; c=relaxed/simple; bh=uRO9hNSHchqspmCb1F6je6akXTN4Hy8qBEMg95DG9jg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AbmQncNOJryz0pntSnkxkV8Jjo0zrPMz/RHP1QjmapGL4ThAEqYclLKNmyns/vuWtesWUSYMfYs2ph9S7e7VNvVffAzaF3Cwo+xBNOSv52d6TfwyCVU8157wwYcQLtM4XNTvqJVFeAYSzctFCWHXLNadrjffCkdgmne/wkbiFXE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EJQEsp6o; arc=none smtp.client-ip=10.30.226.201 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> 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.6.23 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