lkml.org 
[lkml]   [2012]   [Sep]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 2/3] mtd: cmdlinepart: sort the unsorted partitions
From
Date
On Sun, 2012-08-26 at 13:21 -0400, Huang Shijie wrote:
> +/* There are only several partitions, so the Bubble sort is enough. */
> +static inline void sort_partitons(struct mtd_partition *parts, int num_parts)
> +{
> + int i, j;
> +
> + if (num_parts < 2)
> + return;

Not necessary, the for loop should work for this case.
> +
> + if (parts[0].offset == OFFSET_CONTINUOUS)
> + return;

Hmm, I guess the sorting function should not have this check. You
probably can just sort normally these ones, they will be the last ones.

And then we can do a separate pass where we check for overlapping
partitions and multiple OFFSET_CONTINUOUS.

> +
> + /* sort by the offset */
> + for (i = 0; i < num_parts - 1; i++) {
> + for (j = 1; j < num_parts - i; j++) {
> + if (parts[j - 1].offset > parts[j].offset) {
> + struct mtd_partition tmp;
> +
> + tmp = parts[j - 1];
> + parts[j - 1] = parts[j];
> + parts[j] = tmp;
> + }
> + }
> + }
> + return;
> +}


--
Best Regards,
Artem Bityutskiy
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2012-09-03 10:02    [W:0.204 / U:2.404 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site