2019-02-06 03:35:04

by Yizhuo Zhai

[permalink] [raw]
Subject: [PATCH] phy: Variable "val" in function miphy_osc_is_ready() could be uninitialized

In function miphy_osc_is_ready(), local variable "val"
could be uninitalized. if function regmap_read() returns
-EINVAL. However, this value is used in if statement.
This is potentially unsafe.

Signed-off-by: Yizhuo <[email protected]>
---
drivers/phy/st/phy-miphy28lp.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/st/phy-miphy28lp.c b/drivers/phy/st/phy-miphy28lp.c
index 213e2e15339c..40c7c0a611a0 100644
--- a/drivers/phy/st/phy-miphy28lp.c
+++ b/drivers/phy/st/phy-miphy28lp.c
@@ -835,7 +835,8 @@ static int miphy_osc_is_ready(struct miphy28lp_phy *miphy_phy)
{
struct miphy28lp_dev *miphy_dev = miphy_phy->phydev;
unsigned long finish = jiffies + 5 * HZ;
- u32 val;
+ u32 val = 0;
+ int ret;

if (!miphy_phy->osc_rdy)
return 0;
@@ -844,8 +845,10 @@ static int miphy_osc_is_ready(struct miphy28lp_phy *miphy_phy)
return -EINVAL;

do {
- regmap_read(miphy_dev->regmap,
+ ret = regmap_read(miphy_dev->regmap,
miphy_phy->syscfg_reg[SYSCFG_STATUS], &val);
+ if (ret)
+ return ret;

if ((val & MIPHY_OSC_RDY) != MIPHY_OSC_RDY)
cpu_relax();
--
2.17.1



2019-02-06 08:40:58

by Patrice CHOTARD

[permalink] [raw]
Subject: Re: [PATCH] phy: Variable "val" in function miphy_osc_is_ready() could be uninitialized

Hi Yizhuo

On 2/6/19 4:30 AM, Yizhuo wrote:
> In function miphy_osc_is_ready(), local variable "val"
> could be uninitalized. if function regmap_read() returns
> -EINVAL. However, this value is used in if statement.
> This is potentially unsafe.
>
> Signed-off-by: Yizhuo <[email protected]>
> ---
> drivers/phy/st/phy-miphy28lp.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/phy/st/phy-miphy28lp.c b/drivers/phy/st/phy-miphy28lp.c
> index 213e2e15339c..40c7c0a611a0 100644
> --- a/drivers/phy/st/phy-miphy28lp.c
> +++ b/drivers/phy/st/phy-miphy28lp.c
> @@ -835,7 +835,8 @@ static int miphy_osc_is_ready(struct miphy28lp_phy *miphy_phy)
> {
> struct miphy28lp_dev *miphy_dev = miphy_phy->phydev;
> unsigned long finish = jiffies + 5 * HZ;
> - u32 val;
> + u32 val = 0;
> + int ret;
>
> if (!miphy_phy->osc_rdy)
> return 0;
> @@ -844,8 +845,10 @@ static int miphy_osc_is_ready(struct miphy28lp_phy *miphy_phy)
> return -EINVAL;
>
> do {
> - regmap_read(miphy_dev->regmap,
> + ret = regmap_read(miphy_dev->regmap,
> miphy_phy->syscfg_reg[SYSCFG_STATUS], &val);
> + if (ret)
> + return ret;
>
> if ((val & MIPHY_OSC_RDY) != MIPHY_OSC_RDY)
> cpu_relax();
>

Reviewed-by: Patrice Chotard <[email protected]>

Thanks

2019-02-06 11:55:42

by Kishon Vijay Abraham I

[permalink] [raw]
Subject: Re: [PATCH] phy: Variable "val" in function miphy_osc_is_ready() could be uninitialized

Hi Yizhuo,

On 06/02/19 9:00 AM, Yizhuo wrote:
> In function miphy_osc_is_ready(), local variable "val"
> could be uninitalized. if function regmap_read() returns
> -EINVAL. However, this value is used in if statement.
> This is potentially unsafe.
>
> Signed-off-by: Yizhuo <[email protected]>

Can you send all your fixes in a series?

Thanks
Kishon
> ---
> drivers/phy/st/phy-miphy28lp.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/phy/st/phy-miphy28lp.c b/drivers/phy/st/phy-miphy28lp.c
> index 213e2e15339c..40c7c0a611a0 100644
> --- a/drivers/phy/st/phy-miphy28lp.c
> +++ b/drivers/phy/st/phy-miphy28lp.c
> @@ -835,7 +835,8 @@ static int miphy_osc_is_ready(struct miphy28lp_phy *miphy_phy)
> {
> struct miphy28lp_dev *miphy_dev = miphy_phy->phydev;
> unsigned long finish = jiffies + 5 * HZ;
> - u32 val;
> + u32 val = 0;
> + int ret;
>
> if (!miphy_phy->osc_rdy)
> return 0;
> @@ -844,8 +845,10 @@ static int miphy_osc_is_ready(struct miphy28lp_phy *miphy_phy)
> return -EINVAL;
>
> do {
> - regmap_read(miphy_dev->regmap,
> + ret = regmap_read(miphy_dev->regmap,
> miphy_phy->syscfg_reg[SYSCFG_STATUS], &val);
> + if (ret)
> + return ret;
>
> if ((val & MIPHY_OSC_RDY) != MIPHY_OSC_RDY)
> cpu_relax();
>