Linux-ARM-Kernel Archive on lore.kernel.org
 help / Atom feed
* [PATCH] phy: Variable "caldone" in function rockchip_emmc_phy_power() could be uninitialized
@ 2019-02-06  1:47 Yizhuo
  2019-02-12 10:47 ` Heiko Stübner
  0 siblings, 1 reply; 2+ messages in thread
From: Yizhuo @ 2019-02-06  1:47 UTC (permalink / raw)
  Cc: csong, Heiko Stuebner, zhiyunq, linux-kernel,
	Kishon Vijay Abraham I, Yizhuo, linux-rockchip, linux-arm-kernel

In function rockchip_emmc_phy_power(), local variable "caldone"
could be uninitialized if function regmap_read() returns -EINVAL.
However, it will be used directly in the later context, which
is potentially unsafe.

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

diff --git a/drivers/phy/rockchip/phy-rockchip-emmc.c b/drivers/phy/rockchip/phy-rockchip-emmc.c
index f1b24f18e9b2..ca921ae08309 100644
--- a/drivers/phy/rockchip/phy-rockchip-emmc.c
+++ b/drivers/phy/rockchip/phy-rockchip-emmc.c
@@ -85,11 +85,12 @@ struct rockchip_emmc_phy {
 static int rockchip_emmc_phy_power(struct phy *phy, bool on_off)
 {
 	struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy);
-	unsigned int caldone;
+	unsigned int caldone = 0;
 	unsigned int dllrdy;
 	unsigned int freqsel = PHYCTRL_FREQSEL_200M;
 	unsigned long rate;
 	unsigned long timeout;
+	int err;
 
 	/*
 	 * Keep phyctrl_pdb and phyctrl_endll low to allow
@@ -164,9 +165,14 @@ static int rockchip_emmc_phy_power(struct phy *phy, bool on_off)
 	 * wait 5us for calpad busy trimming
 	 */
 	udelay(5);
-	regmap_read(rk_phy->reg_base,
+	err = regmap_read(rk_phy->reg_base,
 		    rk_phy->reg_offset + GRF_EMMCPHY_STATUS,
 		    &caldone);
+	if (err) {
+		pr_err("Failed to read status.\n");
+		return err;
+	}
+
 	caldone = (caldone >> PHYCTRL_CALDONE_SHIFT) & PHYCTRL_CALDONE_MASK;
 	if (caldone != PHYCTRL_CALDONE_DONE) {
 		pr_err("rockchip_emmc_phy_power: caldone timeout.\n");
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] phy: Variable "caldone" in function rockchip_emmc_phy_power() could be uninitialized
  2019-02-06  1:47 [PATCH] phy: Variable "caldone" in function rockchip_emmc_phy_power() could be uninitialized Yizhuo
@ 2019-02-12 10:47 ` Heiko Stübner
  0 siblings, 0 replies; 2+ messages in thread
From: Heiko Stübner @ 2019-02-12 10:47 UTC (permalink / raw)
  To: Yizhuo
  Cc: csong, zhiyunq, linux-kernel, Kishon Vijay Abraham I,
	linux-rockchip, linux-arm-kernel

Am Mittwoch, 6. Februar 2019, 02:47:33 CET schrieb Yizhuo:
> In function rockchip_emmc_phy_power(), local variable "caldone"
> could be uninitialized if function regmap_read() returns -EINVAL.
> However, it will be used directly in the later context, which
> is potentially unsafe.
> 
> Signed-off-by: Yizhuo <yzhai003@ucr.edu>
> ---
>  drivers/phy/rockchip/phy-rockchip-emmc.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/phy/rockchip/phy-rockchip-emmc.c
> b/drivers/phy/rockchip/phy-rockchip-emmc.c index f1b24f18e9b2..ca921ae08309
> 100644
> --- a/drivers/phy/rockchip/phy-rockchip-emmc.c
> +++ b/drivers/phy/rockchip/phy-rockchip-emmc.c
> @@ -85,11 +85,12 @@ struct rockchip_emmc_phy {
>  static int rockchip_emmc_phy_power(struct phy *phy, bool on_off)
>  {
>  	struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy);
> -	unsigned int caldone;
> +	unsigned int caldone = 0;

hmm, this may hide actual uninitialized uses in the future?
With the added error handling below, there shouldn't be a case
where caldone might be used uninitialized still?


Heiko

>  	unsigned int dllrdy;
>  	unsigned int freqsel = PHYCTRL_FREQSEL_200M;
>  	unsigned long rate;
>  	unsigned long timeout;
> +	int err;
> 
>  	/*
>  	 * Keep phyctrl_pdb and phyctrl_endll low to allow
> @@ -164,9 +165,14 @@ static int rockchip_emmc_phy_power(struct phy *phy,
> bool on_off) * wait 5us for calpad busy trimming
>  	 */
>  	udelay(5);
> -	regmap_read(rk_phy->reg_base,
> +	err = regmap_read(rk_phy->reg_base,
>  		    rk_phy->reg_offset + GRF_EMMCPHY_STATUS,
>  		    &caldone);
> +	if (err) {
> +		pr_err("Failed to read status.\n");
> +		return err;
> +	}
> +
>  	caldone = (caldone >> PHYCTRL_CALDONE_SHIFT) & PHYCTRL_CALDONE_MASK;
>  	if (caldone != PHYCTRL_CALDONE_DONE) {
>  		pr_err("rockchip_emmc_phy_power: caldone timeout.\n");





_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ 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-02-06  1:47 [PATCH] phy: Variable "caldone" in function rockchip_emmc_phy_power() could be uninitialized Yizhuo
2019-02-12 10:47 ` Heiko Stübner

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.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-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org infradead-linux-arm-kernel@archiver.kernel.org
	public-inbox-index linux-arm-kernel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


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