Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp842097pxb; Tue, 3 Nov 2020 14:07:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJMWgc/Ys0Kj+bhlo8NYBhYD37IMtqSdKPwItsMspNBEfJUy5obfV/Ws7c6Usl4+pXEZpt X-Received: by 2002:a05:6402:1f1:: with SMTP id i17mr9096978edy.60.1604441272696; Tue, 03 Nov 2020 14:07:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604441272; cv=none; d=google.com; s=arc-20160816; b=wgYmguU9jTyWGclxitzEHQn446wUOwLUImm4aryUd7e55hiJX1zeVQnx1oGZpMS3t5 mVKviJfkw+NOn7NfdXVhb3JFaiEg46JOWgjAyT3UBkYDi0vD2CymaeRVIw03VOfDO9zw QYBjf6LrXSmkcNCnTgyock7CNTJSFXGRPM7kXAz6/dldcd13rOu249R2oCctDv5vSylO AJbQTh1zoOhotM1tjryXcRMEtDWeFBUXfrWz3Rd7nWVULX58UAWKRyiiiSOicxEZVScD VJr5YtAX4QbGupPPoepCzFXMJwG+UQyq79tH5ULMPi/9qeANL1hCpOjRm1Vg83XTwIs9 0gRg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TaSKCQvk4qvlOAPTooOju5Fn5zt84JvnvhlKXAdmTf0=; b=z/LNiyf8SweUJwu+dRuUb0DOGfVNwbQLLWbccSvJX8irOwUBYY9R2bZnohXlFmVT2b KyssfFUMD8x46ESldTYl3XgstCOPBjo9XKadlB4HyOje7soiq419JDZLx5JrFllqEO0e ijHdk4zULONBnpQp8XAU2gU5kPhXT5981TdPoX3nwa0JsQwDPoJTiNwR4HCkIR4p5Vk4 6zzD6xS41vUea8N0wJjGVKkTie5LGGH1kS9TjZZpKxphf4iplsf7ydhSmqaD0j2+l96c CEZ+rnXke18nOUs93PS0Dz6h5JdpmYc3r32ZNUHT+i8H8EOd8zPQZCe+zICChcRba1om s8hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e891+oel; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p14si132951ejg.51.2020.11.03.14.07.29; Tue, 03 Nov 2020 14:07:52 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=e891+oel; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730534AbgKCUma (ORCPT + 99 others); Tue, 3 Nov 2020 15:42:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:54506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730494AbgKCUmV (ORCPT ); Tue, 3 Nov 2020 15:42:21 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1615D2224E; Tue, 3 Nov 2020 20:42:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436140; bh=y6LYEWEo8WSjrCc+zuYLctxEhV3uhZU/fFRDvDueRZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e891+oelnh5aGU1R/zx7JZzQAIO003hb7Vk4iBcu4aMjpHQxXUhQR5HdsGyAO8hGA GAkoeOBdfQ9od40SC2DQD5ZTkoKvu60udsnjn6lKmBM+zB0Tf+M6avURrDkirDzcZE Hr97uX2JFAjX73l9pnHs+tbI4MtAOh1mTVDrNbxU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Osipenko , Jon Hunter , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.9 120/391] cpuidle: tegra: Correctly handle result of arm_cpuidle_simple_enter() Date: Tue, 3 Nov 2020 21:32:51 +0100 Message-Id: <20201103203354.921748396@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dmitry Osipenko [ Upstream commit 1170433e6611402b869c583fa1fbfd85106ff066 ] The enter() callback of CPUIDLE drivers returns index of the entered idle state on success or a negative value on failure. The negative value could any negative value, i.e. it doesn't necessarily needs to be a error code. That's because CPUIDLE core only cares about the fact of failure and not about the reason of the enter() failure. Like every other enter() callback, the arm_cpuidle_simple_enter() returns the entered idle-index on success. Unlike some of other drivers, it never fails. It happened that TEGRA_C1=index=err=0 in the code of cpuidle-tegra driver, and thus, there is no problem for the cpuidle-tegra driver created by the typo in the code which assumes that the arm_cpuidle_simple_enter() returns a error code. The arm_cpuidle_simple_enter() also may return a -ENODEV error if CPU_IDLE is disabled in a kernel's config, but all CPUIDLE drivers are disabled if CPU_IDLE is disabled, including the cpuidle-tegra driver. So we can't ever see the error code from arm_cpuidle_simple_enter() today. Of course the code may get some changes in the future and then the typo may transform into a real bug, so let's correct the typo! The tegra_cpuidle_state_enter() is now changed to make it return the entered idle-index on success and negative error code on fail, which puts it on par with the arm_cpuidle_simple_enter(), making code consistent in regards to the error handling. This patch fixes a minor typo in the code, it doesn't fix any bugs. Signed-off-by: Dmitry Osipenko Reviewed-by: Jon Hunter Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/cpuidle/cpuidle-tegra.c | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/drivers/cpuidle/cpuidle-tegra.c b/drivers/cpuidle/cpuidle-tegra.c index a12fb141875a7..e8956706a2917 100644 --- a/drivers/cpuidle/cpuidle-tegra.c +++ b/drivers/cpuidle/cpuidle-tegra.c @@ -172,7 +172,7 @@ static int tegra_cpuidle_coupled_barrier(struct cpuidle_device *dev) static int tegra_cpuidle_state_enter(struct cpuidle_device *dev, int index, unsigned int cpu) { - int ret; + int err; /* * CC6 state is the "CPU cluster power-off" state. In order to @@ -183,9 +183,9 @@ static int tegra_cpuidle_state_enter(struct cpuidle_device *dev, * CPU cores, GIC and L2 cache). */ if (index == TEGRA_CC6) { - ret = tegra_cpuidle_coupled_barrier(dev); - if (ret) - return ret; + err = tegra_cpuidle_coupled_barrier(dev); + if (err) + return err; } local_fiq_disable(); @@ -194,15 +194,15 @@ static int tegra_cpuidle_state_enter(struct cpuidle_device *dev, switch (index) { case TEGRA_C7: - ret = tegra_cpuidle_c7_enter(); + err = tegra_cpuidle_c7_enter(); break; case TEGRA_CC6: - ret = tegra_cpuidle_cc6_enter(cpu); + err = tegra_cpuidle_cc6_enter(cpu); break; default: - ret = -EINVAL; + err = -EINVAL; break; } @@ -210,7 +210,7 @@ static int tegra_cpuidle_state_enter(struct cpuidle_device *dev, tegra_pm_clear_cpu_in_lp2(); local_fiq_enable(); - return ret; + return err ?: index; } static int tegra_cpuidle_adjust_state_index(int index, unsigned int cpu) @@ -236,21 +236,27 @@ static int tegra_cpuidle_enter(struct cpuidle_device *dev, int index) { unsigned int cpu = cpu_logical_map(dev->cpu); - int err; + int ret; index = tegra_cpuidle_adjust_state_index(index, cpu); if (dev->states_usage[index].disable) return -1; if (index == TEGRA_C1) - err = arm_cpuidle_simple_enter(dev, drv, index); + ret = arm_cpuidle_simple_enter(dev, drv, index); else - err = tegra_cpuidle_state_enter(dev, index, cpu); + ret = tegra_cpuidle_state_enter(dev, index, cpu); - if (err && (err != -EINTR || index != TEGRA_CC6)) - pr_err_once("failed to enter state %d err: %d\n", index, err); + if (ret < 0) { + if (ret != -EINTR || index != TEGRA_CC6) + pr_err_once("failed to enter state %d err: %d\n", + index, ret); + index = -1; + } else { + index = ret; + } - return err ? -1 : index; + return index; } static int tegra114_enter_s2idle(struct cpuidle_device *dev, -- 2.27.0