diff mbox

mtd: cmdlinepart: fix the wrong check condition

Message ID 1345355849-8992-1-git-send-email-shijie8@gmail.com
State New, archived
Headers show

Commit Message

Huang Shijie Aug. 19, 2012, 5:57 a.m. UTC
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.

Signed-off-by: Huang Shijie <shijie8@gmail.com>
---
 drivers/mtd/cmdlinepart.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Artem Bityutskiy Aug. 24, 2012, 4:06 p.m. UTC | #1
On Sun, 2012-08-19 at 01:57 -0400, Huang Shijie wrote:
> 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.
> 
> Signed-off-by: Huang Shijie <shijie8@gmail.com>

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.

> @@ -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.
Huang Shijie Aug. 25, 2012, 7:08 a.m. UTC | #2
On Fri, Aug 24, 2012 at 12:06 PM, Artem Bityutskiy <dedekind1@gmail.com> wrote:

> So you may also just add
>
> if (!mtd_id)
>         return 0
>
> at the beginning?

yes. Your code is better then mine.


Huang Shijie
diff mbox

Patch

diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index fc960a3..330b25f 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -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++)
 			{