From b61011ada5ff9f323b8a1795211139c290cbf693 Mon Sep 17 00:00:00 2001 From: David Collins Date: Fri, 3 Aug 2018 16:45:49 -0700 Subject: [PATCH 1/2] clk: qcom: clk-aop-qmp: use correct name pointer before clock registration clk_aop_qmp_prepare() is called from aop_qmp_clk_probe() before devm_clk_register() is called. This means that clock hw->core pointers are NULL and clk_hw_get_name(hw) triggers a NULL pointer dereference. Use hw->init->name instead of clk_hw_get_name(hw) to avoid the NULL pointer dereference. Change-Id: I548df6518053260d44227adc0479b1ea52a81fc9 Signed-off-by: David Collins --- drivers/clk/qcom/clk-aop-qmp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clk/qcom/clk-aop-qmp.c b/drivers/clk/qcom/clk-aop-qmp.c index ea6c8a4f93ca..3d69dc945003 100644 --- a/drivers/clk/qcom/clk-aop-qmp.c +++ b/drivers/clk/qcom/clk-aop-qmp.c @@ -149,7 +149,8 @@ static int clk_aop_qmp_prepare(struct clk_hw *hw) ret = mbox_send_message(clk->mbox, &pkt); if (ret < 0) { pr_err("Failed to send clk prepare request for %s, ret %d\n", - clk_hw_get_name(hw), ret); + hw->core ? clk_hw_get_name(hw) : hw->init->name, + ret); goto err; } From beddf9a0d1b3ca295c7667bf9da25fa03c5a0ecb Mon Sep 17 00:00:00 2001 From: David Collins Date: Tue, 9 Jan 2018 18:01:35 -0800 Subject: [PATCH 2/2] clk: qcom: clk-spmi-pmic-div: add support for clock-output-names Some boards utilize several PMICs which contain clock divider peripherals. Add support for the clock-output-names property so that unique names can be specified for each divider clock. If clock-output-names is not specified, then the clock names will be div_clkN where N=1 to qcom,num-clkdivs. Change-Id: I66b5fcd0a3890886fe1e8cd85b15ada8a55ecb0f Signed-off-by: David Collins --- drivers/clk/qcom/clk-spmi-pmic-div.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/clk/qcom/clk-spmi-pmic-div.c b/drivers/clk/qcom/clk-spmi-pmic-div.c index f2cf55cee2fd..af7ebeb9a7e8 100644 --- a/drivers/clk/qcom/clk-spmi-pmic-div.c +++ b/drivers/clk/qcom/clk-spmi-pmic-div.c @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2017, The Linux Foundation. All rights reserved. - */ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. */ #include #include @@ -204,6 +203,7 @@ static int spmi_pmic_clkdiv_probe(struct platform_device *pdev) struct regmap *regmap; struct device *dev = &pdev->dev; struct device_node *of_node = dev->of_node; + bool use_dt_name = false; const char *parent_name; int nclks, i, ret, cxo_hz; char name[20]; @@ -252,13 +252,26 @@ static int spmi_pmic_clkdiv_probe(struct platform_device *pdev) return -ENODEV; } + if (of_find_property(of_node, "clock-output-names", NULL)) + use_dt_name = true; + init.name = name; init.parent_names = &parent_name; init.num_parents = 1; init.ops = &clk_spmi_pmic_div_ops; for (i = 0, clkdiv = cc->clks; i < nclks; i++) { - snprintf(name, sizeof(name), "div_clk%d", i + 1); + if (use_dt_name) { + ret = of_property_read_string_index(of_node, + "clock-output-names", i, &init.name); + if (ret) { + dev_err(dev, "could not read clock-output-names %d, ret=%d\n", + i, ret); + return ret; + } + } else { + snprintf(name, sizeof(name), "div_clk%d", i + 1); + } spin_lock_init(&clkdiv[i].lock); clkdiv[i].base = start + i * 0x100;