Skip to contentSkip to conversation

scripts: imx-image: Fix resource leak

PATCH In review Alexander Shiyan 2 participants 16 messages Apr 12, 2014 – Apr 23, 2014

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

PATCH 1/12 scripts: imx-image: Fix resource leak

---
 scripts/imx/imx-image.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
scripts/imx/imx-image.c +7 -4
index 1d935be..f87f4d2 100644
@@ -528,7 +528,7 @@ static int parse_config(const char *filename)
 	int lineno = 0;
 	char *line = NULL, *tmp;
 	char *argv[MAXARGS];
-	int nargs, i, ret;
+	int nargs, i, ret = 0;
 
 	f = fopen(filename, "r");
 	if (!f) {
@@ -559,7 +559,7 @@ static int parse_config(const char *filename)
 				if (ret) {
 					fprintf(stderr, "error in line %d: %s\n",
 							lineno, strerror(-ret));
-					return ret;
+					goto out_parse;
 				}
 				break;
 			}
@@ -567,11 +567,14 @@ static int parse_config(const char *filename)
 
 		if (ret == -ENOENT) {
 			fprintf(stderr, "no such command: %s\n", argv[0]);
-			return ret;
+			break;
 		}
 	}
 
-	return 0;
+out_parse:
+	fclose(f);
+
+	return ret;
 }
 
 static int xread(int fd, void *buf, int len)
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/12 gui: Fix resource leak

---
 lib/gui/picopng.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/gui/picopng.c +4 -0
index 77cd81c..e740b1c 100644
@@ -761,9 +761,12 @@ int main(int argc, char **argv)
 	infp = fopen(fname, "rb");
 	if (!infp) {
 		perror("fopen");
+		free(inbuf);
 		return 1;
 	} else if (fread(inbuf, 1, insize, infp) != insize) {
 		perror("fread");
+		free(inbuf);
+		fclose(infp);
 		return 1;
 	}
 	fclose(infp);
@@ -793,6 +796,7 @@ int main(int argc, char **argv)
 		return 1;
 	} else if (fwrite(info->image->data, 1, outsize, outfp) != outsize) {
 		perror("fwrite");
+		fclose(outfp);
 		return 1;
 	}
 	fclose(outfp);
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 3/12 lzo: Remove unused variable

In reply to Alexander Shiyan
---
 lib/decompress_unlzo.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/decompress_unlzo.c +1 -2
index 5ee3667..10ad42a 100644
@@ -56,7 +56,6 @@ static inline int parse_header(u8 *input, int *skip, int in_len)
 	int l;
 	u8 *parse = input;
 	u8 *end = input + in_len;
-	u8 level = 0;
 	u16 version;
 
 	/*
@@ -78,7 +77,7 @@ static inline int parse_header(u8 *input, int *skip, int in_len)
 	version = get_unaligned_be16(parse);
 	parse += 7;
 	if (version >= 0x0940)
-		level = *parse++;
+		parse++;
 	if (get_unaligned_be32(parse) & HEADER_HAS_FILTER)
 		parse += 8; /* flags + filter info */
 	else
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 4/12 ubifs: Remove unused variable

In reply to Alexander Shiyan
---
 fs/ubifs/ubifs.c | 4 ----
 1 file changed, 4 deletions(-)
fs/ubifs/ubifs.c +0 -4
index 35923a9..49d5583 100644
@@ -240,8 +240,6 @@ static struct inode *ubifs_findfile(struct super_block *sb, const char *filename
 		return ubifs_iget(sb, 1);
 
 	for (;;) {
-		struct ubifs_inode *ui;
-
 		/* Extract the actual part from the pathname.  */
 		next = strchr(name, '/');
 		if (next) {
@@ -257,8 +255,6 @@ static struct inode *ubifs_findfile(struct super_block *sb, const char *filename
 		if (!inode)
 			break;
 
-		ui = ubifs_inode(inode);
-
 		/*
 		 * Check if directory with this name exists
 		 */
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH 5/12 commands/mount: Return real error code if "mount" fail

In reply to Alexander Shiyan
---
 commands/mount.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
commands/mount.c +1 -1
index 691bc29..77efe71 100644
@@ -115,7 +115,7 @@ static int do_mount(int argc, char *argv[])
 
 	if ((ret = mount(dev, type, mountpoint, fsoptions))) {
 		perror("mount");
-		return 1;
+		return ret;
 	}
 	return 0;
 }
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#5 lore raw

Re: [PATCH 05/12] commands/mount: Return real error code if "mount" fail

Quoted 10 lines · Alexander Shiyan
---
 commands/mount.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
commands/mount.c +0 -0
index 691bc29..77efe71 100644

commands/mount.c static int do_mount(int argc, char *argv[]) · line 118

Quoted 5 lines
commands/mount.c +1 -1
@@ -115,7 +115,7 @@ static int do_mount(int argc, char *argv[])
 
 	if ((ret = mount(dev, type, mountpoint, fsoptions))) {
 		perror("mount");
-		return 1;
+		return ret;

The perror() should be removed then. Otherwise we get the same error message twice.

Sascha

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH 6/12 commands/uimage: Fix error printing

In reply to Alexander Shiyan
---
 commands/uimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
commands/uimage.c +1 -1
index 345e496..4b0ed4d 100644
@@ -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");
 		}
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH 7/12 commands/umount: Return real error code if "umount" fail

In reply to Alexander Shiyan
---
 commands/umount.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
commands/umount.c +3 -4
index e6de1bc..8dcf7f0 100644
@@ -28,11 +28,10 @@ static int do_umount(int argc, char *argv[])
 	if (argc != 2)
 		return COMMAND_ERROR_USAGE;
 
-	if ((ret = umount(argv[1]))) {
+	if ((ret = umount(argv[1])))
 		perror("umount");
-		return 1;
-	}
-	return 0;
+
+	return ret;
 }
 
 static const __maybe_unused char cmd_umount_help[] =
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#8 lore raw

Re: [PATCH 07/12] commands/umount: Return real error code if "umount" fail

Quoted 10 lines · Alexander Shiyan
---
 commands/umount.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
commands/umount.c +0 -0
index e6de1bc..8dcf7f0 100644

commands/umount.c static int do_umount(int argc, char *argv[]) · line 34

Quoted 8 lines
commands/umount.c +1 -3
@@ -28,11 +28,10 @@ static int do_umount(int argc, char *argv[])
 	if (argc != 2)
 		return COMMAND_ERROR_USAGE;
 
-	if ((ret = umount(argv[1]))) {
+	if ((ret = umount(argv[1])))
 		perror("umount");
-		return 1;
-	}

Here perror() also should be removed.

Sascha

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH 8/12 commands/usbserial: Remove unused variable

In reply to Alexander Shiyan
---
 commands/usbserial.c | 3 ---
 1 file changed, 3 deletions(-)
commands/usbserial.c +0 -3
index bd5067f..969fd25 100644
@@ -31,7 +31,6 @@ static int do_usbserial(int argc, char *argv[])
 {
 	int opt;
 	struct usb_serial_pdata pdata;
-	char *argstr;
 	char *manufacturer = "barebox";
 	const char *productname = barebox_get_model();
 	u16 idVendor = 0, idProduct = 0;
@@ -68,8 +67,6 @@ static int do_usbserial(int argc, char *argv[])
 		}
 	}
 
-	argstr = argv[optind];
-
 	pdata.manufacturer = manufacturer;
 	pdata.productname = productname;
 	pdata.idVendor = idVendor;
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

PATCH 9/12 ata: pata-imx: Remove unused variable

In reply to Alexander Shiyan
---
 drivers/ata/pata-imx.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/ata/pata-imx.c +0 -3
index 7f9e39b..6bd7524 100644
@@ -78,9 +78,6 @@ static void pata_imx_set_bus_timing(void __iomem *base, unsigned long clkrate,
 {
 	uint32_t T = 1000000000 / clkrate;
 
-	struct mxc_ata_config_regs *ata_regs;
-	ata_regs = (struct mxc_ata_config_regs *)base;
-
 	if (mode >= ARRAY_SIZE(pio_t1))
 		return;
 
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw

PATCH 10/12 imx_keypad: Fix error handling

In reply to Alexander Shiyan
---
 drivers/input/imx_keypad.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/input/imx_keypad.c +8 -9
index e6870df..a1e2055 100644
@@ -392,17 +392,17 @@ static int __init imx_keypad_probe(struct device_d *dev)
 	struct console_device *cdev;
 	int error, i;
 
-	keypad = xzalloc(sizeof(struct imx_keypad));
-	if (!keypad) {
-		pr_err("not enough memory for driver data\n");
-		error = -ENOMEM;
-	}
-
 	if (!keymap_data) {
 		pr_err("no keymap defined\n");
 		return -ENODEV;
 	}
 
+	keypad = xzalloc(sizeof(struct imx_keypad));
+	if (!keypad) {
+		pr_err("not enough memory for driver data\n");
+		return -ENOMEM;
+	}
+
 	keypad->dev = dev;
 	keypad->mmio_base = dev_request_mem_region(dev, 0);
 
@@ -420,8 +420,8 @@ static int __init imx_keypad_probe(struct device_d *dev)
 	if (keypad->rows_en_mask > ((1 << MAX_MATRIX_KEY_ROWS) - 1) ||
 	   keypad->cols_en_mask > ((1 << MAX_MATRIX_KEY_COLS) - 1)) {
 		pr_err("invalid key data (too many rows or colums)\n");
-		error = -EINVAL;
-		//goto failed_clock_put;
+		free(keypad);
+		return -EINVAL;
 	}
 	pr_debug("enabled rows mask: %x\n", keypad->rows_en_mask);
 	pr_debug("enabled cols mask: %x\n", keypad->cols_en_mask);
@@ -446,7 +446,6 @@ static int __init imx_keypad_probe(struct device_d *dev)
 	console_register(&keypad->cdev);
 
 	return poller_register(&keypad->poller);
-
 }
 
 static struct driver_d imx_keypad_driver = {
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#12 lore raw

Re: [PATCH 10/12] imx_keypad: Fix error handling

Quoted 19 lines · Alexander Shiyan
---
 drivers/input/imx_keypad.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/input/imx_keypad.c +0 -6
index e6870df..a1e2055 100644
@@ -392,17 +392,17 @@ static int __init imx_keypad_probe(struct device_d *dev)
 	struct console_device *cdev;
 	int error, i;
 
-	keypad = xzalloc(sizeof(struct imx_keypad));
-	if (!keypad) {
-		pr_err("not enough memory for driver data\n");
-		error = -ENOMEM;
-	}
-

drivers/input/imx_keypad.c static int __init imx_keypad_probe(struct device_d *dev) · line 404

Quoted 10 lines
drivers/input/imx_keypad.c +5 -0
 	if (!keymap_data) {
 		pr_err("no keymap defined\n");
 		return -ENODEV;
 	}
 
+	keypad = xzalloc(sizeof(struct imx_keypad));
+	if (!keypad) {
+		pr_err("not enough memory for driver data\n");
+		return -ENOMEM;
+	}

No need to check the result from xzalloc. Removed this while applying.

Sascha

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#13 lore raw

PATCH 11/12 mtd: partition: Remove unused variable

In reply to Alexander Shiyan
---
 drivers/mtd/partition.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/mtd/partition.c +0 -3
index 720c2ad..c2461a0 100644
@@ -7,11 +7,8 @@
 static int mtd_part_read(struct mtd_info *mtd, loff_t from, size_t len,
                 size_t *retlen, u_char *buf)
 {
-	struct mtd_ecc_stats stats;
 	int res;
 
-	stats = mtd->master->ecc_stats;
-
 	if (from >= mtd->size)
 		len = 0;
 	else if (from + len > mtd->size)
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#14 lore raw

PATCH 12/12 mtd: nand: bbt: Remove unused variable

In reply to Alexander Shiyan
---
 drivers/mtd/nand/nand_bbt.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/mtd/nand/nand_bbt.c +1 -4
index b0548a3..1357c5c 100644
@@ -551,7 +551,7 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
 {
 	struct nand_chip *this = mtd->priv;
 	int i, chips;
-	int bits, startblock, block, dir;
+	int startblock, block, dir;
 	int scanlen = mtd->writesize + mtd->oobsize;
 	int bbtblocks;
 	int blocktopage = this->bbt_erase_shift - this->page_shift;
@@ -575,9 +575,6 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
 		bbtblocks = mtd->size >> this->bbt_erase_shift;
 	}
 
-	/* Number of bits for each erase block in the bbt */
-	bits = td->options & NAND_BBT_NRBITS_MSK;
-
 	for (i = 0; i < chips; i++) {
 		/* Reset version information */
 		td->version[i] = 0;
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#15 lore raw
In reply to Alexander Shiyan
Quoted 1 line · Alexander Shiyan

Applied this series without 05/12 and 07/12 for now.

Sascha

Quoted 52 lines
---
 scripts/imx/imx-image.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
scripts/imx/imx-image.c +7 -4
index 1d935be..f87f4d2 100644
@@ -528,7 +528,7 @@ static int parse_config(const char *filename)
 	int lineno = 0;
 	char *line = NULL, *tmp;
 	char *argv[MAXARGS];
-	int nargs, i, ret;
+	int nargs, i, ret = 0;
 
 	f = fopen(filename, "r");
 	if (!f) {
@@ -559,7 +559,7 @@ static int parse_config(const char *filename)
 				if (ret) {
 					fprintf(stderr, "error in line %d: %s\n",
 							lineno, strerror(-ret));
-					return ret;
+					goto out_parse;
 				}
 				break;
 			}
@@ -567,11 +567,14 @@ static int parse_config(const char *filename)
 
 		if (ret == -ENOENT) {
 			fprintf(stderr, "no such command: %s\n", argv[0]);
-			return ret;
+			break;
 		}
 	}
 
-	return 0;
+out_parse:
+	fclose(f);
+
+	return ret;
 }
 
 static int xread(int fd, void *buf, int len)
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox