All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] net: pfe_eth: Fix resoure leak in pfe_spi_flash_init
@ 2020-09-11 11:06 Kuldeep Singh
  2020-09-11 11:06 ` [PATCH 2/2] net: pfe_eth: Remove non-DM code check from pfe_spi_flash_init Kuldeep Singh
  2020-09-18 13:42 ` [PATCH 1/2] net: pfe_eth: Fix resoure leak in pfe_spi_flash_init Priyanka Jain
  0 siblings, 2 replies; 3+ messages in thread
From: Kuldeep Singh @ 2020-09-11 11:06 UTC (permalink / raw)
  To: u-boot

Fix Coverity issue: RESOURCE_LEAK.
leaked_storage: Variable addr going out of scope leaks the storage it
points to.

Fixes: e0152dbed683 ("net: pfe_eth: Use spi_flash_read API to access
flash memory")
Signed-off-by: Kuldeep Singh <kuldeep.singh@nxp.com>
---
 drivers/net/pfe_eth/pfe_firmware.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/pfe_eth/pfe_firmware.c b/drivers/net/pfe_eth/pfe_firmware.c
index 55e661c..4ad09dd 100644
--- a/drivers/net/pfe_eth/pfe_firmware.c
+++ b/drivers/net/pfe_eth/pfe_firmware.c
@@ -170,6 +170,9 @@ int pfe_spi_flash_init(void)
 	int ret = 0;
 	void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH);
 
+	if (!addr)
+		return -ENOMEM;
+
 #ifdef CONFIG_DM_SPI_FLASH
 	struct udevice *new;
 
@@ -186,6 +189,7 @@ int pfe_spi_flash_init(void)
 #endif
 	if (!pfe_flash) {
 		printf("SF: probe for pfe failed\n");
+		free(addr);
 		return -ENODEV;
 	}
 
-- 
2.7.4

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

* [PATCH 2/2] net: pfe_eth: Remove non-DM code check from pfe_spi_flash_init
  2020-09-11 11:06 [PATCH 1/2] net: pfe_eth: Fix resoure leak in pfe_spi_flash_init Kuldeep Singh
@ 2020-09-11 11:06 ` Kuldeep Singh
  2020-09-18 13:42 ` [PATCH 1/2] net: pfe_eth: Fix resoure leak in pfe_spi_flash_init Priyanka Jain
  1 sibling, 0 replies; 3+ messages in thread
From: Kuldeep Singh @ 2020-09-11 11:06 UTC (permalink / raw)
  To: u-boot

CONFIG_DM_SPI_FLASH is only supported now with passing of driver
conversion deadline from non-DM to DM model. Hence, it's safe to remove
non-DM code check from pfe_spi_flash_init.

Also use CONFIG_ENV_SPI_MODE and CONFIG_ENV_SPI_MAX_HZ instead of
reading reading values from DT.

Signed-off-by: Kuldeep Singh <kuldeep.singh@nxp.com>
---
 drivers/net/pfe_eth/pfe_firmware.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/net/pfe_eth/pfe_firmware.c b/drivers/net/pfe_eth/pfe_firmware.c
index 4ad09dd..d414c75 100644
--- a/drivers/net/pfe_eth/pfe_firmware.c
+++ b/drivers/net/pfe_eth/pfe_firmware.c
@@ -167,26 +167,20 @@ static int pfe_fit_check(void)
 int pfe_spi_flash_init(void)
 {
 	struct spi_flash *pfe_flash;
+	struct udevice *new;
 	int ret = 0;
 	void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH);
 
 	if (!addr)
 		return -ENOMEM;
 
-#ifdef CONFIG_DM_SPI_FLASH
-	struct udevice *new;
-
-	/* speed and mode will be read from DT */
 	ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS,
-				     CONFIG_ENV_SPI_CS, 0, 0, &new);
+				     CONFIG_ENV_SPI_CS,
+				     CONFIG_ENV_SPI_MAX_HZ,
+				     CONFIG_ENV_SPI_MODE,
+				     &new);
 
 	pfe_flash = dev_get_uclass_priv(new);
-#else
-	pfe_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS,
-				    CONFIG_ENV_SPI_CS,
-				    CONFIG_ENV_SPI_MAX_HZ,
-				    CONFIG_ENV_SPI_MODE);
-#endif
 	if (!pfe_flash) {
 		printf("SF: probe for pfe failed\n");
 		free(addr);
-- 
2.7.4

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

* [PATCH 1/2] net: pfe_eth: Fix resoure leak in pfe_spi_flash_init
  2020-09-11 11:06 [PATCH 1/2] net: pfe_eth: Fix resoure leak in pfe_spi_flash_init Kuldeep Singh
  2020-09-11 11:06 ` [PATCH 2/2] net: pfe_eth: Remove non-DM code check from pfe_spi_flash_init Kuldeep Singh
@ 2020-09-18 13:42 ` Priyanka Jain
  1 sibling, 0 replies; 3+ messages in thread
From: Priyanka Jain @ 2020-09-18 13:42 UTC (permalink / raw)
  To: u-boot

>-----Original Message-----
>From: Kuldeep Singh <kuldeep.singh@nxp.com>
>Sent: Friday, September 11, 2020 4:37 PM
>To: u-boot at lists.denx.de
>Cc: Priyanka Jain <priyanka.jain@nxp.com>; Ashish Kumar
><ashish.kumar@nxp.com>; Kuldeep Singh <kuldeep.singh@nxp.com>
>Subject: [PATCH 1/2] net: pfe_eth: Fix resoure leak in pfe_spi_flash_init
>
>Fix Coverity issue: RESOURCE_LEAK.
>leaked_storage: Variable addr going out of scope leaks the storage it points to.
>
>Fixes: e0152dbed683 ("net: pfe_eth: Use spi_flash_read API to access flash
>memory")
>Signed-off-by: Kuldeep Singh <kuldeep.singh@nxp.com>
>---
> drivers/net/pfe_eth/pfe_firmware.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
>diff --git a/drivers/net/pfe_eth/pfe_firmware.c
>b/drivers/net/pfe_eth/pfe_firmware.c
>index 55e661c..4ad09dd 100644
>--- a/drivers/net/pfe_eth/pfe_firmware.c
>+++ b/drivers/net/pfe_eth/pfe_firmware.c
>@@ -170,6 +170,9 @@ int pfe_spi_flash_init(void)
> 	int ret = 0;
> 	void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH);
>
>+	if (!addr)
>+		return -ENOMEM;
>+
> #ifdef CONFIG_DM_SPI_FLASH
> 	struct udevice *new;
>
>@@ -186,6 +189,7 @@ int pfe_spi_flash_init(void)  #endif
> 	if (!pfe_flash) {
> 		printf("SF: probe for pfe failed\n");
>+		free(addr);
> 		return -ENODEV;
> 	}
>
>--
>2.7.4
Reviewed-by: Priyanka Jain <priyanka.jain@nxp.com>

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

end of thread, other threads:[~2020-09-18 13:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-11 11:06 [PATCH 1/2] net: pfe_eth: Fix resoure leak in pfe_spi_flash_init Kuldeep Singh
2020-09-11 11:06 ` [PATCH 2/2] net: pfe_eth: Remove non-DM code check from pfe_spi_flash_init Kuldeep Singh
2020-09-18 13:42 ` [PATCH 1/2] net: pfe_eth: Fix resoure leak in pfe_spi_flash_init Priyanka Jain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.