Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1222469 > unrolled thread

Re: [PATCH] lib/string_helpers.c: fix infinite loop in string_get_size()

Started byJames Bottomley <jbottomley@odin.com>
First post2015-09-11 03:30 +0200
Last post2015-09-14 11:20 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] lib/string_helpers.c: fix infinite loop in  string_get_size() James Bottomley <jbottomley@odin.com> - 2015-09-11 03:30 +0200
    Re: [PATCH] lib/string_helpers.c: fix infinite loop in string_get_size() Vitaly Kuznetsov <vkuznets@redhat.com> - 2015-09-14 11:20 +0200

#1222469 — Re: [PATCH] lib/string_helpers.c: fix infinite loop in string_get_size()

FromJames Bottomley <jbottomley@odin.com>
Date2015-09-11 03:30 +0200
SubjectRe: [PATCH] lib/string_helpers.c: fix infinite loop in string_get_size()
Message-ID<q7lk6-2Q0-7@gated-at.bofh.it>
T24gRnJpLCAyMDE1LTA5LTA0IGF0IDE0OjU2ICswMjAwLCBWaXRhbHkgS3V6bmV0c292IHdyb3Rl
Og0KPiBzdHJpbmdfZ2V0X3NpemUoMSwgNTEyLCAwLCAuLi4sIC4uLikgY2FsbCByZXN1bHRzIGlu
IGFuIGluZmluaXRlIGxvb3AuIFRoZQ0KPiBwcm9ibGVtIGlzIHRoYXQgaWYgc2l6ZSA9PSAwIHdo
ZW4gd2Ugc3RhcnQgY2FsY3VsYXRpbmcgc2ZfY2FwIHRoaXMgbG9vcA0KPiB3aWxsIG5ldmVyIGVu
ZC4NCj4gDQo+IFRoZSBjYWxsZXIgY2F1c2luZyB0aGUgaXNzdWUgaXMgc2RfcmVhZF9jYXBhY2l0
eSgpLCB0aGUgcHJvYmxlbSB3YXMgbm90aWNlZA0KPiBvbiBIeXBlci1WLg0KPiANCj4gU2lnbmVk
LW9mZi1ieTogVml0YWx5IEt1em5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Q0KPiAgCQlzZl9jYXAgKj0gMTA7DQo+ICANCg0KDQo=
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1223959 — Re: [PATCH] lib/string_helpers.c: fix infinite loop in string_get_size()

FromVitaly Kuznetsov <vkuznets@redhat.com>
Date2015-09-14 11:20 +0200
SubjectRe: [PATCH] lib/string_helpers.c: fix infinite loop in string_get_size()
Message-ID<q8y5A-1Tq-7@gated-at.bofh.it>
In reply to#1222469
James Bottomley <jbottomley@odin.com> writes:

> On Fri, 2015-09-04 at 14:56 +0200, Vitaly Kuznetsov wrote:
>> string_get_size(1, 512, 0, ..., ...) call results in an infinite loop. The
>> problem is that if size == 0 when we start calculating sf_cap this loop
>> will never end.
>> 
>> The caller causing the issue is sd_read_capacity(), the problem was noticed
>> on Hyper-V.
>> 
>> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>> ---
>>  lib/string_helpers.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/lib/string_helpers.c b/lib/string_helpers.c
>> index c98ae81..a155c7b 100644
>> --- a/lib/string_helpers.c
>> +++ b/lib/string_helpers.c
>> @@ -76,7 +76,7 @@ void string_get_size(u64 size, u64 blk_size, const enum string_size_units units,
>>  		i++;
>>  	}
>>  
>> -	sf_cap = size;
>> +	sf_cap = size ? size : 1;
>
> If size can become zero after the scale adjustment, then there's a fault
> in the algorithm, and this probably isn't the right fix.  However, I did
> a brief calculation, and I can't see how size becomes zero ...

... but it does ...

> it might be that I haven't looked at this long enough (I am on holiday).

The function itself looks over complicated to me but you're probably
right and I'll try to find the root cause of the issue in the algorythm.

Thanks,

>
> James
>
>>  	for (j = 0; sf_cap*10 < 1000; j++)
>>  		sf_cap *= 10;
>>  

-- 
  Vitaly
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web