Command line parsing

David A. Braun braunster at gmail.com
Mon Sep 19 14:50:44 EDT 2005


If the name in master->name doesn't match any of the partitions 
mentioned on the kernel command line then *pparts->offset is not 
initialized. The result is that all the partitions start at 0. Also the 
length of the "SIZE_REMAINING" partition is never initialized. Also the 
return value is -EINVAL instead of the number of partitions. This 
results in none of the partitions being pass to the driver. The only 
partition that appears in /proc/partitions is one for the whole device.

There are two problems. The if statement

    if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id)))
    {
          ...

before the innermost for loop prevents the non-matching cmdline 
partitions from being initialized. Secondly the return statement just 
after this same for loop stops processing any remaining partitions 
following the matching partition.

As it turns out after looking over the code some more the table in 
question is internal to the cmdline parser anyway so no harm is done. 
Any partition declared on the cmdline that is referenced by a mtd driver 
gets initialized correctly. Unreferenced ones don't and need not be. 
There is however a small amount of kernel memory wasted on the partition 
table in cmdlineparts. It doesn't look like it ever gets released, not 
even if the cmdline parser gets de-registered (which it doesn't).

dave

Jörn Engel wrote:

>On Mon, 19 September 2005 16:26:07 +0200, Marius Groeger wrote:
>  
>
>>On Mon, 19 Sep 2005, Jörn Engel wrote:
>>    
>>
>>>On Sat, 17 September 2005 10:55:40 -0400, David A. Braun wrote:
>>>      
>>>
>>>>Is there any particular reason parse_cmdline_partitions() in
>>>>drivers/mtd/cmdlineparse.c doesn't completely setup the partition
>>>>table(s) it builds? It fails to initialize the offsets and sizes of any
>>>>partition tabled unless it is the one named by "master". This one has
>>>>the offsets and lengths filled in but the others are left zero with the
>>>>exception of partitions specified with "-" or SIZE_REMAINING. I would
>>>>have expected all partitions described in the cmdline to be initialized
>>>>if any are.
>>>>        
>>>>
>>>Iirc, the code was written by someone at Sysgo, possibly Robert, and
>>>hasn't been touched for quite a while.  So if you have any patches
>>>that improve the situation for you, feel free to send them.
>>>      
>>>
>>Acutally it was me :-), but someone decided to remove my name and just 
>>leave in the reference to our company... Anyway you're right about my 
>>not having touched that code. Looking at it briefly, though, I don't 
>>really spot anything suspicous. Apart from the (potential) oddity that 
>>the cmdline is saved and processed much later at a time the flash 
>>hardware is actually, I don't see what is not initialized.
>>    
>>
>
>[ slightly off-topic ]
>
>If you want your copyright line restored and don't have cvs access,
>send me a patch.
>
>For those less aware of how copyright law works:
>The copyright itself is independent of some lines explicitly claiming
>it for somebody.  So this is not about a legal issue, just politeness.
>
>Jörn
>
>  
>




More information about the linux-mtd mailing list