* [PATCH] net: stmmac: Variable "val" in function sun8i_dwmac_set_syscon() could be uninitialized
@ 2019-02-07 17:46 Yizhuo
2019-02-08 7:44 ` Maxime Ripard
2019-02-09 7:01 ` David Miller
0 siblings, 2 replies; 12+ messages in thread
From: Yizhuo @ 2019-02-07 17:46 UTC (permalink / raw)
Cc: csong, zhiyunq, Yizhuo, Giuseppe Cavallaro, Alexandre Torgue,
Maxime Ripard, Chen-Yu Tsai, netdev, linux-arm-kernel,
linux-kernel
In function sun8i_dwmac_set_syscon(), local variable "val" could
be uninitialized if function regmap_read() returns -EINVAL.
However, it will be used directly in the if statement, which
is potentially unsafe.
Signed-off-by: Yizhuo <yzhai003@ucr.edu>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 39c2122a4f26..50cfd6d83052 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -641,7 +641,12 @@ static int sun8i_dwmac_set_syscon(struct stmmac_priv *priv)
int ret;
u32 reg, val;
- regmap_read(gmac->regmap, SYSCON_EMAC_REG, &val);
+ ret = regmap_read(gmac->regmap, SYSCON_EMAC_REG, &val);
+ if (ret) {
+ dev_err(priv->device, "Fail to read SYSCON_EMAC_REG.\n");
+ return ret;
+ }
+
reg = gmac->variant->default_syscon_value;
if (reg != val)
dev_warn(priv->device,
--
2.17.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] net: stmmac: Variable "val" in function sun8i_dwmac_set_syscon() could be uninitialized
2019-02-07 17:46 [PATCH] net: stmmac: Variable "val" in function sun8i_dwmac_set_syscon() could be uninitialized Yizhuo
@ 2019-02-08 7:44 ` Maxime Ripard
2019-02-09 7:01 ` David Miller
1 sibling, 0 replies; 12+ messages in thread
From: Maxime Ripard @ 2019-02-08 7:44 UTC (permalink / raw)
To: Yizhuo
Cc: csong, zhiyunq, Giuseppe Cavallaro, Alexandre Torgue,
Chen-Yu Tsai, netdev, linux-arm-kernel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 491 bytes --]
On Thu, Feb 07, 2019 at 09:46:23AM -0800, Yizhuo wrote:
> In function sun8i_dwmac_set_syscon(), local variable "val" could
> be uninitialized if function regmap_read() returns -EINVAL.
> However, it will be used directly in the if statement, which
> is potentially unsafe.
>
> Signed-off-by: Yizhuo <yzhai003@ucr.edu>
Acked-by: Maxime Ripard <maxime.ripard@bootlin.com>
Thanks!
Maxime
--
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] net: stmmac: Variable "val" in function sun8i_dwmac_set_syscon() could be uninitialized
2019-02-07 17:46 [PATCH] net: stmmac: Variable "val" in function sun8i_dwmac_set_syscon() could be uninitialized Yizhuo
2019-02-08 7:44 ` Maxime Ripard
@ 2019-02-09 7:01 ` David Miller
2019-08-30 22:29 ` Yizhuo Zhai
1 sibling, 1 reply; 12+ messages in thread
From: David Miller @ 2019-02-09 7:01 UTC (permalink / raw)
To: yzhai003
Cc: csong, zhiyunq, peppe.cavallaro, alexandre.torgue, maxime.ripard,
wens, netdev, linux-arm-kernel, linux-kernel
From: Yizhuo <yzhai003@ucr.edu>
Date: Thu, 7 Feb 2019 09:46:23 -0800
> In function sun8i_dwmac_set_syscon(), local variable "val" could
> be uninitialized if function regmap_read() returns -EINVAL.
> However, it will be used directly in the if statement, which
> is potentially unsafe.
>
> Signed-off-by: Yizhuo <yzhai003@ucr.edu>
This doesn't apply to any of my trees.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] net: stmmac: Variable "val" in function sun8i_dwmac_set_syscon() could be uninitialized
2019-02-09 7:01 ` David Miller
@ 2019-08-30 22:29 ` Yizhuo Zhai
2019-08-31 0:37 ` David Miller
0 siblings, 1 reply; 12+ messages in thread
From: Yizhuo Zhai @ 2019-08-30 22:29 UTC (permalink / raw)
To: David Miller
Cc: Chengyu Song, Zhiyun Qian, Giuseppe Cavallaro, Alexandre Torgue,
Maxime Ripard, Chen-Yu Tsai, netdev, linux-arm-kernel,
linux-kernel
Hi David:
Thanks for your feedback, this patch should work for v4.14.
On Fri, Feb 8, 2019 at 11:01 PM David Miller <davem@davemloft.net> wrote:
>
> From: Yizhuo <yzhai003@ucr.edu>
> Date: Thu, 7 Feb 2019 09:46:23 -0800
>
> > In function sun8i_dwmac_set_syscon(), local variable "val" could
> > be uninitialized if function regmap_read() returns -EINVAL.
> > However, it will be used directly in the if statement, which
> > is potentially unsafe.
> >
> > Signed-off-by: Yizhuo <yzhai003@ucr.edu>
>
> This doesn't apply to any of my trees.
--
Kind Regards,
Yizhuo Zhai
Computer Science, Graduate Student
University of California, Riverside
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] net: stmmac: Variable "val" in function sun8i_dwmac_set_syscon() could be uninitialized
2019-08-30 22:29 ` Yizhuo Zhai
@ 2019-08-31 0:37 ` David Miller
0 siblings, 0 replies; 12+ messages in thread
From: David Miller @ 2019-08-31 0:37 UTC (permalink / raw)
To: yzhai003
Cc: csong, zhiyunq, peppe.cavallaro, alexandre.torgue, maxime.ripard,
wens, netdev, linux-arm-kernel, linux-kernel
From: Yizhuo Zhai <yzhai003@ucr.edu>
Date: Fri, 30 Aug 2019 15:29:07 -0700
> Thanks for your feedback, this patch should work for v4.14.
You must always submit patches against the current tree.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH] net: stmmac: Variable "val" in function sun8i_dwmac_set_syscon() could be uninitialized
@ 2019-02-05 22:15 Yizhuo
2019-02-06 9:18 ` Maxime Ripard
2019-02-07 4:17 ` David Miller
0 siblings, 2 replies; 12+ messages in thread
From: Yizhuo @ 2019-02-05 22:15 UTC (permalink / raw)
Cc: csong, zhiyunq, Yizhuo, Giuseppe Cavallaro, Alexandre Torgue,
Maxime Ripard, Chen-Yu Tsai, netdev, linux-arm-kernel,
linux-kernel
In function sun8i_dwmac_set_syscon(), local variable "val" could
be uninitialized if function regmap_read() returns -EINVAL.
However, it will be used directly in the if statement, which
is potentially unsafe.
Signed-off-by: Yizhuo <yzhai003@ucr.edu>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 39c2122a4f26..11d481c9e7ab 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -639,9 +639,14 @@ static int sun8i_dwmac_set_syscon(struct stmmac_priv *priv)
struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
struct device_node *node = priv->device->of_node;
int ret;
- u32 reg, val;
+ u32 reg, val = 0;
+
+ ret = regmap_read(gmac->regmap, SYSCON_EMAC_REG, &val);
+ if (ret) {
+ dev_err(priv->device, "Fail to read SYSCON_EMAC_REG.\n");
+ return ret;
+ }
- regmap_read(gmac->regmap, SYSCON_EMAC_REG, &val);
reg = gmac->variant->default_syscon_value;
if (reg != val)
dev_warn(priv->device,
--
2.17.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] net: stmmac: Variable "val" in function sun8i_dwmac_set_syscon() could be uninitialized
2019-02-05 22:15 Yizhuo
@ 2019-02-06 9:18 ` Maxime Ripard
2019-02-07 4:17 ` David Miller
1 sibling, 0 replies; 12+ messages in thread
From: Maxime Ripard @ 2019-02-06 9:18 UTC (permalink / raw)
To: Yizhuo
Cc: csong, zhiyunq, Giuseppe Cavallaro, Alexandre Torgue,
Chen-Yu Tsai, netdev, linux-arm-kernel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1171 bytes --]
Hi,
On Tue, Feb 05, 2019 at 02:15:59PM -0800, Yizhuo wrote:
> In function sun8i_dwmac_set_syscon(), local variable "val" could
> be uninitialized if function regmap_read() returns -EINVAL.
> However, it will be used directly in the if statement, which
> is potentially unsafe.
>
> Signed-off-by: Yizhuo <yzhai003@ucr.edu>
> ---
> drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 39c2122a4f26..11d481c9e7ab 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> @@ -639,9 +639,14 @@ static int sun8i_dwmac_set_syscon(struct stmmac_priv *priv)
> struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
> struct device_node *node = priv->device->of_node;
> int ret;
> - u32 reg, val;
> + u32 reg, val = 0;
I guess we don't need to initialize it anymore with the check you add?
Maxime
--
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] net: stmmac: Variable "val" in function sun8i_dwmac_set_syscon() could be uninitialized
2019-02-05 22:15 Yizhuo
2019-02-06 9:18 ` Maxime Ripard
@ 2019-02-07 4:17 ` David Miller
[not found] ` <CABvMjLQ6MYtGYeLxwceZsvcyn4oScgMo+BGQMHw7SkZ1uxFmHQ@mail.gmail.com>
1 sibling, 1 reply; 12+ messages in thread
From: David Miller @ 2019-02-07 4:17 UTC (permalink / raw)
To: yzhai003
Cc: csong, zhiyunq, peppe.cavallaro, alexandre.torgue, maxime.ripard,
wens, netdev, linux-arm-kernel, linux-kernel
From: Yizhuo <yzhai003@ucr.edu>
Date: Tue, 5 Feb 2019 14:15:59 -0800
> @@ -639,9 +639,14 @@ static int sun8i_dwmac_set_syscon(struct stmmac_priv *priv)
> struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
> struct device_node *node = priv->device->of_node;
> int ret;
> - u32 reg, val;
> + u32 reg, val = 0;
> +
> + ret = regmap_read(gmac->regmap, SYSCON_EMAC_REG, &val);
> + if (ret) {
> + dev_err(priv->device, "Fail to read SYSCON_EMAC_REG.\n");
> + return ret;
> + }
I agree with the other reviewer that since you check 'ret' the initialization of
'val' is no longer needed.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2019-08-31 0:37 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-07 17:46 [PATCH] net: stmmac: Variable "val" in function sun8i_dwmac_set_syscon() could be uninitialized Yizhuo
2019-02-08 7:44 ` Maxime Ripard
2019-02-09 7:01 ` David Miller
2019-08-30 22:29 ` Yizhuo Zhai
2019-08-31 0:37 ` David Miller
-- strict thread matches above, loose matches on Subject: below --
2019-02-05 22:15 Yizhuo
2019-02-06 9:18 ` Maxime Ripard
2019-02-07 4:17 ` David Miller
[not found] ` <CABvMjLQ6MYtGYeLxwceZsvcyn4oScgMo+BGQMHw7SkZ1uxFmHQ@mail.gmail.com>
2019-02-07 5:53 ` Yizhuo Zhai
2019-02-07 9:24 ` Maxime Ripard
2019-02-07 17:48 ` Yizhuo Zhai
2019-02-07 17:53 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).