Skip to content

Commit 1c1d046

Browse files
arjun024ingomolnar
authored andcommitted
x86/boot: Standardize strcmp()
strcmp() is always expected to return 0 when arguments are equal, negative when its first argument @str1 is less than its second argument @str2 and a positive value otherwise. Previously strcmp("a", "b") returned 1. Now it gives -1, as it is supposed to. Until now this bug never triggered, because all uses for strcmp() in the boot code tested for nonzero: triton:~/tip> git grep strcmp arch/x86/boot/ arch/x86/boot/boot.h:int strcmp(const char *str1, const char *str2); arch/x86/boot/edd.c: if (!strcmp(eddarg, "skipmbr") || !strcmp(eddarg, "skip")) { arch/x86/boot/edd.c: else if (!strcmp(eddarg, "off")) arch/x86/boot/edd.c: else if (!strcmp(eddarg, "on")) should in the future strcmp() be used in a comparative way in the boot code, it might have led to (not so subtle) bugs. Signed-off-by: Arjun Sreedharan <arjun024@gmail.com> Signed-off-by: Borislav Petkov <bp@suse.de> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1426520267-1803-1-git-send-email-arjun024@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 91d8f04 commit 1c1d046

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎arch/x86/boot/string.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int strcmp(const char *str1, const char *str2)
3030
int delta = 0;
3131

3232
while (*s1 || *s2) {
33-
delta = *s2 - *s1;
33+
delta = *s1 - *s2;
3434
if (delta)
3535
return delta;
3636
s1++;

0 commit comments

Comments
 (0)