Skip to contentSkip to conversation

random fixes

PATCH Superseded Oleksij Rempel 2 participants 9 messages Nov 10, 2018 – Nov 16, 2018

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover random fixes

Some random fixes for issues found by https://app.codacy.com

Oleksij Rempel (5):
commands: keystore: init s_len
ddr_spd: remove unused array video/ssd1307fb: fix potential memory leak on error
clk: imx: cpu: avoid use after free on error
of: partition: set ret for error cases

 commands/keystore.c       | 2 +-
 common/ddr_spd.c          | 2 --
 drivers/clk/imx/clk-cpu.c | 4 +++-
 drivers/of/partition.c    | 4 ++--
 drivers/video/ssd1307fb.c | 8 ++++++--
 5 files changed, 12 insertions(+), 8 deletions(-)
Signature · 7 lines
2.17.1


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

PATCH 1/5 commands: keystore: init s_len

if read_file_2 will fail, s_len will stay uninitialized.

---
 commands/keystore.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
commands/keystore.c +1 -1
index 52c4be263..50a6c8494 100644
@@ -15,7 +15,7 @@ static int do_keystore(int argc, char *argv[])
 	const char *file = NULL;
 	char *secret_str = NULL;
 	void *secret;
-	int s_len;
+	int s_len = 0;
 
 	while ((opt = getopt(argc, argv, "rs:f:")) > 0) {
 		switch (opt) {
Signature · 7 lines
2.17.1


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

Re: [PATCH v1 1/5] commands: keystore: init s_len

Quoted 12 lines · Oleksij Rempel

if read_file_2 will fail, s_len will stay uninitialized.

---
 commands/keystore.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
commands/keystore.c +0 -0
index 52c4be263..50a6c8494 100644

commands/keystore.c static int do_keystore(int argc, char *argv[]) · line 18

Quoted 5 lines
commands/keystore.c +1 -1
@@ -15,7 +15,7 @@ static int do_keystore(int argc, char *argv[])
 	const char *file = NULL;
 	char *secret_str = NULL;
 	void *secret;
-	int s_len;
+	int s_len = 0;

if read_file_2 fails then s_len is also not used.

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
#3 lore raw

PATCH 2/5 ddr_spd: remove unused array

In reply to Oleksij Rempel
---
 common/ddr_spd.c | 2 --
 1 file changed, 2 deletions(-)
common/ddr_spd.c +0 -2
index ec343ef5a..7e2945ed9 100644
@@ -166,7 +166,6 @@ static int ddr2_sdram_ctime(uint8_t byte)
 void ddr_spd_print(uint8_t *record)
 {
 	int highestCAS = 0;
-	int cas[256];
 	int i, i_i, k, x, y;
 	int ddrclk, tbits, pcclk;
 	int trcd, trp, tras;
@@ -199,7 +198,6 @@ void ddr_spd_print(uint8_t *record)
 	for (i_i = 2; i_i < 7; i_i++) {
 		if (s->cas_lat & 1 << i_i) {
 			highestCAS = i_i;
-			cas[highestCAS]++;
 		}
 	}
 
Signature · 7 lines
2.17.1


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

PATCH 3/5 video/ssd1307fb: fix potential memory leak on error

In reply to Oleksij Rempel
---
 drivers/video/ssd1307fb.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/video/ssd1307fb.c +6 -2
index d68f0c505..1fd1a3cfb 100644
@@ -548,8 +548,11 @@ static int ssd1307fb_probe(struct device_d *dev)
 	/* clear display */
 	array = ssd1307fb_alloc_array(par->width * par->height / 8,
 				      SSD1307FB_DATA);
-	if (!array)
-		return -ENOMEM;
+	if (!array) {
+		dev_err(&client->dev, "Couldn't not allocate an array\n");
+		ret = -ENOMEM;
+		goto panel_init_error;
+	}
 
 	for (i = 0; i < (par->height / 8); i++) {
 		for (j = 0; j < par->width; j++) {
@@ -569,6 +572,7 @@ static int ssd1307fb_probe(struct device_d *dev)
 
 panel_init_error:
 reset_oled_error:
+	free(vmem);
 fb_alloc_error:
 	regulator_disable(par->vbat);
 	free(info);
Signature · 7 lines
2.17.1


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

Re: [PATCH v1 3/5] video/ssd1307fb: fix potential memory leak on error

Quoted 10 lines · Oleksij Rempel
---
 drivers/video/ssd1307fb.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/video/ssd1307fb.c +0 -0
index d68f0c505..1fd1a3cfb 100644

drivers/video/ssd1307fb.c static int ssd1307fb_probe(struct device_d *dev) · line 552

Quoted 7 lines
drivers/video/ssd1307fb.c +2 -2
@@ -548,8 +548,11 @@ static int ssd1307fb_probe(struct device_d *dev)
 	/* clear display */
 	array = ssd1307fb_alloc_array(par->width * par->height / 8,
 				      SSD1307FB_DATA);
-	if (!array)
-		return -ENOMEM;
+	if (!array) {
+		dev_err(&client->dev, "Couldn't not allocate an array\n");

Please do not add messages in allocation failure pathes. When we get out of memory it's not really interesting where it happened, at least not when it's not the culprit itself. It would rather be interesting who ate all your memory before.

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 4/5 clk: imx: cpu: avoid use after free on error

In reply to Oleksij Rempel
---
 drivers/clk/imx/clk-cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/imx/clk-cpu.c +3 -1
index 5ac0ed178..f9db36018 100644
@@ -111,8 +111,10 @@ struct clk *imx_clk_cpu(const char *name, const char *parent_name,
 	cpu->clk.num_parents = 1;
 
 	ret = clk_register(&cpu->clk);
-	if (ret)
+	if (ret) {
 		free(cpu);
+		return 0;
+	}
 
 	return &cpu->clk;
 }
Signature · 7 lines
2.17.1


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

Re: [PATCH v1 4/5] clk: imx: cpu: avoid use after free on error

Quoted 10 lines · Oleksij Rempel
---
 drivers/clk/imx/clk-cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/imx/clk-cpu.c +0 -0
index 5ac0ed178..f9db36018 100644

drivers/clk/imx/clk-cpu.c struct clk *imx_clk_cpu(const char *name, const char *parent_name, · line 116

Quoted 7 lines
drivers/clk/imx/clk-cpu.c +2 -1
@@ -111,8 +111,10 @@ struct clk *imx_clk_cpu(const char *name, const char *parent_name,
 	cpu->clk.num_parents = 1;
 
 	ret = clk_register(&cpu->clk);
-	if (ret)
+	if (ret) {
 		free(cpu);
+		return 0;

Should be return NULL.

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
#8 lore raw

PATCH 5/5 of: partition: set ret for error cases

In reply to Oleksij Rempel

looks like it was forgotten.

---
 drivers/of/partition.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/of/partition.c +2 -2
index aa6e601b7..2848b9636 100644
@@ -186,11 +186,11 @@ static int of_partition_fixup(struct device_node *root, void *ctx)
 			return ret;
 	}
 
-	of_property_write_u32(partnode, "#size-cells", n_cells);
+	ret = of_property_write_u32(partnode, "#size-cells", n_cells);
 	if (ret)
 		return ret;
 
-	of_property_write_u32(partnode, "#address-cells", n_cells);
+	ret = of_property_write_u32(partnode, "#address-cells", n_cells);
 	if (ret)
 		return ret;
 
Signature · 7 lines
2.17.1


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