s390: avoid undefined behaviour
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Wed, 8 Nov 2017 10:18:29 +0000 (11:18 +0100)
committerHeiko Carstens <heiko.carstens@de.ibm.com>
Wed, 8 Nov 2017 21:11:20 +0000 (22:11 +0100)
At a couple of places smatch emits warnings like this:

    arch/s390/mm/vmem.c:409 vmem_map_init() warn:
        right shifting more than type allows

In fact shifting a signed type right is undefined. Avoid this and add
an unsigned long cast. The shifted values are always positive.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
arch/s390/mm/init.c
arch/s390/mm/vmem.c

index 3b567838b905f99ff8a755a90647520ba9348d00..a26fb8ee4a6b97ef1fb116c319044b17914dc258 100644 (file)
@@ -144,8 +144,8 @@ void __init mem_init(void)
 
 void free_initmem(void)
 {
-       __set_memory((unsigned long) _sinittext,
-                    (_einittext - _sinittext) >> PAGE_SHIFT,
+       __set_memory((unsigned long)_sinittext,
+                    (unsigned long)(_einittext - _sinittext) >> PAGE_SHIFT,
                     SET_MEMORY_RW | SET_MEMORY_NX);
        free_initmem_default(POISON_FREE_INITMEM);
 }
index f890f2ad951b5a60acd6490ccc6ec165bfee5ca1..24671beb2defd71abcf1d32a0b22db8b4c6ec508 100644 (file)
@@ -402,17 +402,17 @@ void __init vmem_map_init(void)
 
        for_each_memblock(memory, reg)
                vmem_add_mem(reg->base, reg->size);
-       __set_memory((unsigned long) _stext,
-                    (_etext - _stext) >> PAGE_SHIFT,
+       __set_memory((unsigned long)_stext,
+                    (unsigned long)(_etext - _stext) >> PAGE_SHIFT,
                     SET_MEMORY_RO | SET_MEMORY_X);
-       __set_memory((unsigned long) _etext,
-                    (__end_rodata - _etext) >> PAGE_SHIFT,
+       __set_memory((unsigned long)_etext,
+                    (unsigned long)(__end_rodata - _etext) >> PAGE_SHIFT,
                     SET_MEMORY_RO);
-       __set_memory((unsigned long) _sinittext,
-                    (_einittext - _sinittext) >> PAGE_SHIFT,
+       __set_memory((unsigned long)_sinittext,
+                    (unsigned long)(_einittext - _sinittext) >> PAGE_SHIFT,
                     SET_MEMORY_RO | SET_MEMORY_X);
        pr_info("Write protected kernel read-only data: %luk\n",
-               (__end_rodata - _stext) >> 10);
+               (unsigned long)(__end_rodata - _stext) >> 10);
 }
 
 /*