From patchwork Thu Jan 2 22:06:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 234605 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B91BC3276C for ; Thu, 2 Jan 2020 22:46:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3E5FA20848 for ; Thu, 2 Jan 2020 22:46:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578005210; bh=Q0XfiEEF4+nFab0KeB9h3/YN2rBxXvvfp51xB1lxAsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=dZWzNILtCVwTti/8cHInOtmbYv4Q2Q/kMv5Gn1oj2ZqBw0APLtb9gZ2RDND7u+N+x eFICATqEy253VGKZDIh4utr2Tjs/4X8lom7YnG91qkD/ZkIfSkp8fHKwSagw4OLFvb AiLhuGNmmfZV4MNL4iWALfnArmrlM1pDk9WRjYPM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729878AbgABWaU (ORCPT ); Thu, 2 Jan 2020 17:30:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:33994 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730012AbgABWaU (ORCPT ); Thu, 2 Jan 2020 17:30:20 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 349A62253D; Thu, 2 Jan 2020 22:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004219; bh=Q0XfiEEF4+nFab0KeB9h3/YN2rBxXvvfp51xB1lxAsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dDMdFxpeWlTSlScb6cJymbkSwv1YjJ1fPglyFhA7FiBZeAQX41MqX71IB5/DjZwAN sjwywIKaz4HMFKcbJ5ZumKZuk0z7ATkLJR475fSP6MivM5X3tc45o2ySM2FRedE86A 8M4aMVFknmGO+s2h5jmK8x4VIorFBV9l0gGsY+3E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bjorn Andersson , Viresh Kumar , Amit Kucheria , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 4.9 070/171] cpufreq: Register drivers only after CPU devices have been registered Date: Thu, 2 Jan 2020 23:06:41 +0100 Message-Id: <20200102220556.622524885@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.960200039@linuxfoundation.org> References: <20200102220546.960200039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Viresh Kumar [ Upstream commit 46770be0cf94149ca48be87719bda1d951066644 ] The cpufreq core heavily depends on the availability of the struct device for CPUs and if they aren't available at the time cpufreq driver is registered, we will never succeed in making cpufreq work. This happens due to following sequence of events: - cpufreq_register_driver() - subsys_interface_register() - return 0; //successful registration of driver ... at a later point of time - register_cpu(); - device_register(); - bus_probe_device(); - sif->add_dev(); - cpufreq_add_dev(); - get_cpu_device(); //FAILS - per_cpu(cpu_sys_devices, num) = &cpu->dev; //used by get_cpu_device() - return 0; //CPU registered successfully Because the per-cpu variable cpu_sys_devices is set only after the CPU device is regsitered, cpufreq will never be able to get it when cpufreq_add_dev() is called. This patch avoids this failure by making sure device structure of at least CPU0 is available when the cpufreq driver is registered, else return -EPROBE_DEFER. Reported-by: Bjorn Andersson Co-developed-by: Amit Kucheria Signed-off-by: Viresh Kumar Tested-by: Amit Kucheria Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/cpufreq/cpufreq.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 063ce77df619..86d48f8c6a2e 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2449,6 +2449,13 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) if (cpufreq_disabled()) return -ENODEV; + /* + * The cpufreq core depends heavily on the availability of device + * structure, make sure they are available before proceeding further. + */ + if (!get_cpu_device(0)) + return -EPROBE_DEFER; + if (!driver_data || !driver_data->verify || !driver_data->init || !(driver_data->setpolicy || driver_data->target_index || driver_data->target) ||