Skip to content

Commit

Permalink
powerpc: Fix handling of strncmp with zero len
Browse files Browse the repository at this point in the history
Commit 0119536, which added the assembly version of strncmp to
powerpc, mentions that it adds two instructions to the version from
boot/string.S to allow it to handle len=0. Unfortunately, it doesn't
always return 0 when that is the case. The length is passed in r5, but
the return value is passed back in r3. In certain cases, this will
happen to work. Otherwise it will pass back the address of the first
string as the return value.

This patch lifts the len <= 0 handling code from memcpy to handle that
case.

Reported by: Christian_Sellars@symantec.com
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
CC: <stable@kernel.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
  • Loading branch information
Jeff Mahoney authored and Benjamin Herrenschmidt committed Apr 7, 2010
1 parent 6d1bdd2 commit 637a990
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion arch/powerpc/lib/string.S
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ _GLOBAL(strcmp)

_GLOBAL(strncmp)
PPC_LCMPI r5,0
beqlr
ble- 2f
mtctr r5
addi r5,r3,-1
addi r4,r4,-1
Expand All @@ -82,6 +82,8 @@ _GLOBAL(strncmp)
beqlr 1
bdnzt eq,1b
blr
2: li r3,0
blr

_GLOBAL(strlen)
addi r4,r3,-1
Expand Down

0 comments on commit 637a990

Please sign in to comment.