only use legitimate shift counts in bitmap shifting
PATCH 1/1 only use legitimate shift counts in bitmap shifting
An alternative would be to remove these implicitly unused functions.
Coverity ID 1192174 (__bitmap_shift_right)
Coverity ID 1192175 (__bitmap_shift_left)
xen/common/bitmap.c +6 -2
@@ -144,7 +144,9 @@ void __bitmap_shift_right(unsigned long lower = src[off + k];if (left && off + k == lim -1 ) lower &= mask; - dst[k] = upper << (BITS_PER_LONG - rem) | lower >> rem; + dst[k] = rem + ? (upper << (BITS_PER_LONG - rem)) | (lower >> rem) + : lower;if (left && k == lim -1 ) dst[k] &= mask; }
@@ -185,7 +187,9 @@ void __bitmap_shift_left(unsigned long * upper = src[k];if (left && k == lim -1 ) upper &= (1UL << left) -1 ; - dst[k + off] = lower >> (BITS_PER_LONG - rem) | upper << rem; + dst[k + off] = rem ? (lower >> (BITS_PER_LONG - rem)) + | (upper << rem) + : upper;if (left && k + off == lim -1 ) dst[k + off] &= (1UL << left) -1 ; }
only use legitimate shift counts in bitmap shifting
An alternative would be to remove these implicitly unused functions.
Coverity ID 1192174 (__bitmap_shift_right)
Coverity ID 1192175 (__bitmap_shift_left)
xen/common/bitmap.c +6 -2
@@ -144,7 +144,9 @@ void __bitmap_shift_right(unsigned long lower = src[off + k];if (left && off + k == lim -1 ) lower &= mask; - dst[k] = upper << (BITS_PER_LONG - rem) | lower >> rem; + dst[k] = rem + ? (upper << (BITS_PER_LONG - rem)) | (lower >> rem) + : lower;if (left && k == lim -1 ) dst[k] &= mask; }
@@ -185,7 +187,9 @@ void __bitmap_shift_left(unsigned long * upper = src[k];if (left && k == lim -1 ) upper &= (1UL << left) -1 ; - dst[k + off] = lower >> (BITS_PER_LONG - rem) | upper << rem; + dst[k + off] = rem ? (lower >> (BITS_PER_LONG - rem)) + | (upper << rem) + : upper;if (left && k + off == lim -1 ) dst[k + off] &= (1UL << left) -1 ; }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 1 line · Jan Beulich
An alternative would be to remove these implicitly unused functions.
Why "implicitly"?
Looks like we got this file from Linux, which I suppose is a reason to keep it intact even if we aren't using these particular functions. It does look like the same fix applies to Linux though.
Can you be explicit about which thing is illegitimate? I have inferred it is when rem == 0, which leads to "upper << BITS_PER_LONG"? If you make that clear in the commit message then:
Quoted 33 lines
Coverity ID 1192174 (
__bitmap_shift_right)
Coverity ID 1192175 (__bitmap_shift_left)Signed-off-by Jan Beulich <[email protected]>xen/common/bitmap.c +6
-2@@ -144,7 +144,9 @@ void __bitmap_shift_right(unsigned long lower = src[off + k];if (left && off + k == lim -1 ) lower &= mask; - dst[k] = upper << (BITS_PER_LONG - rem) | lower >> rem; + dst[k] = rem + ? (upper << (BITS_PER_LONG - rem)) | (lower >> rem) + : lower;if (left && k == lim -1 ) dst[k] &= mask; }@@ -185,7 +187,9 @@ void __bitmap_shift_left(unsigned long * upper = src[k];if (left && k == lim -1 ) upper &= (1UL << left) -1 ; - dst[k + off] = lower >> (BITS_PER_LONG - rem) | upper << rem; + dst[k + off] = rem ? (lower >> (BITS_PER_LONG - rem)) + | (upper << rem) + : upper;if (left && k + off == lim -1 ) dst[k + off] &= (1UL << left) -1 ; }
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 11:01, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
An alternative would be to remove these implicitly unused functions.
Why "implicitly"?
Because they have users (cpumask shifts), but those users are themselves unused.
Quoted 8 lines
Looks like we got this file from Linux, which I suppose is a reason to keep it intact even if we aren't using these particular functions. It does look like the same fix applies to Linux though.
Can you be explicit about which thing is illegitimate? I have inferred it is when rem == 0, which leads to "upper <<
BITS_PER_LONG"? If you make that clear in the commit message then:Acked-by Ian Campbell <[email protected]>
Thanks - added
For rem being zero (where rem is the remainder of a division by BITS_PER_LONG, "upper << (BITS_PER_LONG - rem)" degenerates to "upper << BITS_PER_LONG", which is undefined.
despite thinking that this just describes the obvious.
Jan
Quoted 8 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 11:01, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
An alternative would be to remove these implicitly unused functions.
Why "implicitly"?
Because they have users (cpumask shifts), but those users are themselves unused.
So they are, I grepped but misread the answer somehow (despite it being quite clear)
Quoted 10 lines
Quoted 9 lines
Looks like we got this file from Linux, which I suppose is a reason to keep it intact even if we aren't using these particular functions. It does look like the same fix applies to Linux though.
Can you be explicit about which thing is illegitimate? I have inferred it is when rem == 0, which leads to "upper <<
BITS_PER_LONG"? If you make that clear in the commit message then:Acked-by Ian Campbell <[email protected]>
Quoted 7 lines
Thanks - added
For rem being zero (where rem is the remainder of a division by
BITS_PER_LONG, "upper << (BITS_PER_LONG- rem)" degenerates to "upper <<BITS_PER_LONG", which is undefined.despite thinking that this just describes the obvious.
It's only obvious once you have spotted it ;-) "When rem is zero" would have been enough of a hint for me FWIW (sorry for appearing to suggest I wanted more).
Ian.