Skip to content

Replace strncmp with str_has_prefix

Chuhong Yuan linux-iommu linux-pm lkml 5 versions – Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest8 patches 9 repliesApplied
  2. v38 patches 1 replySuperseded
  3. v2 posting 2/210 patches 3 repliesApplied
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v2 posting 1/21 patch0 repliesSuperseded
v11 patch1 replySuperseded

Changes in v4 from the cover letter

- Eliminate assignments in if conditions.

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/8dma: debug: Replace strncmp with str_has_prefixkernel/dma/debug.c+1 -10 replies
2/8module: Replace strncmp with str_has_prefixkernel/module.c+1 -10 replies
3/8PM/sleep: Replace strncmp with str_has_prefixkernel/power/main.c+1 -11 reply
4/8printk: Replace strncmp with str_has_prefixkernel/printk/braille.c kernel/printk/printk.c+27 -105 replies
5/8reboot: Replace strncmp with str_has_prefixkernel/reboot.c+5 -20 replies
6/8sched: Replace strncmp with str_has_prefixkernel/sched/debug.c kernel/sched/isolation.c+11 -63 replies
7/8userns: Replace strncmp with str_has_prefixkernel/user_namespace.c+12 -80 replies
8/8watchdog: Replace strncmp with str_has_prefixkernel/watchdog.c+4 -40 replies

Reviews trailers per patch

2 of 8 patches have a Reviewed-by or Acked-by.

PatchValentin SchneiderPetr MladekSergey Senozhatsky
1/8
2/8
3/8
4/8R-b R-b
5/8
6/8R-b
7/8
8/8

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v4 thread

Cover letter [PATCH v4 0/8] Replace strncmp with str_has_prefix

The commit 72921427d46b
("string.h: Add str_has_prefix() helper function") introduced str_has_prefix() to substitute error-prone strncmp(str, const, len).

strncmp(str, const, len) is easy to have error in len because of counting error or sizeof(const) without - 1.

These patches replace such pattern with str_has_prefix() to avoid hard coded constant length and sizeof.

Besides, str_has_prefix() returns the length of prefix when the comparison returns true.
We can use this return value to substitute some hard-coding.

Changelog:

v1 -> v2:
- Revise the description.
- Use the return value of str_has_prefix() to eliminate hard coding.
- Remove possible false positives and add newly detected one in upstream.

v2 -> v3:
- Revise the description.
- Remove else uses in printk.c.

v3 -> v4:
- Eliminate assignments in if conditions.

Chuhong Yuan (8):
dma: debug: Replace strncmp with str_has_prefix
module: Replace strncmp with str_has_prefix PM/sleep: Replace strncmp with str_has_prefix
printk: Replace strncmp with str_has_prefix
reboot: Replace strncmp with str_has_prefix
sched: Replace strncmp with str_has_prefix
userns: Replace strncmp with str_has_prefix
watchdog: Replace strncmp with str_has_prefix

 kernel/dma/debug.c       |  2 +-
 kernel/module.c          |  2 +-
 kernel/power/main.c      |  2 +-
 kernel/printk/braille.c  | 15 +++++++++++----
 kernel/printk/printk.c   | 22 ++++++++++++++++------
 kernel/reboot.c          |  7 +++++--
 kernel/sched/debug.c     |  6 ++++--
 kernel/sched/isolation.c | 11 +++++++----
 kernel/user_namespace.c  | 20 ++++++++++++--------
 kernel/watchdog.c        |  8 ++++----
 10 files changed, 62 insertions(+), 33 deletions(-)
Signature · 1 line
2.20.1