Skip to content

Commit b0f55f2

Browse files
amylaartorvalds
authored andcommitted
ARC: [lib] strchr breakage in Big-endian configuration
For a search buffer, 2 byte aligned, strchr() was returning pointer outside of buffer (buf - 1) ------------->8---------------- // Input buffer (default 4 byte aigned) char *buffer = "1AA_"; // actual search start (to mimick 2 byte alignment) char *current_line = &(buffer[2]); // Character to search for char c = 'A'; char *c_pos = strchr(current_line, c); printf("%s\n", c_pos) --> 'AA_' as oppose to 'A_' ------------->8---------------- Reported-by: Anton Kolesov <Anton.Kolesov@synopsys.com> Debugged-by: Anton Kolesov <Anton.Kolesov@synopsys.com> Cc: <stable@vger.kernel.org> # [3.9 and 3.10] Cc: Noam Camus <noamc@ezchip.com> Signed-off-by: Joern Rennecke <joern.rennecke@embecosm.com> Signed-off-by: Vineet Gupta <vgupta@synopsys.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 89b53e5 commit b0f55f2

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎arch/arc/lib/strchr-700.S‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,18 @@ ARC_ENTRY strchr
3939
ld.a r2,[r0,4]
4040
sub r12,r6,r7
4141
bic r12,r12,r6
42+
#ifdef __LITTLE_ENDIAN__
4243
and r7,r12,r4
4344
breq r7,0,.Loop ; For speed, we want this branch to be unaligned.
4445
b .Lfound_char ; Likewise this one.
46+
#else
47+
and r12,r12,r4
48+
breq r12,0,.Loop ; For speed, we want this branch to be unaligned.
49+
lsr_s r12,r12,7
50+
bic r2,r7,r6
51+
b.d .Lfound_char_b
52+
and_s r2,r2,r12
53+
#endif
4554
; /* We require this code address to be unaligned for speed... */
4655
.Laligned:
4756
ld_s r2,[r0]
@@ -95,6 +104,7 @@ ARC_ENTRY strchr
95104
lsr r7,r7,7
96105

97106
bic r2,r7,r6
107+
.Lfound_char_b:
98108
norm r2,r2
99109
sub_s r0,r0,4
100110
asr_s r2,r2,3

0 commit comments

Comments
 (0)