lkml.org 
[lkml]   [2018]   [Dec]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH v3] string.h: Add str_has_prefix() helper
On Fri, 21 Dec 2018 15:19:33 -0800
Joe Perches <joe@perches.com> wrote:

> I believe this should be bool.
>
> I don't find a use for non-zero assigned len value in the kernel
> for strncmp and I believe the function should simply be:
>
> static inline bool str_has_prefix(const char *str, const char prefix[])
> {
> return !strncmp(str, prefix, strlen(prefix));
> }

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 3bb2b3351e35..e4566b9c2553 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -172,8 +172,8 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
* it's not worth the risk */
return -EINVAL;

- if (strncmp(buf, temp, sizeof(temp) - 1) == 0) {
- buf += sizeof(temp) - 1;
+ if ((len = str_has_prefix(buf, temp))) {
+ buf += len;
sdkp->cache_override = 1;
} else {
sdkp->cache_override = 0;
And there's more places like this.

>
> It's hard to believe __always_inline vs inline matters
> for any single line function.

I've been burnt by gcc deciding to not inline single functions before.
Why take the chance? It also documents that I must be inlined, and not
just a hint.

-- Steve

\
 
 \ /
  Last update: 2018-12-22 00:26    [W:0.138 / U:0.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site