strstrip incorrectly marked __must_check
Subsystems (4)
PATCH 1/1 strstrip incorrectly marked __must_check
strstrip strips whitespace from the beginning and end of a string. I agree you have to take the returned pointer if you want to strip from the beginning. However, if you wish to keep the whitespace at the beginning and only wish strstrip to remove it from the end, then it's entirely legitimate to discard the returned pointer.
This is what we have in drivers/scsi/ipr.c and the patch to make strstrip __must_check is now causing SCSI spurious warnings in that code.
---
include/linux/string.h +1 -1
@@ -62,7 +62,7 @@ extern char * strnchr(const char *, size_t, int);#ifndef __HAVE_ARCH_STRRCHRextern char *strrchr (const char *,int );#endif -extern char *__must_check strstrip (char *); +extern char *strstrip (char *);#ifndef __HAVE_ARCH_STRSTRextern char *strstr (const char *,const char *);#endif
Andrew Morton
maintainerQuoted 10 lines · On Tue, 03 Nov 2009 12:38:08 -0600 James Bottomley <[email protected]>…
strstrip strips whitespace from the beginning and end of a string. I agree you have to take the returned pointer if you want to strip from the beginning. However, if you wish to keep the whitespace at the beginning and only wish strstrip to remove it from the end, then it's entirely legitimate to discard the returned pointer.
This is what we have in
drivers/scsi/ipr.cand the patch to make strstrip__must_checkis now causing SCSI spurious warnings in that code.
Would prefer to keep the warning and to patch ipr.c, please. We found I think three call sites which were incorrectly ignoring the strstrip() return value and it's reasonable to fear that others will make the same mistake in the future.
And maybe ipr.c _should_ be patched. Right now it's assuming that the string coming back from the device has no leading whitespace. Why trim any possible trailing whitespace but not trim any possible leading whitespace?
Or..
/*
* Comment goes here
*/
static inline void strsrip_tail(char *str)
{
char *x __used;
x = strstrip(str);
} static inline void strsrip_tail(char *str)
{
- char *x __used;
- x = strstrip(str);
+ char *x = strstrip(str);
+ BUG_ON(x != str);
}
Signature · 4 lines
Matthew Wilcox Intel Open Source Technology Centre "Bill, look, we understand that you're interested in selling us this operating system, but compare it to ours. We can't possibly take such a retrograde step."
2009/11/4 Matthew Wilcox <[email protected]>:
Quoted 8 lines
static inline void
strsrip_tail(char *str)
{
- char *x__used;
- x = strstrip(str);
+ char *x = strstrip(str);
+BUG_ON(x != str);
}
Looks reasonable to me :)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Review
Quoted 7 lines · On Tue, 3 Nov 2009 12:04:20 -0700 Matthew Wilcox <[email protected]> wrote:
static inline void
strsrip_tail(char *str)
{(quoted diff) +2
-2- char *x __used; - x = strstrip(str); + char *x = strstrip(str); + BUG_ON(x != str);
That breaks it. It was fine before you did that but now it blows up if there are leading spaces.
Review
Quoted 7 lines · Matthew Wilcox
static inline void
strsrip_tail(char *str)
{(quoted diff) +2
-2- char *x __used; - x = strstrip(str); + char *x = strstrip(str); + BUG_ON(x != str); }
Please, no. I said didn't care about leading whitespace ... I didn't say there wasn't any.
James
Quoted 14 lines · Andrew Morton
Quoted 10 lines · On Tue, 03 Nov 2009 12:38:08 -0600 James Bottomley <[email protected]>…
strstrip strips whitespace from the beginning and end of a string. I agree you have to take the returned pointer if you want to strip from the beginning. However, if you wish to keep the whitespace at the beginning and only wish strstrip to remove it from the end, then it's entirely legitimate to discard the returned pointer.
This is what we have in
drivers/scsi/ipr.cand the patch to make strstrip__must_checkis now causing SCSI spurious warnings in that code.
Quoted 4 lines
Would prefer to keep the warning and to patch
ipr.c, please. We found I think three call sites which were incorrectly ignoring thestrstrip()return value and it's reasonable to fear that others will make the same mistake in the future.
What's the problem with the mistake ... additional leading whitespace?
Quoted 4 lines
And maybe
ipr.c_should_ be patched. Right now it's assuming that the string coming back from the device has no leading whitespace. Why trim any possible trailing whitespace but not trim any possible leading whitespace?
I think it doesn't care. It wants to append an error code to the string, and to make it more visible it wants to strip trailing whitespace before doing so.
Quoted 10 lines
Or..
/*
* Comment goes here
*/
static inline voidstrsrip_tail(char *str){ char *x __used; x = strstrip(str); }
Yes, I could go for that ... I just don't see such a problem with the currently overloaded uses of strstrip.
James
Quoted 5 lines
static inline void
strsrip_tail(char *str){ char *x __used; x = strstrip(str); }
Bikeshed time but its cleaner to do
static inline __must_check void strstrip(char *str)
{
return strim(str);
}and make strim() the old strstrip function without the check requirement
Alan
2009/11/4 Alan Cox <[email protected]>:
Quoted 6 lines
Quoted 5 lines
static inline void
strsrip_tail(char *str)
{
char *x__used;
x = strstrip(str);
}
Quoted 8 lines
Bikeshed time but its cleaner to do
static inline
__must_checkvoidstrstrip(char *str){
return strim(str);
}and make
strim()the old strstrip function without the check requirement
Okey...
[quick hack and compile check]
done :)
sorry for attached file. I'm under poor mail environment now.
From 94a86424a882d52fcd11039d11fbd0363a31472f Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <[email protected]>
Date: Wed, 4 Nov 2009 04:47:23 +0900
Subject: [PATCH] lib: Introduce strim
Recently, We marked strstrip() as must_check. because it was frequently misused and it should be checked. however, we found one exception. scsi/ipr.c intentionally ignore return value of strstrip. because, it wish to keep the whitespace at the beginning.
Thus, we need to keep with and without checked whitespace trim function. This patch makes strim new function and ipr.c use it.
--- drivers/scsi/ipr.c | 4 ++-- include/linux/string.h | 9 ++++++++- lib/string.c | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-)
drivers/scsi/ipr.c +2 -2
@@ -1333,7 +1333,7 @@ static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg, error = &hostrcb->hcam.u.error.u.type_17_error; error->failure_reason[sizeof (error->failure_reason) -1 ] ='\0' ; -strstrip (error->failure_reason); +strim (error->failure_reason);ipr_hcam_err (hostrcb,"%s [PRC: %08X]\n" , error->failure_reason,be32_to_cpu (hostrcb->hcam.u.error.prc));
@@ -1359,7 +1359,7 @@ static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg, error = &hostrcb->hcam.u.error.u.type_07_error; error->failure_reason[sizeof (error->failure_reason) -1 ] ='\0' ; -strstrip (error->failure_reason); +strim (error->failure_reason);ipr_hcam_err (hostrcb,"%s [PRC: %08X]\n" , error->failure_reason,be32_to_cpu (hostrcb->hcam.u.error.prc));
include/linux/string.h +8 -1
@@ -62,7 +62,14 @@ extern char * strnchr(const char *, size_t, int);#ifndef __HAVE_ARCH_STRRCHRextern char *strrchr (const char *,int );#endif -extern char *__must_check strstrip (char *); + +extern char *strim (char *); + +static inline __must_check char *strstrip (char *str) +{ +return strim (str); +} +#ifndef __HAVE_ARCH_STRSTRextern char *strstr (const char *,const char *);#endif
lib/string.c +3 -3
@@ -330,14 +330,14 @@ EXPORT_SYMBOL(strnchr);#endif /** -* strstrip - Removes leading and trailing whitespace from @s. +* strim - Removes leading and trailing whitespace from @s. * @s: The string to be stripped. * * Note that the first trailing whitespace is replaced with a %NUL-terminator * in the given string @s. Returns a pointer to the first non-whitespace * character in @s. */ -char *strstrip (char *s) +char *strim (char *s) {size_t size;char *end;
@@ -357,7 +357,7 @@ char *strstrip(char *s)return s; } -EXPORT_SYMBOL (strstrip); +EXPORT_SYMBOL (strim);#ifndef __HAVE_ARCH_STRLEN/**
Signature · 1 line
1.6.2.5
Hi,
I have several places in my code where the new __must_check of strstrip will introduce unnecessary dummy variables to avoid the warnings.
Therefore I would like to have the suggested new strim() or strstip_tail() function. Any chance to have this upstream soon?
Michael
Quoted 22 lines · KOSAKI Motohiro
2009/11/4 Alan Cox <[email protected]>:
Quoted 6 lines
Quoted 5 lines
static inline void
strsrip_tail(char *str){ char *x __used; x = strstrip(str); }Quoted 8 lines
Bikeshed time but its cleaner to do
static inline
__must_checkvoidstrstrip(char *str){ return strim(str); }and make
strim()the old strstrip function without the check requirementOkey...
[quick hack and compile check]
done :)
sorry for attached file. I'm under poor mail environment now.
Quoted 7 lines
Hi,
I have several places in my code where the new
__must_checkof strstrip will introduce unnecessary dummy variables to avoid the warnings.Therefore I would like to have the suggested new
strim()orstrstip_tail()function. Any chance to have this upstream soon?
strim() is in mmotm now. I expect it will merge mainline soon.
Thanks.
Quoted 27 lines
Michael
Quoted 22 lines · KOSAKI Motohiro
2009/11/4 Alan Cox <[email protected]>:
Quoted 6 lines
Quoted 5 lines
static inline void
strsrip_tail(char *str){ char *x __used; x = strstrip(str); }Quoted 8 lines
Bikeshed time but its cleaner to do
static inline
__must_checkvoidstrstrip(char *str){ return strim(str); }and make
strim()the old strstrip function without the check requirementOkey...
[quick hack and compile check]
done :)
sorry for attached file. I'm under poor mail environment now.
Quoted 9 lines · KOSAKI Motohiro
Quoted 7 lines
Hi,
I have several places in my code where the new
__must_checkof strstrip will introduce unnecessary dummy variables to avoid the warnings.Therefore I would like to have the suggested new
strim()orstrstip_tail()function. Any chance to have this upstream soon?
strim()is in mmotm now. I expect it will merge mainline soon.
That's really good news!
Thanks!
Michael