Skip to contentSkip to conversation

mtd: cmdlinepart: fix the wrong check condition

PATCH Superseded Huang Shijie 2 participants 3 messages Aug 18, 2012 – Aug 25, 2012 Memory technology devices (MTD)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: cmdlinepart: fix the wrong check condition

If the mtd_id is NULL, the check condition will be true. So the cmdlinepart may parses out several mtd partitions. This is obviously wrong.

Just fix it.

---
 drivers/mtd/cmdlinepart.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/mtd/cmdlinepart.c +1 -1
index fc960a3..330b25f 100644
@@ -328,7 +328,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
 
 	for(part = partitions; part; part = part->next)
 	{
-		if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id)))
+		if (mtd_id && (!strcmp(part->mtd_id, mtd_id)))
 		{
 			for(i = 0, offset = 0; i < part->num_parts; i++)
 			{
Signature · 1 line
1.7.4.4
#1 lore raw
Quoted 7 lines · Huang Shijie

If the mtd_id is NULL, the check condition will be true. So the cmdlinepart may parses out several mtd partitions. This is obviously wrong.

Just fix it.

I do not understand from the description what is exactly the problem with the current code, and how exactly you solve it. Please, elaborate some more by re-sending the patch with better commit message.

drivers/mtd/cmdlinepart.c static int parse_cmdline_partitions(struct mtd_info *master, · line 334

Quoted 9 lines
drivers/mtd/cmdlinepart.c +1 -1
@@ -328,7 +328,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
 
 	for(part = partitions; part; part = part->next)
 	{
-		if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id)))
+		if (mtd_id && (!strcmp(part->mtd_id, mtd_id)))
 		{
 			for(i = 0, offset = 0; i < part->num_parts; i++)
 			{

So you may also just add

if (!mtd_id)
return 0

at the beginning?

I guess you should first try to explain what that check is trying to do, what is mtd_id and when it can be NULL. Then tell what is the problem and how you solve it.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#2 lore raw
Quoted 6 lines · Artem Bityutskiy

So you may also just add

if (!mtd_id)
return 0

at the beginning?

yes. Your code is better then mine.

Huang Shijie