Re: [PATCH] avoiding the same resource to be inserted

From: Huang Shijie
Date: Wed Aug 25 2010 - 00:32:01 EST


On Wed, Aug 25, 2010 at 7:46 AM, Andrew Morton
<akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Mon, 16 Aug 2010 23:55:38 +0800
> Huang Shijie <shijie8@xxxxxxxxx> wrote:
>
>> Â If the same resource is inserted to the resource tree
>> (maybe not on purpose), a dead loop will be created. In this situation,
>> The kernel does not report any warning or error    :(
>>
>> Â The command below will show a endless print.
>> Â #cat /proc/iomem
>
> OK, we shouldn't do that.
>
>> Â So, adding the check for the same resource is needed for the stability
>> and reliability of the kernel.
>>
>> Signed-off-by: Huang Shijie <shijie8@xxxxxxxxx>
>> ---
>> Âkernel/resource.c | Â Â2 +-
>> Â1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/kernel/resource.c b/kernel/resource.c
>> index 7b36976..60daab4 100644
>> --- a/kernel/resource.c
>> +++ b/kernel/resource.c
>> @@ -451,7 +451,7 @@ static struct resource * __insert_resource(struct resource *parent, struct resou
>> Â Â Â Â Â Â Â if (!first)
>> Â Â Â Â Â Â Â Â Â Â Â return first;
>>
>> - Â Â Â Â Â Â if (first == parent)
>> + Â Â Â Â Â Â if (first == parent || first == new)
>> Â Â Â Â Â Â Â Â Â Â Â return first;
>
> However, inserting the same thing twice _is_ a bug, and we shouldn't
> silently accept it like this. ÂWe should tell the programmer!

Indeed, this is a bug caused by the driver programmer.I had spent
nearly two day to find it in my colleague's code.


>
> But we can recover from the situation so let's not kill the box. ÂHow
> does this look?
>
> --- a/kernel/resource.c~kernel-resourcec-handle-reinsertion-of-an-already-inserted-resource
> +++ a/kernel/resource.c
> @@ -453,6 +453,8 @@ static struct resource * __insert_resour
>
> Â Â Â Â Â Â Â Âif (first == parent)
> Â Â Â Â Â Â Â Â Â Â Â Âreturn first;
> + Â Â Â Â Â Â Â if (WARN_ON(first == new)) Â Â Â/* duplicated insertion */
> + Â Â Â Â Â Â Â Â Â Â Â return first;
>

Yes. This one is better.
Many drivers do not check the returned value of insert_resouce().


> Â Â Â Â Â Â Â Âif ((first->start > new->start) || (first->end < new->end))
> Â Â Â Â Â Â Â Â Â Â Â Âbreak;
> _
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/