Linux-Clk Archive on lore.kernel.org
 help / Atom feed
* [PATCH] clk: gemini: Variable "val" in function gemini_clk_probe() could be uninitialized
@ 2019-01-27  5:10 Yizhuo
  2019-02-06 19:23 ` Stephen Boyd
  0 siblings, 1 reply; 2+ messages in thread
From: Yizhuo @ 2019-01-27  5:10 UTC (permalink / raw)
  To: unlisted-recipients:; (no To-header on input)
  Cc: csong, zhiyunq, Yizhuo, Michael Turquette, Stephen Boyd,
	linux-clk, linux-kernel

In function gemini_clk_probe(), local variable "val" could
be uninitialized if function regmap_read() returns -EINVAL.
However, it will be used as index in the later context, which
could potentially be unsafe.

Signed-off-by: Yizhuo <yzhai003@ucr.edu>
---
 drivers/clk/clk-gemini.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk-gemini.c b/drivers/clk/clk-gemini.c
index 5e66e6c0205e..07e1b551d1d9 100644
--- a/drivers/clk/clk-gemini.c
+++ b/drivers/clk/clk-gemini.c
@@ -314,7 +314,10 @@ static int gemini_clk_probe(struct platform_device *pdev)
 	gemini_clk_data->hws[GEMINI_CLK_RTC] = hw;
 
 	/* CPU clock derived as a fixed ratio from the AHB clock */
-	regmap_read(map, GEMINI_GLOBAL_STATUS, &val);
+	ret = regmap_read(map, GEMINI_GLOBAL_STATUS, &val);
+	if (ret)
+		return ret;
+
 	val >>= CPU_AHB_RATIO_SHIFT;
 	val &= CPU_AHB_RATIO_MASK;
 	hw = clk_hw_register_fixed_factor(NULL, "cpu", "ahb", 0,
@@ -323,7 +326,10 @@ static int gemini_clk_probe(struct platform_device *pdev)
 	gemini_clk_data->hws[GEMINI_CLK_CPU] = hw;
 
 	/* Security clock is 1:1 or 0.75 of APB */
-	regmap_read(map, GEMINI_GLOBAL_CLOCK_CONTROL, &val);
+	ret = regmap_read(map, GEMINI_GLOBAL_CLOCK_CONTROL, &val);
+	if (ret)
+		return ret;
+
 	if (val & SECURITY_CLK_SEL) {
 		mult = 1;
 		div = 1;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] clk: gemini: Variable "val" in function gemini_clk_probe() could be uninitialized
  2019-01-27  5:10 [PATCH] clk: gemini: Variable "val" in function gemini_clk_probe() could be uninitialized Yizhuo
@ 2019-02-06 19:23 ` Stephen Boyd
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Boyd @ 2019-02-06 19:23 UTC (permalink / raw)
  To: Yizhuo
  Cc: csong, zhiyunq, Yizhuo, Michael Turquette, Stephen Boyd,
	linux-clk, linux-kernel

Quoting Yizhuo (2019-01-26 21:10:12)
> In function gemini_clk_probe(), local variable "val" could
> be uninitialized if function regmap_read() returns -EINVAL.
> However, it will be used as index in the later context, which
> could potentially be unsafe.

Ok. How did you find this? Any pointers?

> 
> Signed-off-by: Yizhuo <yzhai003@ucr.edu>
> ---
>  drivers/clk/clk-gemini.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)

There are other locations in this file where 'val' is used even if
regmap_read() fails. For example gemini_pci_recalc_rate() does this. Can
you fix all the callers in this file? Presumably nobody cares that this
API could fail in this driver because it's a thin wrapper around mmio
read that never fails. Maybe we could have a comment instead that this
is the case and then ignore this patch entirely.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-27  5:10 [PATCH] clk: gemini: Variable "val" in function gemini_clk_probe() could be uninitialized Yizhuo
2019-02-06 19:23 ` Stephen Boyd

Linux-Clk Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-clk/0 linux-clk/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-clk linux-clk/ https://lore.kernel.org/linux-clk \
		linux-clk@vger.kernel.org linux-clk@archiver.kernel.org
	public-inbox-index linux-clk


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-clk


AGPL code for this site: git clone https://public-inbox.org/ public-inbox