From patchwork Thu Jun 1 18:27:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjan van de Ven X-Patchwork-Id: 13264378 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06616C7EE2F for ; Thu, 1 Jun 2023 18:30:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232656AbjFASat (ORCPT ); Thu, 1 Jun 2023 14:30:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232258AbjFASan (ORCPT ); Thu, 1 Jun 2023 14:30:43 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42ED1197 for ; Thu, 1 Jun 2023 11:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685644242; x=1717180242; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TV9+KotZgTt2wCEdDqxarJhA1EkexUK6f2+xSypUoxQ=; b=VcrMwIQCOhffYBvwC/Qhblc5czevZDF+rHuSVqPo0cIaOgLT4oec42SU t4zxGUFl9APz13lRvqDKIVq7lDp47N9TNrUAKB99sHG8VR4MBhv/wtGW7 fLoleOciMNjC0i3Ra4Ya406VfD2rQ8npP+ZcQLI5+SAXaPiKWveU7CmGL MoIo6ct+hL8X8e+EVpqiaSz0gCScLusZhL7ym/nukt+p8rBSHZHoox8kc fcnjgRbEYVAulILGGLwsK48z98RcFkaBlSk0PcwEofjQ/CJPzCyEN9YdI ZbGGga0GS7z0cfxgNkKuY/86Nrm9IBPu4rnod1lgH9j8MOlMVsaqKZSa1 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="383921632" X-IronPort-AV: E=Sophos;i="6.00,210,1681196400"; d="scan'208";a="383921632" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2023 11:28:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="657900914" X-IronPort-AV: E=Sophos;i="6.00,210,1681196400"; d="scan'208";a="657900914" Received: from arjan-box.jf.intel.com ([10.54.74.119]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2023 11:28:19 -0700 From: arjan@linux.intel.com To: linux-pm@vger.kernel.org Cc: artem.bityutskiy@linux.intel.com, rafael@kernel.org, Arjan van de Ven , Arjan van de Ven Subject: [PATCH 3/7] intel_idle: Add a sanity check in the new state_update_enter_method function Date: Thu, 1 Jun 2023 18:27:57 +0000 Message-Id: <20230601182801.2622044-4-arjan@linux.intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230601182801.2622044-1-arjan@linux.intel.com> References: <20230601182801.2622044-1-arjan@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Arjan van de Ven The state_update_enter_method function updates a state's enter function pointer, but does so assuming that the current function is "intel_idle" or "intel_idle_irq". In the code currently that's basically the case, but soon this will change. Add a sanity check early in the function to make the assumption explicit, and return early if the precondition is not met. Signed-off-by: Arjan van de Ven --- drivers/idle/intel_idle.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c index 256c2d42e350..8415965372c7 100644 --- a/drivers/idle/intel_idle.c +++ b/drivers/idle/intel_idle.c @@ -1841,6 +1841,14 @@ static bool __init intel_idle_verify_cstate(unsigned int mwait_hint) static void state_update_enter_method(struct cpuidle_state *state, int cstate) { + /* + * The updates below are only valid if state->enter is actually the + * 'intel_idle' or 'intel_idle_irq' functions; for all other cases + * we just bow out early. + */ + if (state->enter != intel_idle && state->enter != intel_idle_irq ) + return; + if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) { /* * Combining with XSTATE with IBRS or IRQ_ENABLE flags