mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/14] Smatch warning fixups
@ 2014-02-07  8:48 Lucas Stach
  2014-02-07  8:48 ` [PATCH 01/14] remove redundant NULL check on free Lucas Stach
                   ` (14 more replies)
  0 siblings, 15 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

I've run smatch over a imx_v7_defconfig build
and fixed the resulting warnings.

Some of them are just minor issues with no
real impact, but some of them are real potential
problems or even real bugs.

Lucas Stach (14):
  remove redundant NULL check on free
  commands: edit: properly propagate error code
  common: env: properly propagate error code
  clk: imx: unsigned mfn is never less than zero
  lib: math: fix return path (numstack may be NULL)
  lib: libbb: f should never be NULL
  comamnds: uimage: actually print error message
  usb: ulpi: fix logic-op
  usb: dfu: fix error path to avoid NULL ptr deref
  net: usb: smsc95xx: fix wrong phy reset condition
  net: usb: asix: properly propagate error code
  mtd: core: avoid possible NULL ptr deref
  clk: avoid possible NULL ptr deref
  don't cast negative error codes to unsigned size_t

 arch/arm/mach-imx/clk-pllv1.c | 2 --
 commands/edit.c               | 2 +-
 commands/uimage.c             | 2 +-
 common/environment.c          | 5 ++---
 common/uimage.c               | 6 +++---
 drivers/clk/clkdev.c          | 8 +++++---
 drivers/eeprom/at25.c         | 3 +--
 drivers/mtd/core.c            | 3 ++-
 drivers/net/usb/asix.c        | 4 ++--
 drivers/net/usb/smsc95xx.c    | 2 +-
 drivers/usb/core/usb.c        | 3 +--
 drivers/usb/gadget/dfu.c      | 4 +++-
 drivers/usb/otg/ulpi.c        | 4 ++--
 include/image.h               | 2 +-
 lib/libbb.c                   | 2 +-
 lib/math.c                    | 4 ++--
 lib/parameter.c               | 3 +--
 net/eth.c                     | 2 +-
 18 files changed, 30 insertions(+), 31 deletions(-)

-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 01/14] remove redundant NULL check on free
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  8:48 ` [PATCH 02/14] commands: edit: properly propagate error code Lucas Stach
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

free() already checks the pointer to be non
NULL. No need to do it again.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 common/environment.c   | 3 +--
 drivers/eeprom/at25.c  | 3 +--
 drivers/usb/core/usb.c | 3 +--
 lib/parameter.c        | 3 +--
 net/eth.c              | 2 +-
 5 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/common/environment.c b/common/environment.c
index 6f06bfc..ab82103 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -371,8 +371,7 @@ skip:
 	ret = 0;
 out:
 	close(envfd);
-	if (buf_free)
-		free(buf_free);
+	free(buf_free);
 	return ret;
 }
 
diff --git a/drivers/eeprom/at25.c b/drivers/eeprom/at25.c
index 68b4710..0a099e1 100644
--- a/drivers/eeprom/at25.c
+++ b/drivers/eeprom/at25.c
@@ -294,8 +294,7 @@ static int at25_probe(struct device_d *dev)
 	return 0;
 
 fail:
-	if (at25)
-		free(at25);
+	free(at25);
 
 	return err;
 }
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 68a51d1..fe1ac02 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -504,8 +504,7 @@ int usb_host_detect(struct usb_host *host, int force)
 
 		list_del(&dev->list);
 		unregister_device(&dev->dev);
-		if (dev->hub)
-			free(dev->hub);
+		free(dev->hub);
 		dma_free(dev->setup_packet);
 		dma_free(dev->descriptor);
 		free(dev);
diff --git a/lib/parameter.c b/lib/parameter.c
index c5c6426..a0bae3e 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -108,8 +108,7 @@ int dev_set_param(struct device_d *dev, const char *name, const char *val)
 int dev_param_set_generic(struct device_d *dev, struct param_d *p,
 		const char *val)
 {
-	if (p->value)
-		free(p->value);
+	free(p->value);
 	if (!val) {
 		p->value = NULL;
 		return 0;
diff --git a/net/eth.c b/net/eth.c
index 37dd9e0..cb59e76 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -382,7 +382,7 @@ void eth_unregister(struct eth_device *edev)
 
 	dev_remove_parameters(&edev->dev);
 
-	if (IS_ENABLED(CONFIG_OFDEVICE) && edev->nodepath)
+	if (IS_ENABLED(CONFIG_OFDEVICE))
 		free(edev->nodepath);
 
 	unregister_device(&edev->dev);
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 02/14] commands: edit: properly propagate error code
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
  2014-02-07  8:48 ` [PATCH 01/14] remove redundant NULL check on free Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  8:48 ` [PATCH 03/14] common: env: " Lucas Stach
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 commands/edit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/edit.c b/commands/edit.c
index 295d0a7..6b34101 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -266,7 +266,7 @@ static int save_file(const char *path)
 	fd = open(path, O_WRONLY | O_TRUNC | O_CREAT);
 	if (fd < 0) {
 		printf("could not open file for writing: %s\n", errno_str());
-		return -1;
+		return fd;
 	}
 
 	line = buffer;
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 03/14] common: env: properly propagate error code
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
  2014-02-07  8:48 ` [PATCH 01/14] remove redundant NULL check on free Lucas Stach
  2014-02-07  8:48 ` [PATCH 02/14] commands: edit: properly propagate error code Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  8:48 ` [PATCH 04/14] clk: imx: unsigned mfn is never less than zero Lucas Stach
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 common/environment.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/environment.c b/common/environment.c
index ab82103..8b22edf 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -245,7 +245,7 @@ int envfs_load(const char *filename, char *dir, unsigned flags)
 	envfd = open(filename, O_RDONLY);
 	if (envfd < 0) {
 		printf("Open %s %s\n", filename, errno_str());
-		return -1;
+		return envfd;
 	}
 
 	/* read superblock */
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 04/14] clk: imx: unsigned mfn is never less than zero
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
                   ` (2 preceding siblings ...)
  2014-02-07  8:48 ` [PATCH 03/14] common: env: " Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  8:48 ` [PATCH 05/14] lib: math: fix return path (numstack may be NULL) Lucas Stach
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 arch/arm/mach-imx/clk-pllv1.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/arm/mach-imx/clk-pllv1.c b/arch/arm/mach-imx/clk-pllv1.c
index 6785da0..372ffb5 100644
--- a/arch/arm/mach-imx/clk-pllv1.c
+++ b/arch/arm/mach-imx/clk-pllv1.c
@@ -60,8 +60,6 @@ static unsigned long clk_pllv1_recalc_rate(struct clk *clk,
 	ll = (unsigned long long)freq * mfn_abs;
 
 	do_div(ll, mfd + 1);
-	if (mfn < 0)
-		ll = -ll;
 	ll = (freq * mfi) + ll;
 
 	return ll;
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 05/14] lib: math: fix return path (numstack may be NULL)
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
                   ` (3 preceding siblings ...)
  2014-02-07  8:48 ` [PATCH 04/14] clk: imx: unsigned mfn is never less than zero Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  8:48 ` [PATCH 06/14] lib: libbb: f should never be NULL Lucas Stach
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 lib/math.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/math.c b/lib/math.c
index a4731ed..2e53b09 100644
--- a/lib/math.c
+++ b/lib/math.c
@@ -546,8 +546,8 @@ static arith_t evaluate_string(arith_state_t *math_state, const char *expr)
 	arith_t result;
 
 	if (numstack == NULL || stack == NULL) {
-		errmsg = "out of memory";
-		goto err_with_custom_msg;
+		math_state->errmsg = "out of memory";
+		return -1;
 	}
 
 	/* Start with a left paren */
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 06/14] lib: libbb: f should never be NULL
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
                   ` (4 preceding siblings ...)
  2014-02-07  8:48 ` [PATCH 05/14] lib: math: fix return path (numstack may be NULL) Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  8:48 ` [PATCH 07/14] comamnds: uimage: actually print error message Lucas Stach
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

We assume it to be non NULL in other places, so
we are in much greater trouble if it actually is.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 lib/libbb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/libbb.c b/lib/libbb.c
index 189a170..dd42e66 100644
--- a/lib/libbb.c
+++ b/lib/libbb.c
@@ -43,7 +43,7 @@ EXPORT_SYMBOL(concat_path_file);
 
 char *concat_subpath_file(const char *path, const char *f)
 {
-	if (f && DOT_OR_DOTDOT(f))
+	if (DOT_OR_DOTDOT(f))
 		return NULL;
 	return concat_path_file(path, f);
 }
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 07/14] comamnds: uimage: actually print error message
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
                   ` (5 preceding siblings ...)
  2014-02-07  8:48 ` [PATCH 06/14] lib: libbb: f should never be NULL Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  9:22   ` Uwe Kleine-König
  2014-02-07  8:48 ` [PATCH 08/14] usb: ulpi: fix logic-op Lucas Stach
                   ` (7 subsequent siblings)
  14 siblings, 1 reply; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 commands/uimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/uimage.c b/commands/uimage.c
index 345e496..4b0ed4d 100644
--- a/commands/uimage.c
+++ b/commands/uimage.c
@@ -63,8 +63,8 @@ static int do_uimage(int argc, char *argv[])
 		printf("verifying data crc... ");
 		ret = uimage_verify(handle);
 		if (ret) {
-			goto err;
 			printf("Bad Data CRC\n");
+			goto err;
 		} else {
 			printf("ok\n");
 		}
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 08/14] usb: ulpi: fix logic-op
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
                   ` (6 preceding siblings ...)
  2014-02-07  8:48 ` [PATCH 07/14] comamnds: uimage: actually print error message Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  8:48 ` [PATCH 09/14] usb: dfu: fix error path to avoid NULL ptr deref Lucas Stach
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

Checking register bits is a bitwise operation.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 drivers/usb/otg/ulpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/otg/ulpi.c b/drivers/usb/otg/ulpi.c
index e0aa201..6fef5f2 100644
--- a/drivers/usb/otg/ulpi.c
+++ b/drivers/usb/otg/ulpi.c
@@ -51,7 +51,7 @@ int ulpi_read(int reg, void __iomem *view)
 	int ret;
 
 	/* make sure interface is running */
-	if (!(readl(view) && ULPIVW_SS)) {
+	if (!(readl(view) & ULPIVW_SS)) {
 		writel(ULPIVW_WU, view);
 
 		/* wait for wakeup */
@@ -73,7 +73,7 @@ int ulpi_set(u8 bits, int reg, void __iomem *view)
 	int ret;
 
 	/* make sure the interface is running */
-	if (!(readl(view) && ULPIVW_SS)) {
+	if (!(readl(view) & ULPIVW_SS)) {
 		writel(ULPIVW_WU, view);
 		/* wait for wakeup */
 		ret = ulpi_poll(view, ULPIVW_WU);
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 09/14] usb: dfu: fix error path to avoid NULL ptr deref
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
                   ` (7 preceding siblings ...)
  2014-02-07  8:48 ` [PATCH 08/14] usb: ulpi: fix logic-op Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  8:48 ` [PATCH 10/14] net: usb: smsc95xx: fix wrong phy reset condition Lucas Stach
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 drivers/usb/gadget/dfu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/dfu.c b/drivers/usb/gadget/dfu.c
index e15fc41..4d4c347 100644
--- a/drivers/usb/gadget/dfu.c
+++ b/drivers/usb/gadget/dfu.c
@@ -597,8 +597,10 @@ static int dfu_bind_config(struct usb_configuration *c)
 	func->disable = dfu_disable;
 
 	dfu->dnreq = usb_ep_alloc_request(c->cdev->gadget->ep0);
-	if (!dfu->dnreq)
+	if (!dfu->dnreq) {
 		printf("usb_ep_alloc_request failed\n");
+		goto out;
+	}
 	dfu->dnreq->buf = dma_alloc(CONFIG_USBD_DFU_XFER_SIZE);
 	dfu->dnreq->complete = dn_complete;
 	dfu->dnreq->zero = 0;
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 10/14] net: usb: smsc95xx: fix wrong phy reset condition
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
                   ` (8 preceding siblings ...)
  2014-02-07  8:48 ` [PATCH 09/14] usb: dfu: fix error path to avoid NULL ptr deref Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  8:48 ` [PATCH 11/14] net: usb: asix: properly propagate error code Lucas Stach
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 drivers/net/usb/smsc95xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 38ca12f..eb8f0be 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -447,7 +447,7 @@ static int smsc95xx_phy_initialize(struct usbnet *dev)
 		udelay(10 * 1000);
 		bmcr = smsc95xx_mdio_read(&dev->miibus, phy_id, MII_BMCR);
 		timeout++;
-	} while ((bmcr & MII_BMCR) && (timeout < 100));
+	} while ((bmcr & BMCR_RESET) && (timeout < 100));
 
 	if (timeout >= 100) {
 		netdev_warn(dev->net, "timeout on PHY Reset");
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 11/14] net: usb: asix: properly propagate error code
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
                   ` (9 preceding siblings ...)
  2014-02-07  8:48 ` [PATCH 10/14] net: usb: smsc95xx: fix wrong phy reset condition Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  8:48 ` [PATCH 12/14] mtd: core: avoid possible NULL ptr deref Lucas Stach
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 drivers/net/usb/asix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c
index b58db5d..37057a7 100644
--- a/drivers/net/usb/asix.c
+++ b/drivers/net/usb/asix.c
@@ -382,7 +382,7 @@ static int asix_get_ethaddr(struct eth_device *edev, unsigned char *adr)
 
 	if (ret < 0) {
 		debug("Failed to read MAC address: %d\n", ret);
-		return -1;
+		return ret;
 	}
 
 	return 0;
@@ -403,7 +403,7 @@ static int ax88172_get_ethaddr(struct eth_device *edev, unsigned char *adr)
 	if ((ret = asix_read_cmd(udev, AX88172_CMD_READ_NODE_ID,
 				0, 0, 6, adr)) < 0) {
 		debug("read AX_CMD_READ_NODE_ID failed: %d\n", ret);
-		return -1;
+		return ret;
 	}
 
 	return 0;
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 12/14] mtd: core: avoid possible NULL ptr deref
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
                   ` (10 preceding siblings ...)
  2014-02-07  8:48 ` [PATCH 11/14] net: usb: asix: properly propagate error code Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  8:48 ` [PATCH 13/14] clk: " Lucas Stach
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 drivers/mtd/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 6db1c6d..3439a38 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -404,7 +404,8 @@ int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id)
 	}
 
 	devfs_create(&mtd->cdev);
-	of_parse_partitions(&mtd->cdev, mtd->parent->device_node);
+	if (mtd->parent)
+		of_parse_partitions(&mtd->cdev, mtd->parent->device_node);
 
 	list_for_each_entry(hook, &mtd_register_hooks, hook)
 		if (hook->add_mtd_device)
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 13/14] clk: avoid possible NULL ptr deref
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
                   ` (11 preceding siblings ...)
  2014-02-07  8:48 ` [PATCH 12/14] mtd: core: avoid possible NULL ptr deref Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  8:48 ` [PATCH 14/14] don't cast negative error codes to unsigned size_t Lucas Stach
  2014-02-10  7:51 ` [PATCH 00/14] Smatch warning fixups Sascha Hauer
  14 siblings, 0 replies; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 drivers/clk/clkdev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 66cd832..d9a1c21 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -179,9 +179,11 @@ struct clk *clk_get(struct device_d *dev, const char *con_id)
 	if (!IS_ERR(clk))
 		return clk;
 
-	clk = of_clk_get_by_name(dev->device_node, con_id);
-		if (!IS_ERR(clk))
-			return clk;
+	if (dev) {
+		clk = of_clk_get_by_name(dev->device_node, con_id);
+			if (!IS_ERR(clk))
+				return clk;
+	}
 
 	return clk_get_sys(dev_id, con_id);
 }
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 14/14] don't cast negative error codes to unsigned size_t
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
                   ` (12 preceding siblings ...)
  2014-02-07  8:48 ` [PATCH 13/14] clk: " Lucas Stach
@ 2014-02-07  8:48 ` Lucas Stach
  2014-02-07  9:17   ` Juergen Beisert
  2014-02-10  7:51 ` [PATCH 00/14] Smatch warning fixups Sascha Hauer
  14 siblings, 1 reply; 18+ messages in thread
From: Lucas Stach @ 2014-02-07  8:48 UTC (permalink / raw)
  To: barebox

The cast prevents us from doing proper error checking.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 common/uimage.c | 6 +++---
 include/image.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/uimage.c b/common/uimage.c
index 7fbef86..4296359 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -74,7 +74,7 @@ void uimage_print_contents(struct uimage_handle *handle)
 }
 EXPORT_SYMBOL(uimage_print_contents);
 
-size_t uimage_get_size(struct uimage_handle *handle, unsigned int image_no)
+int uimage_get_size(struct uimage_handle *handle, unsigned int image_no)
 {
 	if (image_no >= handle->nb_data_entries)
 		return -EINVAL;
@@ -373,7 +373,7 @@ struct resource *file_to_sdram(const char *filename, unsigned long adr)
 	struct resource *res;
 	size_t size = BUFSIZ;
 	size_t ofs = 0;
-	size_t now;
+	int now;
 	int fd;
 
 	fd = open(filename, O_RDONLY);
@@ -420,7 +420,7 @@ struct resource *uimage_load_to_sdram(struct uimage_handle *handle,
 		int image_no, unsigned long load_address)
 {
 	int ret;
-	size_t size;
+	int size;
 	resource_size_t start = (resource_size_t)load_address;
 
 	uimage_buf = (void *)load_address;
diff --git a/include/image.h b/include/image.h
index 0c8a4b1..1592348 100644
--- a/include/image.h
+++ b/include/image.h
@@ -230,7 +230,7 @@ int uimage_verify(struct uimage_handle *handle);
 int uimage_load(struct uimage_handle *handle, unsigned int image_no,
 		int(*flush)(void*, unsigned int));
 void uimage_print_contents(struct uimage_handle *handle);
-size_t uimage_get_size(struct uimage_handle *handle, unsigned int image_no);
+int uimage_get_size(struct uimage_handle *handle, unsigned int image_no);
 struct resource *uimage_load_to_sdram(struct uimage_handle *handle,
 		int image_no, unsigned long load_address);
 void *uimage_load_to_buf(struct uimage_handle *handle, int image_no,
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 14/14] don't cast negative error codes to unsigned size_t
  2014-02-07  8:48 ` [PATCH 14/14] don't cast negative error codes to unsigned size_t Lucas Stach
@ 2014-02-07  9:17   ` Juergen Beisert
  0 siblings, 0 replies; 18+ messages in thread
From: Juergen Beisert @ 2014-02-07  9:17 UTC (permalink / raw)
  To: barebox

On Friday 07 February 2014 09:48:56 Lucas Stach wrote:
> The cast prevents us from doing proper error checking.
>
> Signed-off-by: Lucas Stach <dev@lynxeye.de>
> ---
>  common/uimage.c | 6 +++---
>  include/image.h | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/common/uimage.c b/common/uimage.c
> index 7fbef86..4296359 100644
> --- a/common/uimage.c
> +++ b/common/uimage.c
> @@ -74,7 +74,7 @@ void uimage_print_contents(struct uimage_handle *handle)
>  }
>  EXPORT_SYMBOL(uimage_print_contents);
>
> -size_t uimage_get_size(struct uimage_handle *handle, unsigned int image_no)
> +int uimage_get_size(struct uimage_handle *handle, unsigned int image_no)

What about "ssize_t"?

jbe

-- 
Pengutronix e.K.                              | Juergen Beisert             |
Linux Solutions for Science and Industry      | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 07/14] comamnds: uimage: actually print error message
  2014-02-07  8:48 ` [PATCH 07/14] comamnds: uimage: actually print error message Lucas Stach
@ 2014-02-07  9:22   ` Uwe Kleine-König
  0 siblings, 0 replies; 18+ messages in thread
From: Uwe Kleine-König @ 2014-02-07  9:22 UTC (permalink / raw)
  To: Lucas Stach; +Cc: barebox

Hi Lucas,

On Fri, Feb 07, 2014 at 09:48:49AM +0100, Lucas Stach wrote:
> Signed-off-by: Lucas Stach <dev@lynxeye.de>
> ---
>  commands/uimage.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/commands/uimage.c b/commands/uimage.c
> index 345e496..4b0ed4d 100644
> --- a/commands/uimage.c
> +++ b/commands/uimage.c
> @@ -63,8 +63,8 @@ static int do_uimage(int argc, char *argv[])
>  		printf("verifying data crc... ");
>  		ret = uimage_verify(handle);
>  		if (ret) {
> -			goto err;
>  			printf("Bad Data CRC\n");
> +			goto err;
I'd drop the printf instead because in the bad crc case uimage_verify()
already printfs an error. But instead let it give tongue in the other
error cases (like lseek() or read() failing)

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 00/14] Smatch warning fixups
  2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
                   ` (13 preceding siblings ...)
  2014-02-07  8:48 ` [PATCH 14/14] don't cast negative error codes to unsigned size_t Lucas Stach
@ 2014-02-10  7:51 ` Sascha Hauer
  14 siblings, 0 replies; 18+ messages in thread
From: Sascha Hauer @ 2014-02-10  7:51 UTC (permalink / raw)
  To: Lucas Stach; +Cc: barebox

On Fri, Feb 07, 2014 at 09:48:42AM +0100, Lucas Stach wrote:
> I've run smatch over a imx_v7_defconfig build
> and fixed the resulting warnings.
> 
> Some of them are just minor issues with no
> real impact, but some of them are real potential
> problems or even real bugs.
> 
> Lucas Stach (14):
>   remove redundant NULL check on free
>   commands: edit: properly propagate error code
>   common: env: properly propagate error code
>   clk: imx: unsigned mfn is never less than zero
>   lib: math: fix return path (numstack may be NULL)
>   lib: libbb: f should never be NULL
>   comamnds: uimage: actually print error message
>   usb: ulpi: fix logic-op
>   usb: dfu: fix error path to avoid NULL ptr deref
>   net: usb: smsc95xx: fix wrong phy reset condition
>   net: usb: asix: properly propagate error code
>   mtd: core: avoid possible NULL ptr deref
>   clk: avoid possible NULL ptr deref
>   don't cast negative error codes to unsigned size_t

Applied all except 07/14 and 14/14

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2014-02-10  7:51 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-07  8:48 [PATCH 00/14] Smatch warning fixups Lucas Stach
2014-02-07  8:48 ` [PATCH 01/14] remove redundant NULL check on free Lucas Stach
2014-02-07  8:48 ` [PATCH 02/14] commands: edit: properly propagate error code Lucas Stach
2014-02-07  8:48 ` [PATCH 03/14] common: env: " Lucas Stach
2014-02-07  8:48 ` [PATCH 04/14] clk: imx: unsigned mfn is never less than zero Lucas Stach
2014-02-07  8:48 ` [PATCH 05/14] lib: math: fix return path (numstack may be NULL) Lucas Stach
2014-02-07  8:48 ` [PATCH 06/14] lib: libbb: f should never be NULL Lucas Stach
2014-02-07  8:48 ` [PATCH 07/14] comamnds: uimage: actually print error message Lucas Stach
2014-02-07  9:22   ` Uwe Kleine-König
2014-02-07  8:48 ` [PATCH 08/14] usb: ulpi: fix logic-op Lucas Stach
2014-02-07  8:48 ` [PATCH 09/14] usb: dfu: fix error path to avoid NULL ptr deref Lucas Stach
2014-02-07  8:48 ` [PATCH 10/14] net: usb: smsc95xx: fix wrong phy reset condition Lucas Stach
2014-02-07  8:48 ` [PATCH 11/14] net: usb: asix: properly propagate error code Lucas Stach
2014-02-07  8:48 ` [PATCH 12/14] mtd: core: avoid possible NULL ptr deref Lucas Stach
2014-02-07  8:48 ` [PATCH 13/14] clk: " Lucas Stach
2014-02-07  8:48 ` [PATCH 14/14] don't cast negative error codes to unsigned size_t Lucas Stach
2014-02-07  9:17   ` Juergen Beisert
2014-02-10  7:51 ` [PATCH 00/14] Smatch warning fixups Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox