Skip to contentSkip to conversation

x86/ldt: make a size variable unsigned

PATCH Superseded Dan Carpenter 4 participants 4 messages Dec 8, 2016 – Dec 10, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/ldt: make a size variable unsigned

My static checker complains that we put an upper bound on the "size" variable but not a lower bound. The checker is not smart enough to know the possible ranges of "old_mm->context.ldt->size" from init_new_context_ldt() so it thinks maybe it could be negative.

Let's make it unsigned to silence the warning and future proof the code a bit.

arch/x86/kernel/ldt.c +1 -1
index 4d12cdf2b453..d6320c63be45 100644
@@ -34,7 +34,7 @@ static void flush_ldt(void *current_mm)
 }
 
 /* The caller must call finalize_ldt_struct on the result. LDT starts zeroed. */
-static struct ldt_struct *alloc_ldt_struct(int size)
+static struct ldt_struct *alloc_ldt_struct(unsigned int size)
 {
 	struct ldt_struct *new_ldt;
 	int alloc_size;
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Dan Carpenter

My static checker complains that we put an upper bound on the "size" variable but not a lower bound. The checker is not smart enough to know the possible ranges of "old_mm->context.ldt->size" from init_new_context_ldt() so it thinks maybe it could be negative.

Let's make it unsigned to silence the warning and future proof the code a bit.

#2 lore raw
In reply to Dan Carpenter
Quoted 15 lines · Dan Carpenter

My static checker complains that we put an upper bound on the "size" variable but not a lower bound. The checker is not smart enough to know the possible ranges of "old_mm->context.ldt->size" from init_new_context_ldt() so it thinks maybe it could be negative.

Let's make it unsigned to silence the warning and future proof the code a bit.

arch/x86/kernel/ldt.c +0 -0
index 4d12cdf2b453..d6320c63be45 100644

arch/x86/kernel/ldt.c static void flush_ldt(void *current_mm) · line 40

Quoted 8 lines
arch/x86/kernel/ldt.c +1 -1
@@ -34,7 +34,7 @@ static void flush_ldt(void *current_mm)
 }
 
 /* The caller must call finalize_ldt_struct on the result. LDT starts zeroed. */
-static struct ldt_struct *alloc_ldt_struct(int size)
+static struct ldt_struct *alloc_ldt_struct(unsigned int size)
 {
 	struct ldt_struct *new_ldt;
 	int alloc_size;

So yes, this fixes the checker warning, but then it leaves the code in inconsistent state:

	alloc_size = size * LDT_ENTRY_SIZE;

Why not doing the obvious

- int alloc_size;
+ unsigned int alloc_size;

right away?

We have lots of places where we 'fixup' stuff and leave the rest untouched, which then causes trouble a few month down the road. Probably not in this case, but still.

I'm all for addressing such issues, but then please take the time aside of mechanically fixing the checker fallout to make the overall usage consistent.

Thanks,

tglx

#3 lore raw

[tip:x86/cleanups] x86/ldt: Make a size argument unsigned

In reply to Dan Carpenter
x86/ldt: Make a size argument unsigned
Commit-ID:  296dc5806de57dc84fce000d60fc201ba40f96e8
Gitweb:     http://git.kernel.org/tip/296dc5806de57dc84fce000d60fc201ba40f96e8
Author:     Dan Carpenter <[email protected]>
AuthorDate: Thu, 8 Dec 2016 13:56:03 +0300
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sat, 10 Dec 2016 00:24:39 +0100

x86/ldt: Make a size argument unsigned

My static checker complains that we put an upper bound on the "size" argument but not a lower bound. The checker is not smart enough to know the possible ranges of "old_mm->context.ldt->size" from init_new_context_ldt() so it thinks maybe it could be negative.

Let's make it unsigned to silence the warning and future proof the code a bit.

---
 arch/x86/kernel/ldt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/ldt.c +1 -1
index 6707039..e25b668 100644
@@ -34,7 +34,7 @@ static void flush_ldt(void *current_mm)
 }
 
 /* The caller must call finalize_ldt_struct on the result. LDT starts zeroed. */
-static struct ldt_struct *alloc_ldt_struct(int size)
+static struct ldt_struct *alloc_ldt_struct(unsigned int size)
 {
 	struct ldt_struct *new_ldt;
 	int alloc_size;