2018-10-09 20:44:26

by Gustavo A. R. Silva

[permalink] [raw]
Subject: [PATCH net-next 0/2] fix signedness bug and memory leak in mscc driver

This patchset aims to fix a signedness bug in function
vsc85xx_downshift_get() and a memory leak in function
vsc8574_config_pre_init().

Thanks

Gustavo A. R. Silva (2):
net: phy: mscc: fix signedness bug in vsc85xx_downshift_get
net: phy: mscc: fix memory leak in vsc8574_config_pre_init

drivers/net/phy/mscc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

--
2.7.4



2018-10-09 19:42:31

by Gustavo A. R. Silva

[permalink] [raw]
Subject: [PATCH net-next 2/2] net: phy: mscc: fix memory leak in vsc8574_config_pre_init

In case memory resources for *fw* were successfully allocated,
release them before return.

Addresses-Coverity-ID: 1473968 ("Resource leak")
Fixes: 00d70d8e0e78 ("net: phy: mscc: add support for VSC8574 PHY")
Signed-off-by: Gustavo A. R. Silva <[email protected]>
---
drivers/net/phy/mscc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/mscc.c b/drivers/net/phy/mscc.c
index bff56c3..af9fb2d 100644
--- a/drivers/net/phy/mscc.c
+++ b/drivers/net/phy/mscc.c
@@ -1292,7 +1292,7 @@ static int vsc8574_config_pre_init(struct phy_device *phydev)
dev_err(dev,
"%s: failed to assert reset of micro\n",
__func__);
- return ret;
+ goto release_fw;
}
}
} else {
@@ -1338,7 +1338,7 @@ static int vsc8574_config_pre_init(struct phy_device *phydev)

out:
phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
-
+release_fw:
release_firmware(fw);

return ret;
--
2.7.4


2018-10-09 20:45:07

by Gustavo A. R. Silva

[permalink] [raw]
Subject: [PATCH net-next 1/2] net: phy: mscc: fix signedness bug in vsc85xx_downshift_get

Currently, the error handling for the call to function
phy_read_paged() doesn't work because *reg_val* is of
type u16 (16 bits, unsigned), which makes it impossible
for it to hold a value less than 0.

Fix this by changing the type of variable *reg_val* to int.

Addresses-Coverity-ID: 1473970 ("Unsigned compared against 0")
Fixes: 6a0bfbbe20b0 ("net: phy: mscc: migrate to phy_select/restore_page functions")
Signed-off-by: Gustavo A. R. Silva <[email protected]>
---
drivers/net/phy/mscc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/phy/mscc.c b/drivers/net/phy/mscc.c
index bffe077..bff56c3 100644
--- a/drivers/net/phy/mscc.c
+++ b/drivers/net/phy/mscc.c
@@ -522,7 +522,7 @@ static int vsc85xx_mdix_set(struct phy_device *phydev, u8 mdix)

static int vsc85xx_downshift_get(struct phy_device *phydev, u8 *count)
{
- u16 reg_val;
+ int reg_val;

reg_val = phy_read_paged(phydev, MSCC_PHY_PAGE_EXTENDED,
MSCC_PHY_ACTIPHY_CNTL);
--
2.7.4


2018-10-10 06:49:53

by Quentin Schulz

[permalink] [raw]
Subject: Re: [PATCH net-next 2/2] net: phy: mscc: fix memory leak in vsc8574_config_pre_init

Hi Gustavo,

On Tue, Oct 09, 2018 at 09:39:53PM +0200, Gustavo A. R. Silva wrote:
> In case memory resources for *fw* were successfully allocated,
> release them before return.
>
> Addresses-Coverity-ID: 1473968 ("Resource leak")
> Fixes: 00d70d8e0e78 ("net: phy: mscc: add support for VSC8574 PHY")
> Signed-off-by: Gustavo A. R. Silva <[email protected]>
> ---
> drivers/net/phy/mscc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/phy/mscc.c b/drivers/net/phy/mscc.c
> index bff56c3..af9fb2d 100644
> --- a/drivers/net/phy/mscc.c
> +++ b/drivers/net/phy/mscc.c
> @@ -1292,7 +1292,7 @@ static int vsc8574_config_pre_init(struct phy_device *phydev)
> dev_err(dev,
> "%s: failed to assert reset of micro\n",
> __func__);
> - return ret;
> + goto release_fw;
> }
> }
> } else {
> @@ -1338,7 +1338,7 @@ static int vsc8574_config_pre_init(struct phy_device *phydev)
>
> out:
> phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
> -
> +release_fw:
> release_firmware(fw);

You can reuse the out goto label instead, I would like all functions in
the driver to exit with the PHY set to access the standard page.

Thanks,
Quentin


Attachments:
(No filename) (1.24 kB)
signature.asc (849.00 B)
Download all attachments

2018-10-10 06:59:37

by Quentin Schulz

[permalink] [raw]
Subject: Re: [PATCH net-next 1/2] net: phy: mscc: fix signedness bug in vsc85xx_downshift_get

Hi Gustavo,

On Tue, Oct 09, 2018 at 09:38:33PM +0200, Gustavo A. R. Silva wrote:
> Currently, the error handling for the call to function
> phy_read_paged() doesn't work because *reg_val* is of
> type u16 (16 bits, unsigned), which makes it impossible
> for it to hold a value less than 0.
>

Ah, rookie mistake! I should have run Coccinelle on the patches.

> Fix this by changing the type of variable *reg_val* to int.
>
> Addresses-Coverity-ID: 1473970 ("Unsigned compared against 0")
> Fixes: 6a0bfbbe20b0 ("net: phy: mscc: migrate to phy_select/restore_page functions")

Reviewed-by: Quentin Schulz <[email protected]>

Thanks!
Quentin


Attachments:
(No filename) (673.00 B)
signature.asc (849.00 B)
Download all attachments

2018-10-10 08:28:18

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH net-next 2/2] net: phy: mscc: fix memory leak in vsc8574_config_pre_init

Hey Quentin,

On 10/10/18 8:49 AM, Quentin Schulz wrote:

>>
>> out:
>> phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
>> -
>> +release_fw:
>> release_firmware(fw);
>
> You can reuse the out goto label instead, I would like all functions in
> the driver to exit with the PHY set to access the standard page.
>

Oh okay. I've got it.

I'll send v2 shortly.

Thanks for the feedback.
--
Gustavo