* [PATCH] drivers/xen/grant-table.c: Be sure of unsigned value never comparing with 0
@ 2014-08-26 15:38 Chen Gang
2014-08-26 17:03 ` David Vrabel
0 siblings, 1 reply; 5+ messages in thread
From: Chen Gang @ 2014-08-26 15:38 UTC (permalink / raw)
To: konrad.wilk, boris.ostrovsky, david.vrabel
Cc: xen-devel, linux-kernel@vger.kernel.org
In grow_gnttab_list(), 'i' is 'unsigned int', and 'nr_glist_frames' may
be 0 because 'nr_grant_frames' may be 0. So 'i' may never be less than
'nr_glist_frames' in failure processing, which cause infinite looping.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
drivers/xen/grant-table.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index c254ae0..be07645 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -592,8 +592,8 @@ static int grow_gnttab_list(unsigned int more_frames)
return 0;
grow_nomem:
- for ( ; i >= nr_glist_frames; i--)
- free_page((unsigned long) gnttab_list[i]);
+ while (i > nr_glist_frames)
+ free_page((unsigned long) gnttab_list[--i]);
return -ENOMEM;
}
--
1.9.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] drivers/xen/grant-table.c: Be sure of unsigned value never comparing with 0
2014-08-26 15:38 [PATCH] drivers/xen/grant-table.c: Be sure of unsigned value never comparing with 0 Chen Gang
@ 2014-08-26 17:03 ` David Vrabel
2014-08-26 19:42 ` Chen Gang
0 siblings, 1 reply; 5+ messages in thread
From: David Vrabel @ 2014-08-26 17:03 UTC (permalink / raw)
To: Chen Gang, konrad.wilk, boris.ostrovsky
Cc: xen-devel, linux-kernel@vger.kernel.org
On 26/08/14 16:38, Chen Gang wrote:
> In grow_gnttab_list(), 'i' is 'unsigned int', and 'nr_glist_frames' may
> be 0 because 'nr_grant_frames' may be 0. So 'i' may never be less than
> 'nr_glist_frames' in failure processing, which cause infinite looping.
nr_grant_frames is at least 1. See gnttab_init().
> --- a/drivers/xen/grant-table.c
> +++ b/drivers/xen/grant-table.c
> @@ -592,8 +592,8 @@ static int grow_gnttab_list(unsigned int more_frames)
> return 0;
>
> grow_nomem:
> - for ( ; i >= nr_glist_frames; i--)
> - free_page((unsigned long) gnttab_list[i]);
> + while (i > nr_glist_frames)
> + free_page((unsigned long) gnttab_list[--i]);
while (i-- > nr_glist_frames)
...
Would have been better.
David
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] drivers/xen/grant-table.c: Be sure of unsigned value never comparing with 0
2014-08-26 17:03 ` David Vrabel
@ 2014-08-26 19:42 ` Chen Gang
2014-08-27 10:06 ` David Vrabel
0 siblings, 1 reply; 5+ messages in thread
From: Chen Gang @ 2014-08-26 19:42 UTC (permalink / raw)
To: David Vrabel
Cc: konrad.wilk, boris.ostrovsky, xen-devel,
linux-kernel@vger.kernel.org
On 08/27/2014 01:03 AM, David Vrabel wrote:
> On 26/08/14 16:38, Chen Gang wrote:
>> In grow_gnttab_list(), 'i' is 'unsigned int', and 'nr_glist_frames' may
>> be 0 because 'nr_grant_frames' may be 0. So 'i' may never be less than
>> 'nr_glist_frames' in failure processing, which cause infinite looping.
>
> nr_grant_frames is at least 1. See gnttab_init().
>
OK, thanks, that sounds reasonable to me, it is not a real wold bug, it
is my fault. :-)
>> --- a/drivers/xen/grant-table.c
>> +++ b/drivers/xen/grant-table.c
>> @@ -592,8 +592,8 @@ static int grow_gnttab_list(unsigned int more_frames)
>> return 0;
>>
>> grow_nomem:
>> - for ( ; i >= nr_glist_frames; i--)
>> - free_page((unsigned long) gnttab_list[i]);
>> + while (i > nr_glist_frames)
>> + free_page((unsigned long) gnttab_list[--i]);
>
> while (i-- > nr_glist_frames)
> ...
>
> Would have been better.
>
OK, thanks, that sounds reasonable to me.
If necessary to send patch v2 (change comments and contents), please
let me know, and I shall send.
Thanks.
--
Chen Gang
Open share and attitude like air water and life which God blessed
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drivers/xen/grant-table.c: Be sure of unsigned value never comparing with 0
2014-08-26 19:42 ` Chen Gang
@ 2014-08-27 10:06 ` David Vrabel
2014-08-27 10:27 ` Chen Gang
0 siblings, 1 reply; 5+ messages in thread
From: David Vrabel @ 2014-08-27 10:06 UTC (permalink / raw)
To: Chen Gang
Cc: konrad.wilk, boris.ostrovsky, xen-devel,
linux-kernel@vger.kernel.org
On 26/08/14 20:42, Chen Gang wrote:
> On 08/27/2014 01:03 AM, David Vrabel wrote:
>> On 26/08/14 16:38, Chen Gang wrote:
>>> In grow_gnttab_list(), 'i' is 'unsigned int', and 'nr_glist_frames' may
>>> be 0 because 'nr_grant_frames' may be 0. So 'i' may never be less than
>>> 'nr_glist_frames' in failure processing, which cause infinite looping.
>>
>> nr_grant_frames is at least 1. See gnttab_init().
>>
>
> OK, thanks, that sounds reasonable to me, it is not a real wold bug, it
> is my fault. :-)
>
>>> --- a/drivers/xen/grant-table.c
>>> +++ b/drivers/xen/grant-table.c
>>> @@ -592,8 +592,8 @@ static int grow_gnttab_list(unsigned int more_frames)
>>> return 0;
>>>
>>> grow_nomem:
>>> - for ( ; i >= nr_glist_frames; i--)
>>> - free_page((unsigned long) gnttab_list[i]);
>>> + while (i > nr_glist_frames)
>>> + free_page((unsigned long) gnttab_list[--i]);
>>
>> while (i-- > nr_glist_frames)
>> ...
>>
>> Would have been better.
>>
>
> OK, thanks, that sounds reasonable to me.
>
> If necessary to send patch v2 (change comments and contents), please
> let me know, and I shall send.
Applied to devel/for-linus-3.18 with this description:
xen/grant-table: refactor error cleanup in grow_gnttab_list()
The cleanup loop in grow_gnttab_list() is safe from the underflow of
the unsigned 'i' since nr_glist_frames is >= 1, but refactor it
anyway.
Thanks.
David
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] drivers/xen/grant-table.c: Be sure of unsigned value never comparing with 0
2014-08-27 10:06 ` David Vrabel
@ 2014-08-27 10:27 ` Chen Gang
0 siblings, 0 replies; 5+ messages in thread
From: Chen Gang @ 2014-08-27 10:27 UTC (permalink / raw)
To: David Vrabel
Cc: konrad.wilk, boris.ostrovsky, xen-devel,
linux-kernel@vger.kernel.org
On 8/27/14 18:06, David Vrabel wrote:
>
> Applied to devel/for-linus-3.18 with this description:
>
> xen/grant-table: refactor error cleanup in grow_gnttab_list()
>
> The cleanup loop in grow_gnttab_list() is safe from the underflow of
> the unsigned 'i' since nr_glist_frames is >= 1, but refactor it
> anyway.
>
OK, thank you very much for your encouragement! And next, I shall try to
provide another patches for Xen (hope I can finish within this month).
And I should be more careful about the patches which I shall send.
Also I want to consult: "Is there a common test for Xen"? If there is,
please let me know, and I should try to perform the common test before
send any patches.
Welcome any additional ideas, suggestions, and completions.
Thanks.
--
Chen Gang
Open, share, and attitude like air, water, and life which God blessed
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-08-27 10:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-26 15:38 [PATCH] drivers/xen/grant-table.c: Be sure of unsigned value never comparing with 0 Chen Gang
2014-08-26 17:03 ` David Vrabel
2014-08-26 19:42 ` Chen Gang
2014-08-27 10:06 ` David Vrabel
2014-08-27 10:27 ` Chen Gang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox