Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4978000pxj; Tue, 22 Jun 2021 12:13:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJgr9HUqwUKqZCS49V7kZB8UrpWNk/hDgBFUDGw16kkWILK5uU6yL61vi2t4rabhujgEJA X-Received: by 2002:a05:6402:1d3a:: with SMTP id dh26mr7306542edb.127.1624389212319; Tue, 22 Jun 2021 12:13:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624389212; cv=none; d=google.com; s=arc-20160816; b=vMR/BRP2cd0HoBV2j6kJv2z+X/broExhkqsm7TIDxVHyzmXhKQKE4jAdHgmyQLWUuB xFcDtWSDHVpnbdPsUoF6oRdgxiqzGFY1Py9Vksjd8rNCa8nEofLSDh1qhO/O8ZglhLgO zWTvCmcAa/Xh0nShwhpRq/vd5EDe9HgM1mVRI7XBpNXam+/LilnnufM8XNRVineqyYnz TxbyZV5DZnWqPmC2uu7vkd3xmj6cOnT+h8EPem5R6XzfkvkgfGBV95tgclUbnq8OPQmu pivmKUirvVD7mZySICbUQ49N9wivAvZlb08p6Idj96Ry4vOLDRInuz67xUuONgj0Kc26 CwYQ== 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=rB98FpFmcdP/aqwmLZDwYcEsYbac8uxVIIyFhediy0w=; b=z/1BsMv99GwlQzpgaE5h3VQChg0m+AX0QV5KtEQROyo4XoL0ZlX3G1J70P4Q9ldgNa mYwflq/yyNwA+f6NECAAQX4tSa5co7vltJs688h+ZuoKM9y/IDhdI0pT+kmCKqPqr4SJ t6AYoH0lAsvHrHqcsVehdnAvG1fo2VVRY8q0wfrW3SHJeZJpWPnxyv021x23OYWn/zJb D+5LG6CG6sso6BAfU5GXMfhHbOjaInZhCZa6/lqgfJlGPMaGLkjk3HifOS0oJJyXNhX+ 1aR9W7qHuHKwXsp/Py0eDs001IzHl+AaB92t/nhTi4k2GKLl8ln/I3bFmsEOBJ59caJH zwTw== 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 s18si16589246eji.655.2021.06.22.12.13.09; Tue, 22 Jun 2021 12:13:32 -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 S232709AbhFVTOK (ORCPT + 99 others); Tue, 22 Jun 2021 15:14:10 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:43504 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232452AbhFVTOJ (ORCPT ); Tue, 22 Jun 2021 15:14:09 -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.1.0) id 0fae083bb3ac6f6e; Tue, 22 Jun 2021 21:11:41 +0200 Received: from kreacher.localnet (89-64-82-70.dynamic.chello.pl [89.64.82.70]) (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 A28C56645FF; Tue, 22 Jun 2021 21:11:40 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM , Viresh Kumar Cc: LKML Subject: [PATCH v2] cpufreq: Make cpufreq_online() call driver->offline() on errors Date: Tue, 22 Jun 2021 21:11:39 +0200 Message-ID: <5490292.DvuYhMxLoT@kreacher> In-Reply-To: <11788436.O9o76ZdvQC@kreacher> References: <11788436.O9o76ZdvQC@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 89.64.82.70 X-CLIENT-HOSTNAME: 89-64-82-70.dynamic.chello.pl X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduledrfeeguddgudeffecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdejlefghfeiudektdelkeekvddugfeghffggeejgfeukeejleevgffgvdeluddtnecukfhppeekledrieegrdekvddrjedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepkeelrdeigedrkedvrdejtddphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehvihhrvghshhdrkhhumhgrrheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-DCC--Metrics: v370.home.net.pl 1024; Body=3 Fuz1=3 Fuz2=3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki Subject: [PATCH] cpufreq: Make cpufreq_online() call driver->offline() on errors In the CPU removal path the ->offline() callback provided by the driver is always invoked before ->exit(), but in the cpufreq_online() error path it is not, so ->exit() is expected to somehow know the context in which it has been called and act accordingly. That is less than straightforward, so make cpufreq_online() invoke the driver's ->offline() callback, if present, on errors before ->exit() too. This only potentially affects intel_pstate. Fixes: 91a12e91dc39 ("cpufreq: Allow light-weight tear down and bring up of CPUs") Signed-off-by: Rafael J. Wysocki --- -> v2: * Avoid calling ->offline() after a failing ->online(). * Add a comment regarding the expected state after calling ->init(). * Edit the changelog a bit. --- drivers/cpufreq/cpufreq.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) Index: linux-pm/drivers/cpufreq/cpufreq.c =================================================================== --- linux-pm.orig/drivers/cpufreq/cpufreq.c +++ linux-pm/drivers/cpufreq/cpufreq.c @@ -1367,9 +1367,14 @@ static int cpufreq_online(unsigned int c goto out_free_policy; } + /* + * The initialization has succeeded and the policy is online. + * If there is a problem with its frequency table, take it + * offline and drop it. + */ ret = cpufreq_table_validate_and_sort(policy); if (ret) - goto out_exit_policy; + goto out_offline_policy; /* related_cpus should at least include policy->cpus. */ cpumask_copy(policy->related_cpus, policy->cpus); @@ -1515,6 +1520,10 @@ out_destroy_policy: up_write(&policy->rwsem); +out_offline_policy: + if (cpufreq_driver->offline) + cpufreq_driver->offline(policy); + out_exit_policy: if (cpufreq_driver->exit) cpufreq_driver->exit(policy);