]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
x86 setup: sizeof() is unsigned, unbreak comparisons
authorH. Peter Anvin <hpa@zytor.com>
Thu, 25 Oct 2007 23:09:38 +0000 (16:09 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Fri, 26 Oct 2007 03:20:06 +0000 (20:20 -0700)
We use signed values for limit checking since the values can go
negative under certain circumstances.  However, sizeof() is unsigned
and forces the comparison to be unsigned, so move the comparison into
the heap_free() macros so we can ensure it is a signed comparison.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
arch/x86/boot/boot.h
arch/x86/boot/video-bios.c
arch/x86/boot/video-vesa.c
arch/x86/boot/video.c

index 887874f4b49fa9ac900042fed96aae42467552b7..d2b5adf46512f20feb7fc27a14d39bc37c10e3e4 100644 (file)
@@ -216,9 +216,9 @@ static inline char *__get_heap(size_t s, size_t a, size_t n)
 #define GET_HEAP(type, n) \
        ((type *)__get_heap(sizeof(type),__alignof__(type),(n)))
 
-static inline int heap_free(void)
+static inline bool heap_free(size_t n)
 {
-       return heap_end-HEAP;
+       return (int)(heap_end-HEAP) >= (int)n;
 }
 
 /* copy.S */
index 68e65d95cdfd8627a69df2ed1ec7cf33cd392ca4..ed0672a818709b86d8c6ebd6416269434934091e 100644 (file)
@@ -79,7 +79,7 @@ static int bios_probe(void)
        video_bios.modes = GET_HEAP(struct mode_info, 0);
 
        for (mode = 0x14; mode <= 0x7f; mode++) {
-               if (heap_free() < sizeof(struct mode_info))
+               if (!heap_free(sizeof(struct mode_info)))
                        break;
 
                if (mode_defined(VIDEO_FIRST_BIOS+mode))
index 19219071071023e631518e102c4dbcc7481dea17..4716b9a963575aa8d0eedf703feaa7997ada608e 100644 (file)
@@ -57,7 +57,7 @@ static int vesa_probe(void)
        while ((mode = rdfs16(mode_ptr)) != 0xffff) {
                mode_ptr += 2;
 
-               if (heap_free() < sizeof(struct mode_info))
+               if (!heap_free(sizeof(struct mode_info)))
                        break;  /* Heap full, can't save mode info */
 
                if (mode & ~0x1ff)
index e4ba897bf9a3748c89e442141887ea9e0dbba721..ad9712f01739748c0d0d7d727ac34e20401de26f 100644 (file)
@@ -371,7 +371,7 @@ static void save_screen(void)
        saved.curx = boot_params.screen_info.orig_x;
        saved.cury = boot_params.screen_info.orig_y;
 
-       if (heap_free() < saved.x*saved.y*sizeof(u16)+512)
+       if (!heap_free(saved.x*saved.y*sizeof(u16)+512))
                return;         /* Not enough heap to save the screen */
 
        saved.data = GET_HEAP(u16, saved.x*saved.y);