Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3796758pxf; Mon, 29 Mar 2021 11:39:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyugOTov3Ey+Jiha6x/3EF5iJ+0ONrNFPy46DuviAEJtxBE1jLQ+QXjqoaEzuAoXifA79Sy X-Received: by 2002:a17:906:b817:: with SMTP id dv23mr30396989ejb.281.1617043178515; Mon, 29 Mar 2021 11:39:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617043178; cv=none; d=google.com; s=arc-20160816; b=tdiHlJKby5a+agjc+yo7twS/TSD4He6p1By1JgYEh/Dvi70O/jD/RQIWmaJB27OrzI HwJO+9JkpkCQZYBRpVx9xcsaZjVflKAZ0KTojnw7EInQZ4QsmoJVL9fMj+xnTv85HxcA KhlqQKkkBqYcUsofjytfPEh4OolSPRQyS8okqH6/Jz9TUZU2dRhyVo21ygjKpuuaGpls SAjThLWQXQrNU0AfQ+hMW8hkeB/k2pC/9ED+Rq+8EvePqYDaL8qWJO4vMEuYYQA0jLqM WE0pOnGbJqObAT18uaLKpaFUgD7Pn6bGv+w6nBq0p2TnlgIITWau9PGwb+I5fP6Z1z7z HTOw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hoibpahrwvv8VjhupUHEGaS06cwRfmZnksQ9/q0RLOU=; b=U0kK5bkafzIWHCJnePeCawwuUt47LM33KNLgjfj7+tlOUDVcB/UUWhze7Y7VkLTr1S evXygF79QWxtLY9YhHTWVBeV9QQWcesOC7xpzPiOsR36IxSDpJVPb5Da2npzJedOOvQx lfTH344icZBqvrAlwjpAie1NEbpJ0WA4k03nffgK/sx/RxhQfrx1XteXONQ8rGqKFhwt Y0W3e56fbQpxpIa1DX9s/hwHbCG0jya/VhQb+IjSCxxbF/anW/LM+YslFMWV4/Giokd/ g16A51JYDExbs8pbYLtQAwJhRPvgBaDoKBG3bvobHvLU93c65mUlWuWd0Nn3uh9jOY1y OVOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a14si12482823edr.155.2021.03.29.11.39.15; Mon, 29 Mar 2021 11:39:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231623AbhC2Shu (ORCPT + 99 others); Mon, 29 Mar 2021 14:37:50 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:64458 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231319AbhC2Shi (ORCPT ); Mon, 29 Mar 2021 14:37:38 -0400 Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 2.0.3) id 182b48a7b900cf93; Mon, 29 Mar 2021 20:37:37 +0200 Received: from kreacher.localnet (89-64-81-131.dynamic.chello.pl [89.64.81.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 357E1669165; Mon, 29 Mar 2021 20:37:36 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Frederic Weisbecker , Peter Zijlstra , Thomas Gleixner , "Zhou Ti (x2019cwm)" Subject: [PATCH v1 2/5] cpuidle: Use s64 as exit_latency_ns and target_residency_ns data type Date: Mon, 29 Mar 2021 20:15:19 +0200 Message-ID: <1850839.PYKUYFuaPT@kreacher> In-Reply-To: <2764850.e9J7NaK4W3@kreacher> References: <2764850.e9J7NaK4W3@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduledrudehkedguddvkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdejlefghfeiudektdelkeekvddugfeghffggeejgfeukeejleevgffgvdeluddtnecukfhppeekledrieegrdekuddrudefudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekledrieegrdekuddrudefuddphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehfrhgvuggvrhhitgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepthhglhigsehlihhnuhhtrhhonhhigidruggvpdhrtghp thhtohepgidvtddulegtfihmsehsthhfgidrtggr X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Rafael J. Wysocki" Subsequent changes will cause the exit_latency_ns and target_residency_ns fields in struct cpuidle_state to be used in computations in which data type conversions to u64 may turn a negative number close to zero into a verly large positive number leading to incorrect results. In preparation for that, change the data type of the fields mentioned above to s64, but ensure that they will not be negative themselves. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/cpuidle/driver.c | 4 ++++ include/linux/cpuidle.h | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) Index: linux-pm/include/linux/cpuidle.h =================================================================== --- linux-pm.orig/include/linux/cpuidle.h +++ linux-pm/include/linux/cpuidle.h @@ -49,8 +49,8 @@ struct cpuidle_state { char name[CPUIDLE_NAME_LEN]; char desc[CPUIDLE_DESC_LEN]; - u64 exit_latency_ns; - u64 target_residency_ns; + s64 exit_latency_ns; + s64 target_residency_ns; unsigned int flags; unsigned int exit_latency; /* in US */ int power_usage; /* in mW */ Index: linux-pm/drivers/cpuidle/driver.c =================================================================== --- linux-pm.orig/drivers/cpuidle/driver.c +++ linux-pm/drivers/cpuidle/driver.c @@ -181,9 +181,13 @@ static void __cpuidle_driver_init(struct */ if (s->target_residency > 0) s->target_residency_ns = s->target_residency * NSEC_PER_USEC; + else if (s->target_residency_ns < 0) + s->target_residency_ns = 0; if (s->exit_latency > 0) s->exit_latency_ns = s->exit_latency * NSEC_PER_USEC; + else if (s->exit_latency_ns < 0) + s->exit_latency_ns = 0; } }