Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion arch/riscv/lib/strnlen.S
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ strnlen_zbb:
sub t3, t3, t2
slli t2, t2, 3

/* Aligned boundary. */
/*
* Aligned boundary. Use the address of the last valid byte
* (s + count - 1) to avoid loading a word past the count
* boundary in the loop below. count == 0 is handled above.
*/
add t4, a0, a1
addi t4, t4, -1
andi t4, t4, -SZREG

/* Get the first word. */
Expand Down Expand Up @@ -120,6 +125,9 @@ strnlen_zbb:

bgtu t3, a0, 2f

/* All remaining bytes are in the first word, no loop needed. */
bgeu t0, t4, 2f

/* Prepare for the word comparison loop. */
addi t2, t0, SZREG
li t3, -1
Expand Down
Loading