On Mon, Aug 17, 2009 at 03:23:18PM -0500, Aguirre Rodriguez, Sergio Alberto 
wrote:
> #ifndef CONFIG_SPARSEMEM
> int pfn_valid(unsigned long pfn)
> {
>       struct meminfo *mi = &meminfo;
>       unsigned int left = 0, right = mi->nr_banks;
> 
>       while (left <= right) {

This condition will cause the while to loop forever when left == right
and pfn < bank_pfn_start(bank).

>               unsigned int mid = (right - left) / 2;

This calculation is incorrect when left != 0 (also in the original
patch).

>               struct membank *bank = &mi->bank[mid];
> 
>               if (pfn < bank_pfn_start(bank))
>                       right = mid;
>               else if (pfn >= bank_pfn_end(bank))
>                       left = mid + 1;
>               else
>                       return 1;
>       }
>       return 0;
> }
> EXPORT_SYMBOL(pfn_valid);
> #endif

Here's a fixed version:

int pfn_valid(unsigned long pfn)
{
        struct meminfo *mi = &meminfo;
        unsigned int left = 0, right = mi->nr_banks;

        while (left < right) {
                        unsigned int mid = (left + right) / 2;
                        struct membank *bank = &mi->bank[mid];

                        if (pfn < bank_pfn_start(bank))
                                right = mid;
                        else if (pfn >= bank_pfn_end(bank))
                                left = mid + 1;
                        else
                                return 1;
        }

        return 0;
}

Rabin
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to