linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Amit Kucheria <amit.kucheria@linaro.org>,
	"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-pm@vger.kernel.org
Subject: [PATCH AUTOSEL 4.4 59/71] cpufreq: Register drivers only after CPU devices have been registered
Date: Tue, 10 Dec 2019 17:33:04 -0500	[thread overview]
Message-ID: <20191210223316.14988-59-sashal@kernel.org> (raw)
In-Reply-To: <20191210223316.14988-1-sashal@kernel.org>

From: Viresh Kumar <viresh.kumar@linaro.org>

[ 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 <bjorn.andersson@linaro.org>
Co-developed-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/cpufreq/cpufreq.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 2239d42bdadd9..49aa58e617db4 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2426,6 +2426,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) ||
-- 
2.20.1


  parent reply	other threads:[~2019-12-10 22:34 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-10 22:32 [PATCH AUTOSEL 4.4 01/71] drm: mst: Fix query_payload ack reply struct Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 02/71] iio: light: bh1750: Resolve compiler warning and make code more readable Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 03/71] iio: tcs3414: fix iio_triggered_buffer_{pre,post}enable positions Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 04/71] spi: Add call to spi_slave_abort() function when spidev driver is released Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 05/71] staging: rtl8188eu: fix possible null dereference Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 06/71] rtlwifi: prevent memory leak in rtl_usb_probe Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 07/71] IB/iser: bound protection_sg size by data_sg size Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 08/71] media: am437x-vpfe: Setting STD to current value is not an error Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 09/71] media: i2c: ov2659: fix s_stream return value Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 10/71] media: i2c: ov2659: Fix missing 720p register config Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 11/71] media: ov6650: Fix stored frame format not in sync with hardware Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 12/71] tools/power/cpupower: Fix initializer override in hsw_ext_cstates Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 13/71] usb: renesas_usbhs: add suspend event support in gadget mode Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 14/71] hwrng: omap3-rom - Call clk_disable_unprepare() on exit only if not idled Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 15/71] regulator: max8907: Fix the usage of uninitialized variable in max8907_regulator_probe() Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 16/71] media: flexcop-usb: fix NULL-ptr deref in flexcop_usb_transfer_init() Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 17/71] samples: pktgen: fix proc_cmd command result check logic Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 18/71] iio: proximity: sx9500: fix iio_triggered_buffer_{predisable,postenable} positions Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 19/71] mwifiex: pcie: Fix memory leak in mwifiex_pcie_init_evt_ring Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 20/71] media: ti-vpe: vpe: fix a v4l2-compliance warning about invalid pixel format Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 21/71] media: ti-vpe: vpe: fix a v4l2-compliance failure about frame sequence number Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 22/71] media: ti-vpe: vpe: Make sure YUYV is set as default format Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 23/71] extcon: sm5502: Reset registers during initialization Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 24/71] x86/mm: Use the correct function type for native_set_fixmap() Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 25/71] perf report: Add warning when libunwind not compiled in Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 26/71] usb: usbfs: Suppress problematic bind and unbind uevents Sasha Levin
2019-12-11  7:47   ` Greg Kroah-Hartman
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 27/71] iio: adc: max1027: Reset the device at probe time Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 28/71] iio: dac: ad7303: replace mlock with own lock Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 29/71] Bluetooth: hci_core: fix init for HCI_USER_CHANNEL Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 30/71] drm/gma500: fix memory disclosures due to uninitialized bytes Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 31/71] x86/ioapic: Prevent inconsistent state when moving an interrupt Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 32/71] arm64: psci: Reduce the waiting time for cpu_psci_cpu_kill() Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 33/71] ALSA: hda - Fix pending unsol events at shutdown Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 34/71] libata: Ensure ata_port probe has completed before detach Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 35/71] ata: sata_mv, avoid trigerrable BUG_ON Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 36/71] pinctrl: sh-pfc: sh7734: Fix duplicate TCLK1_B Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 37/71] bnx2x: Fix PF-VF communication over multi-cos queues Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 38/71] spi: img-spfi: fix potential double release Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 39/71] rtlwifi: fix memory leak in rtl92c_set_fw_rsvdpagepkt() Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 40/71] perf probe: Fix to find range-only function instance Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 41/71] perf probe: Fix to list probe event with correct line number Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 42/71] perf probe: Walk function lines in lexical blocks Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 43/71] perf probe: Fix to probe an inline function which has no entry pc Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 44/71] perf probe: Fix to show ranges of variables in functions without entry_pc Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 45/71] perf probe: Fix to show inlined function callsite " Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 46/71] perf probe: Skip overlapped location on searching variables Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 47/71] perf probe: Return a better scope DIE if there is no best scope Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 48/71] perf probe: Fix to show calling lines of inlined functions Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 49/71] perf probe: Skip end-of-sequence and non statement lines Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 50/71] perf probe: Filter out instances except for inlined subroutine and subprogram Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 51/71] ath10k: fix get invalid tx rate for Mesh metric Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 52/71] media: pvrusb2: Fix oops on tear-down when radio support is not present Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 53/71] media: si470x-i2c: add missed operations in remove Sasha Levin
2019-12-10 22:32 ` [PATCH AUTOSEL 4.4 54/71] EDAC/ghes: Fix grain calculation Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 55/71] spi: pxa2xx: Add missed security checks Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 56/71] ASoC: rt5677: Mark reg RT5677_PWR_ANLG2 as volatile Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 57/71] net: bcmgenet: Add RGMII_RXID support Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 58/71] parport: load lowlevel driver if ports not found Sasha Levin
2019-12-10 22:33 ` Sasha Levin [this message]
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 60/71] x86/crash: Add a forward declaration of struct kimage Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 61/71] RDMA/qib: Validate ->show()/store() callbacks before calling them Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 62/71] spi: tegra20-slink: add missed clk_unprepare Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 63/71] btrfs: don't prematurely free work in end_workqueue_fn() Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 64/71] iwlwifi: check kasprintf() return value Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 65/71] fbtft: Make sure string is NULL terminated Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 66/71] crypto: sun4i-ss - Fix 64-bit size_t warnings on sun4i-ss-hash.c Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 67/71] crypto: vmx - Avoid weird build failures Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 68/71] libtraceevent: Fix memory leakage in copy_filter_type Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 69/71] perf parse: Fix potential memory leak when handling tracepoint errors Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 70/71] perf intel-bts: Does not support AUX area sampling Sasha Levin
2019-12-10 22:33 ` [PATCH AUTOSEL 4.4 71/71] net: phy: initialise phydev speed and duplex sanely Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191210223316.14988-59-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=amit.kucheria@linaro.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).