Revert "platform/x86/toshiba-apci.c possible bad if test?"
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Matthew,
There is no doubt that the revert was needed but I think the original check which is now reinstated is also wrong.
I do not know what the intention actually is so cannot say what the correct check is but just logically speaking the check makes no sense:
if (sscanf(buf, "%i", &mode) != 1 && (mode != 2 || mode != 1))
The condition "(mode != 2 || mode != 1)" will always be true given that mode can only have a single value: if mode == 1 then mode != 2 is true and thus the condition is true and vice versa if mode == 2 then mode != 1 is true and thus the condition is true, too. And if mode is neither 1 nor 2 then both mode != 2 and mode != 1 are true and thus the condition is true, too. Thus no matter what value "mode" has, the condition is true thus there is no point in it being there thus the if clause is exactly the same as:
if (sscanf(buf, "%i", &mode) != 1)
Presumably that was not the original intention...
Perhaps the intention was to check that mode is either 1 or 2 and other values are not allowed? If so the correct statement would be:
if (sscanf(buf, "%i", &mode) != 1 || (mode != 2 && mode != 1))
But as I said above I do not know if that was the original intention but it looks like that this may have been the intention...
Best regards,
Anton
Quoted 31 lines · Linux Kernel Mailing List
Gitweb: http://git.kernel.org/linus/;a=commit;h=8039aabb6c9f802bca04cc77ca210060a5b53916 Commit: 8039aabb6c9f802bca04cc77ca210060a5b53916 Parent: 186e4e89a0922d75fba476f15b723e541cc34bea Refname: refs/heads/master Author: Matthew Garrett <[email protected]> AuthorDate: Wed Aug 20 08:18:18 2014 -0700 Committer: Matthew Garrett <[email protected]> CommitDate: Wed Aug 20 08:18:18 2014 -0700Revert "
platform/x86/toshiba-apci.cpossible bad if test?"This reverts commit
bdc3ae7221213963f438faeaa69c8b4a2195f491.Signed-off-by Matthew Garrett <[email protected]>---
drivers/platform/x86/toshiba_acpi.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/platform/x86/toshiba_acpi.c +1
-1@@ -1258,7 +1258,7 @@ static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,int mode =-1 ;int time =-1 ; -if (sscanf (buf,"%i" , &mode) !=1 || (mode !=2 || mode !=1 )) +if (sscanf (buf,"%i" , &mode) !=1 && (mode !=2 || mode !=1 ))return -EINVAL ;/* Set the Keyboard Backlight Mode where:
Signature · 3 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) University of Cambridge Information Services, Roger Needham Building 7 JJ Thomson Avenue, Cambridge, CB3 0RB, UK