Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp3845620rwj; Tue, 20 Dec 2022 02:44:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXsi4obQWUBXjwF+/ywFAQXkgv7yXG03AqabYHuRncPBlgnow1fYyKbArjRZDfkQzCuYRSaq X-Received: by 2002:a05:6a20:3b01:b0:a4:150f:8ddc with SMTP id c1-20020a056a203b0100b000a4150f8ddcmr14147365pzh.52.1671533092368; Tue, 20 Dec 2022 02:44:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671533092; cv=none; d=google.com; s=arc-20160816; b=X0jjNYiXz5aZztqz6X3cfB5wpNzfz+2869IoaaKZKd5O5wtx9IjPmi7DJq9hwa/f/9 ZRsN3T2s5635EL4z1iqfWv+GWnC8u2hzQK3tGi2Cdz5q/woi3pQYQmmyi3MnjuBFUEE0 kFEVxDYlLgShLyu3cHFLLx/ssT9gOMSfd4YzPh5E5MTWxduawd0ij61z0Bjr6qJzutLq ND5qwa/mTASqJLrncScqLlP24xxvc2uabBPpmn3+n1C3bOrGxL+R8JeWfIxCBrSv6+rs q0wylKUkijkCMVCwDis/fKFWYHM279z9SNFe92T6sRi85FIEmay4Aj2LkUHD70rp62KA XG0w== 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 :message-id:date:subject:cc:to:from; bh=zO8om+F8UnkxgjgnOdmDvt7KYeTbrl5gMSCzz4d0bWw=; b=hghfwUBD72QGM+vDhJSQ/kcRME8Zu2M4Bx/F9R383C8Xo/JKi8knvbUkBCVtkuQeE5 HSilU/+AuY8J+3NvQnxYbAD7hRcfH/+8zF7nQRDkWEDPcFxLGaA1Zwk3Q9uaBMiqs4fD atysaRDXzVRsjwvU5AXkcCfRV29KQh6CpaQD5qHQFYfZSlEXM2kq6ZemVqsmHFXZgZJF CzCfi9GZxZX6ChxzlDgGbNxIudRr76PUbyKb+BJCm+rYrjcY7BfJlqIscTGkJifTj4XE 1/NyKdzS2r/NDcIpzIBGDvg/5JYvFLlbk63AbDgVWpkV+fIz2ZdQZya/9A39M1aCd0lP iR+w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g35-20020a632023000000b004789f4ef8a6si13790084pgg.640.2022.12.20.02.44.42; Tue, 20 Dec 2022 02:44:52 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233491AbiLTKNE (ORCPT + 70 others); Tue, 20 Dec 2022 05:13:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233272AbiLTKNC (ORCPT ); Tue, 20 Dec 2022 05:13:02 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4475B2653; Tue, 20 Dec 2022 02:13:01 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B99772F4; Tue, 20 Dec 2022 02:13:41 -0800 (PST) Received: from pierre123.nice.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A2F863F71A; Tue, 20 Dec 2022 02:12:59 -0800 (PST) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: james.clark@arm.com, Ionela.Voinescu@arm.com, Pierre Gondois , "Rafael J. Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org Subject: [PATCH] cpufreq: CPPC: Add u64 casts to avoid overflowing Date: Tue, 20 Dec 2022 11:12:25 +0100 Message-Id: <20221220101225.3190672-1-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 The fields of the _CPC object are unsigned 32-bits values. To avoid overflows while using _CPC's values, add 'u64' casts. Signed-off-by: Pierre Gondois --- drivers/cpufreq/cppc_cpufreq.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 432dfb4e8027..022e3555407c 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -487,7 +487,8 @@ static unsigned int get_perf_level_count(struct cpufreq_policy *policy) cpu_data = policy->driver_data; perf_caps = &cpu_data->perf_caps; max_cap = arch_scale_cpu_capacity(cpu); - min_cap = div_u64(max_cap * perf_caps->lowest_perf, perf_caps->highest_perf); + min_cap = div_u64((u64)max_cap * perf_caps->lowest_perf, + perf_caps->highest_perf); if ((min_cap == 0) || (max_cap < min_cap)) return 0; return 1 + max_cap / CPPC_EM_CAP_STEP - min_cap / CPPC_EM_CAP_STEP; @@ -519,10 +520,10 @@ static int cppc_get_cpu_power(struct device *cpu_dev, cpu_data = policy->driver_data; perf_caps = &cpu_data->perf_caps; max_cap = arch_scale_cpu_capacity(cpu_dev->id); - min_cap = div_u64(max_cap * perf_caps->lowest_perf, - perf_caps->highest_perf); - - perf_step = CPPC_EM_CAP_STEP * perf_caps->highest_perf / max_cap; + min_cap = div_u64((u64)max_cap * perf_caps->lowest_perf, + perf_caps->highest_perf); + perf_step = div_u64((u64)CPPC_EM_CAP_STEP * perf_caps->highest_perf, + max_cap); min_step = min_cap / CPPC_EM_CAP_STEP; max_step = max_cap / CPPC_EM_CAP_STEP; -- 2.25.1