Skip to contentSkip to conversation

common/initcall: Extern linker symbols with correct types.

PATCH Superseded Andrew Cooper 3 participants 6 messages Oct 17, 2013 – Oct 22, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/initcall: Extern linker symbols with correct types.

Coverity IDs 1054956, 1054957

Coverity pointed out that we applying array operations based on an expression which yielded singleton pointers. The problem is actually that the externs were typed incorrectly.

Correct the extern declaration to prevent straying into undefined behaviour, and relying on the lenience of GCC to work.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
---
 xen/common/kernel.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
xen/common/kernel.c +3 -3
index b8707d9..e785edb 100644
@@ -196,19 +196,19 @@ void add_taint(unsigned flag)
     tainted |= flag;
 }
 
-extern initcall_t __initcall_start, __presmp_initcall_end, __initcall_end;
+extern initcall_t __initcall_start[], __presmp_initcall_end[], __initcall_end[];
 
 void __init do_presmp_initcalls(void)
 {
     initcall_t *call;
-    for ( call = &__initcall_start; call < &__presmp_initcall_end; call++ )
+    for ( call = __initcall_start; call < __presmp_initcall_end; call++ )
         (*call)();
 }
 
 void __init do_initcalls(void)
 {
     initcall_t *call;
-    for ( call = &__presmp_initcall_end; call < &__initcall_end; call++ )
+    for ( call = __presmp_initcall_end; call < __initcall_end; call++ )
         (*call)();
 }
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper

Coverity IDs 1054956, 1054957

Coverity pointed out that we applying array operations based on an expression
which yielded singleton pointers. The problem is actually that the externs were typed incorrectly.

Correct the extern declaration to prevent straying into undefined behaviour, and relying on the lenience of GCC to work.

Fine by me, but if you already touch this I would have really liked to see you also make the declarations const-correct.

Jan

Quoted 37 lines
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
---
 xen/common/kernel.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
xen/common/kernel.c +3 -3
index b8707d9..e785edb 100644
@@ -196,19 +196,19 @@ void add_taint(unsigned flag)
     tainted |= flag;
 }
 
-extern initcall_t __initcall_start, __presmp_initcall_end, __initcall_end;
+extern initcall_t __initcall_start[], __presmp_initcall_end[], 
 __initcall_end[];
 
 void __init do_presmp_initcalls(void)
 {
     initcall_t *call;
-    for ( call = &__initcall_start; call < &__presmp_initcall_end; call++ )
+    for ( call = __initcall_start; call < __presmp_initcall_end; call++ )
         (*call)();
 }
 
 void __init do_initcalls(void)
 {
     initcall_t *call;
-    for ( call = &__presmp_initcall_end; call < &__initcall_end; call++ )
+    for ( call = __presmp_initcall_end; call < __initcall_end; call++ )
         (*call)();
 }
Signature · 2 lines
-- 
1.7.10.4
#2 lore raw
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper

Coverity IDs 1054956, 1054957

Coverity pointed out that we applying array operations based on an expression
which yielded singleton pointers. The problem is actually that the externs were typed incorrectly.

Quoted 6 lines
Quoted 2 lines

Correct the extern declaration to prevent straying into undefined behaviour, and relying on the lenience of GCC to work.

Fine by me, but if you already touch this I would have really liked to see you also make the declarations const-correct.

Jan

Very good point - I shall submit v2 in due course.

~Andrew

Quoted 40 lines
Quoted 38 lines
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
---
 xen/common/kernel.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
xen/common/kernel.c +3 -3
index b8707d9..e785edb 100644
@@ -196,19 +196,19 @@ void add_taint(unsigned flag)
     tainted |= flag;
 }
 
-extern initcall_t __initcall_start, __presmp_initcall_end, __initcall_end;
+extern initcall_t __initcall_start[], __presmp_initcall_end[], 
 __initcall_end[];
 
 void __init do_presmp_initcalls(void)
 {
     initcall_t *call;
-    for ( call = &__initcall_start; call < &__presmp_initcall_end; call++ )
+    for ( call = __initcall_start; call < __presmp_initcall_end; call++ )
         (*call)();
 }
 
 void __init do_initcalls(void)
 {
     initcall_t *call;
-    for ( call = &__presmp_initcall_end; call < &__initcall_end; call++ )
+    for ( call = __presmp_initcall_end; call < __initcall_end; call++ )
         (*call)();
 }
Signature · 2 lines
-- 
1.7.10.4
#3 lore raw

PATCH v2 1/1 common/initcall: Extern linker symbols with correct types.

Coverity IDs 1054956, 1054957

Coverity pointed out that we applying array operations based on an expression which yielded singleton pointers. The problem is actually that the externs were typed incorrectly.

Correct the extern declaration to prevent straying into undefined behaviour, and relying on the lenience of GCC to work.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>

---

Changes in v2: apply const correctness as well.

---
 xen/common/kernel.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
xen/common/kernel.c +6 -5
index b8707d9..4ca50c4 100644
@@ -196,19 +196,20 @@ void add_taint(unsigned flag)
     tainted |= flag;
 }
 
-extern initcall_t __initcall_start, __presmp_initcall_end, __initcall_end;
+extern const initcall_t __initcall_start[], __presmp_initcall_end[],
+    __initcall_end[];
 
 void __init do_presmp_initcalls(void)
 {
-    initcall_t *call;
-    for ( call = &__initcall_start; call < &__presmp_initcall_end; call++ )
+    const initcall_t *call;
+    for ( call = __initcall_start; call < __presmp_initcall_end; call++ )
         (*call)();
 }
 
 void __init do_initcalls(void)
 {
-    initcall_t *call;
-    for ( call = &__presmp_initcall_end; call < &__initcall_end; call++ )
+    const initcall_t *call;
+    for ( call = __presmp_initcall_end; call < __initcall_end; call++ )
         (*call)();
 }
 
Signature · 1 line
1.7.10.4
#4 lore raw
Quoted 6 lines · Andrew Cooper

Coverity IDs 1054956, 1054957

Coverity pointed out that we applying array operations based on an expression which yielded singleton pointers. The problem is actually that the externs were typed incorrectly.

Quoted 6 lines

Correct the extern declaration to prevent straying into undefined behaviour, and relying on the lenience of GCC to work.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>

Ping?

Quoted 38 lines

---

Changes in v2: apply const correctness as well.

---
 xen/common/kernel.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
xen/common/kernel.c +6 -5
index b8707d9..4ca50c4 100644
@@ -196,19 +196,20 @@ void add_taint(unsigned flag)
     tainted |= flag;
 }
 
-extern initcall_t __initcall_start, __presmp_initcall_end, __initcall_end;
+extern const initcall_t __initcall_start[], __presmp_initcall_end[],
+    __initcall_end[];
 
 void __init do_presmp_initcalls(void)
 {
-    initcall_t *call;
-    for ( call = &__initcall_start; call < &__presmp_initcall_end; call++ )
+    const initcall_t *call;
+    for ( call = __initcall_start; call < __presmp_initcall_end; call++ )
         (*call)();
 }
 
 void __init do_initcalls(void)
 {
-    initcall_t *call;
-    for ( call = &__presmp_initcall_end; call < &__initcall_end; call++ )
+    const initcall_t *call;
+    for ( call = __presmp_initcall_end; call < __initcall_end; call++ )
         (*call)();
 }
 
Acked-by
#5 lore raw
Quoted 7 lines · Andrew Cooper
Quoted 6 lines · Andrew Cooper

Coverity IDs 1054956, 1054957

Coverity pointed out that we applying array operations based on an expression which yielded singleton pointers. The problem is actually that the externs were typed incorrectly.

Quoted 8 lines
Quoted 6 lines

Correct the extern declaration to prevent straying into undefined behaviour, and relying on the lenience of GCC to work.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>

Ping?

Quoted 39 lines
Quoted 38 lines

---

Changes in v2: apply const correctness as well.

---
 xen/common/kernel.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
xen/common/kernel.c +6 -5
index b8707d9..4ca50c4 100644
@@ -196,19 +196,20 @@ void add_taint(unsigned flag)
     tainted |= flag;
 }
 
-extern initcall_t __initcall_start, __presmp_initcall_end, __initcall_end;
+extern const initcall_t __initcall_start[], __presmp_initcall_end[],
+    __initcall_end[];
 
 void __init do_presmp_initcalls(void)
 {
-    initcall_t *call;
-    for ( call = &__initcall_start; call < &__presmp_initcall_end; call++ )
+    const initcall_t *call;
+    for ( call = __initcall_start; call < __presmp_initcall_end; call++ )
         (*call)();
 }
 
 void __init do_initcalls(void)
 {
-    initcall_t *call;
-    for ( call = &__presmp_initcall_end; call < &__initcall_end; call++ )
+    const initcall_t *call;
+    for ( call = __presmp_initcall_end; call < __initcall_end; call++ )
         (*call)();
 }