All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Stephen Boyd <sboyd@kernel.org>,
	Douglas Anderson <dianders@chromium.org>,
	Heiko Stuebner <heiko@sntech.de>,
	Jerome Brunet <jbrunet@baylibre.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-clk@vger.kernel.org
Subject: [PATCH AUTOSEL 5.4 02/84] clk: Don't cache errors from clk_ops::get_phase()
Date: Wed, 15 Apr 2020 07:43:19 -0400	[thread overview]
Message-ID: <20200415114442.14166-2-sashal@kernel.org> (raw)
In-Reply-To: <20200415114442.14166-1-sashal@kernel.org>

From: Stephen Boyd <sboyd@kernel.org>

[ Upstream commit f21cf9c77ee82ef8adfeb2143adfacf21ec1d5cc ]

We don't check for errors from clk_ops::get_phase() before storing away
the result into the clk_core::phase member. This can lead to some fairly
confusing debugfs information if these ops do return an error. Let's
skip the store when this op fails to fix this. While we're here, move
the locking outside of clk_core_get_phase() to simplify callers from
the debugfs side.

Cc: Douglas Anderson <dianders@chromium.org>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Jerome Brunet <jbrunet@baylibre.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Link: https://lkml.kernel.org/r/20200205232802.29184-2-sboyd@kernel.org
Acked-by: Jerome Brunet <jbrunet@baylibre.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/clk/clk.c | 48 +++++++++++++++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 16 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 62d0fc486d3a2..80b029713722b 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2642,12 +2642,14 @@ static int clk_core_get_phase(struct clk_core *core)
 {
 	int ret;
 
-	clk_prepare_lock();
+	lockdep_assert_held(&prepare_lock);
+	if (!core->ops->get_phase)
+		return 0;
+
 	/* Always try to update cached phase if possible */
-	if (core->ops->get_phase)
-		core->phase = core->ops->get_phase(core->hw);
-	ret = core->phase;
-	clk_prepare_unlock();
+	ret = core->ops->get_phase(core->hw);
+	if (ret >= 0)
+		core->phase = ret;
 
 	return ret;
 }
@@ -2661,10 +2663,16 @@ static int clk_core_get_phase(struct clk_core *core)
  */
 int clk_get_phase(struct clk *clk)
 {
+	int ret;
+
 	if (!clk)
 		return 0;
 
-	return clk_core_get_phase(clk->core);
+	clk_prepare_lock();
+	ret = clk_core_get_phase(clk->core);
+	clk_prepare_unlock();
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(clk_get_phase);
 
@@ -2878,13 +2886,21 @@ static struct hlist_head *orphan_list[] = {
 static void clk_summary_show_one(struct seq_file *s, struct clk_core *c,
 				 int level)
 {
-	seq_printf(s, "%*s%-*s %7d %8d %8d %11lu %10lu %5d %6d\n",
+	int phase;
+
+	seq_printf(s, "%*s%-*s %7d %8d %8d %11lu %10lu ",
 		   level * 3 + 1, "",
 		   30 - level * 3, c->name,
 		   c->enable_count, c->prepare_count, c->protect_count,
-		   clk_core_get_rate(c), clk_core_get_accuracy(c),
-		   clk_core_get_phase(c),
-		   clk_core_get_scaled_duty_cycle(c, 100000));
+		   clk_core_get_rate(c), clk_core_get_accuracy(c));
+
+	phase = clk_core_get_phase(c);
+	if (phase >= 0)
+		seq_printf(s, "%5d", phase);
+	else
+		seq_puts(s, "-----");
+
+	seq_printf(s, " %6d\n", clk_core_get_scaled_duty_cycle(c, 100000));
 }
 
 static void clk_summary_show_subtree(struct seq_file *s, struct clk_core *c,
@@ -2921,6 +2937,7 @@ DEFINE_SHOW_ATTRIBUTE(clk_summary);
 
 static void clk_dump_one(struct seq_file *s, struct clk_core *c, int level)
 {
+	int phase;
 	unsigned long min_rate, max_rate;
 
 	clk_core_get_boundaries(c, &min_rate, &max_rate);
@@ -2934,7 +2951,9 @@ static void clk_dump_one(struct seq_file *s, struct clk_core *c, int level)
 	seq_printf(s, "\"min_rate\": %lu,", min_rate);
 	seq_printf(s, "\"max_rate\": %lu,", max_rate);
 	seq_printf(s, "\"accuracy\": %lu,", clk_core_get_accuracy(c));
-	seq_printf(s, "\"phase\": %d,", clk_core_get_phase(c));
+	phase = clk_core_get_phase(c);
+	if (phase >= 0)
+		seq_printf(s, "\"phase\": %d,", phase);
 	seq_printf(s, "\"duty_cycle\": %u",
 		   clk_core_get_scaled_duty_cycle(c, 100000));
 }
@@ -3375,14 +3394,11 @@ static int __clk_core_init(struct clk_core *core)
 		core->accuracy = 0;
 
 	/*
-	 * Set clk's phase.
+	 * Set clk's phase by clk_core_get_phase() caching the phase.
 	 * Since a phase is by definition relative to its parent, just
 	 * query the current clock phase, or just assume it's in phase.
 	 */
-	if (core->ops->get_phase)
-		core->phase = core->ops->get_phase(core->hw);
-	else
-		core->phase = 0;
+	clk_core_get_phase(core);
 
 	/*
 	 * Set clk's duty cycle.
-- 
2.20.1


  reply	other threads:[~2020-04-15 12:31 UTC|newest]

Thread overview: 133+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-15 11:43 [PATCH AUTOSEL 5.4 01/84] drm/ttm: flush the fence on the bo after we individualize the reservation object Sasha Levin
2020-04-15 11:43 ` Sasha Levin
2020-04-15 11:43 ` Sasha Levin [this message]
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 03/84] clk: at91: usb: continue if clk_hw_round_rate() return zero Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 04/84] net/mlx5e: Enforce setting of a single FEC mode Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 05/84] f2fs: fix the panic in do_checkpoint() Sasha Levin
2020-04-15 11:43   ` [f2fs-dev] " Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 06/84] arm64: dts: librem5-devkit: add a vbus supply to usb0 Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 07/84] ARM: dts: rockchip: fix vqmmc-supply property name for rk3188-bqedison2qc Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 08/84] arm64: dts: allwinner: a64: Fix display clock register range Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 09/84] power: supply: bq27xxx_battery: Silence deferred-probe error Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 10/84] clk: tegra: Fix Tegra PMC clock out parents Sasha Levin
     [not found] ` <20200415114442.14166-1-sashal-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2020-04-15 11:43   ` [PATCH AUTOSEL 5.4 11/84] arm64: tegra: Add PCIe endpoint controllers nodes for Tegra194 Sasha Levin
2020-04-15 11:43     ` Sasha Levin
2020-04-15 11:43   ` [PATCH AUTOSEL 5.4 12/84] arm64: tegra: Fix Tegra194 PCIe compatible string Sasha Levin
2020-04-15 11:43     ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 13/84] arm64: dts: clearfog-gt-8k: set gigabit PHY reset deassert delay Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 14/84] soc: imx: gpc: fix power up sequencing Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 15/84] dma-coherent: fix integer overflow in the reserved-memory dma allocation Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 16/84] rtc: 88pm860x: fix possible race condition Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 17/84] NFS: alloc_nfs_open_context() must use the file cred when available Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 18/84] NFSv4/pnfs: Return valid stateids in nfs_layout_find_inode_by_stateid() Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 19/84] NFSv4.2: error out when relink swapfile Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 20/84] ARM: dts: rockchip: fix lvds-encoder ports subnode for rk3188-bqedison2qc Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 21/84] KVM: PPC: Book3S HV: Fix H_CEDE return code for nested guests Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 22/84] f2fs: fix to show norecovery mount option Sasha Levin
2020-04-15 11:43   ` [f2fs-dev] " Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 23/84] phy: uniphier-usb3ss: Add Pro5 support Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 24/84] NFS: direct.c: Fix memory leak of dreq when nfs_get_lock_context fails Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 25/84] f2fs: Fix mount failure due to SPO after a successful online resize FS Sasha Levin
2020-04-15 11:43   ` [f2fs-dev] " Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 26/84] f2fs: Add a new CP flag to help fsck fix resize SPO issues Sasha Levin
2020-04-15 11:43   ` [f2fs-dev] " Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 27/84] s390/cpuinfo: fix wrong output when CPU0 is offline Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 28/84] hibernate: Allow uswsusp to write to swap Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 29/84] btrfs: handle NULL roots in btrfs_put/btrfs_grab_fs_root Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 30/84] btrfs: add RCU locks around block group initialization Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 31/84] powerpc/prom_init: Pass the "os-term" message to hypervisor Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 32/84] powerpc/maple: Fix declaration made after definition Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 33/84] s390/cpum_sf: Fix wrong page count in error message Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 34/84] ext4: do not commit super on read-only bdev Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 35/84] ext4: fix incorrect group count in ext4_fill_super error message Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 36/84] ext4: fix incorrect inodes per group in " Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 37/84] um: ubd: Prevent buffer overrun on command completion Sasha Levin
2020-04-15 11:43   ` Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 38/84] cifs: Allocate encryption header through kmalloc Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 39/84] cxgb4: fix MPS index overwrite when setting MAC address Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 40/84] slcan: Don't transmit uninitialized stack data in padding Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 41/84] net: qualcomm: rmnet: Allow configuration updates to existing devices Sasha Levin
2020-04-15 11:43 ` [PATCH AUTOSEL 5.4 42/84] mm/hugetlb: fix build failure with HUGETLB_PAGE but not HUGEBTLBFS Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 43/84] net: stmmac: dwmac1000: fix out-of-bounds mac address reg setting Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 44/84] net: dsa: mt7530: fix null pointer dereferencing in port5 setup Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 45/84] tun: Don't put_page() for all negative return values from XDP program Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 46/84] mlxsw: spectrum_flower: Do not stop at FLOW_ACTION_VLAN_MANGLE Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 47/84] net: dsa: bcm_sf2: Do not register slave MDIO bus with OF Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 48/84] drm/nouveau/svm: check for SVM initialized before migrating Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 49/84] drm/nouveau/svm: fix vma range check for migration Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 50/84] include/linux/swapops.h: correct guards for non_swap_entry() Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 51/84] percpu_counter: fix a data race at vm_committed_as Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 52/84] linux/bits.h: add compile time sanity check of GENMASK inputs Sasha Levin
2020-04-15 19:40   ` Rikard Falkeborn
2020-04-22  0:57     ` Sasha Levin
2020-04-23 21:40       ` Rikard Falkeborn
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 53/84] compiler.h: fix error in BUILD_BUG_ON() reporting Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 54/84] KVM: s390: vsie: Fix possible race when shadowing region 3 tables Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 55/84] drm/nouveau: workaround runpm fail by disabling PCI power management on certain intel bridges Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 56/84] leds: core: Fix warning message when init_data Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 57/84] net: dsa: bcm_sf2: Ensure correct sub-node is parsed Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 58/84] x86: ACPI: fix CPU hotplug deadlock Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 59/84] net: phy: micrel: kszphy_resume(): add delay after genphy_resume() before accessing PHY registers Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 60/84] csky: Fixup cpu speculative execution to IO area Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 61/84] drm/amdkfd: kfree the wrong pointer Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 62/84] NFS: Fix memory leaks in nfs_pageio_stop_mirroring() Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 63/84] csky: Fixup get wrong psr value from phyical reg Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 64/84] f2fs: fix NULL pointer dereference in f2fs_write_begin() Sasha Levin
2020-04-15 11:44   ` [f2fs-dev] " Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 65/84] ACPICA: Fixes for acpiExec namespace init file Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 66/84] mfd: dln2: Fix sanity checking for endpoints Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 67/84] um: falloc.h needs to be directly included for older libc Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 68/84] drm/vc4: Fix HDMI mode validation Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 69/84] iommu/virtio: Fix freeing of incomplete domains Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 70/84] iommu/vt-d: Fix mm reference leak Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 71/84] SUNRPC: fix krb5p mount to provide large enough buffer in rq_rcvsize Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 72/84] ext2: fix empty body warnings when -Wextra is used Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 73/84] iommu/vt-d: Silence RCU-list debugging warning in dmar_find_atsr() Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 74/84] iommu/vt-d: Fix page request descriptor size Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 75/84] ovl: fix value of i_ino for lower hardlink corner case Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 76/84] ext2: fix debug reference to ext2_xattr_cache Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 77/84] sunrpc: Fix gss_unwrap_resp_integ() again Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 78/84] csky: Fixup init_fpu compile warning with __init Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 79/84] power: supply: axp288_fuel_gauge: Broaden vendor check for Intel Compute Sticks Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 80/84] platform/chrome: cros_ec_rpmsg: Fix race with host event Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 81/84] libnvdimm: Out of bounds read in __nd_ioctl() Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 82/84] acpi/nfit: improve bounds checking for 'func' Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 83/84] iommu/amd: Fix the configuration of GCR3 table root pointer Sasha Levin
2020-04-15 11:44   ` Sasha Levin
2020-04-15 11:44 ` [PATCH AUTOSEL 5.4 84/84] f2fs: fix to wait all node page writeback Sasha Levin
2020-04-15 11:44   ` [f2fs-dev] " 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=20200415114442.14166-2-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=dianders@chromium.org \
    --cc=heiko@sntech.de \
    --cc=jbrunet@baylibre.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=stable@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.