Welcome to Soft32 Linux Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

[PATCH] strstrip incorrectly marked __must_check

 
   Soft32 Home -> Linux -> Kernel RSS
Next:  pycaml override disparity  
Author Message
James Bottomley

External


Since: Sep 12, 2009
Posts: 7



(Msg. 1) Posted: Tue Nov 03, 2009 3:20 pm
Post subject: [PATCH] strstrip incorrectly marked __must_check
Archived from groups: linux>kernel (more info?)

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.

Signed-off-by: James Bottomley <James.Bottomley.DeleteThis@suse.de>

---

diff --git a/include/linux/string.h b/include/linux/string.h
index b850886..489019e 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -62,7 +62,7 @@ extern char * strnchr(const char *, size_t, int);
#ifndef __HAVE_ARCH_STRRCHR
extern char * strrchr(const char *,int);
#endif
-extern char * __must_check strstrip(char *);
+extern char * strstrip(char *);
#ifndef __HAVE_ARCH_STRSTR
extern char * strstr(const char *,const char *);
#endif


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.DeleteThis@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Andrew Morton

External


Since: Feb 02, 2007
Posts: 2592



(Msg. 2) Posted: Tue Nov 03, 2009 3:20 pm
Post subject: Re: [PATCH] strstrip incorrectly marked __must_check [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 03 Nov 2009 12:38:08 -0600
James Bottomley <James.Bottomley DeleteThis @suse.de> wrote:

> 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.
>

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);
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo DeleteThis @vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
KOSAKI Motohiro

External


Since: Nov 04, 2008
Posts: 210



(Msg. 3) Posted: Tue Nov 03, 2009 3:20 pm
Post subject: Re: [PATCH] strstrip incorrectly marked __must_check [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

2009/11/4 Matthew Wilcox <matthew.RemoveThis@wil.cx>:
>
>  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 Smile
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.RemoveThis@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Matthew Wilcox

External


Since: Dec 14, 2006
Posts: 204



(Msg. 4) Posted: Tue Nov 03, 2009 3:20 pm
Post subject: Re: [PATCH] strstrip incorrectly marked __must_check [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

static inline void strsrip_tail(char *str)
{
- char *x __used;
- x = strstrip(str);
+ char *x = strstrip(str);
+ BUG_ON(x != str);
}

--
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."
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo RemoveThis @vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Alan Cox

External


Since: Sep 11, 2004
Posts: 928



(Msg. 5) Posted: Tue Nov 03, 2009 3:20 pm
Post subject: Re: [PATCH] strstrip incorrectly marked __must_check [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 3 Nov 2009 12:04:20 -0700
Matthew Wilcox <matthew DeleteThis @wil.cx> wrote:

>
> static inline void strsrip_tail(char *str)
> {
> - 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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo DeleteThis @vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Alan Cox

External


Since: Sep 11, 2004
Posts: 928



(Msg. 6) Posted: Tue Nov 03, 2009 3:20 pm
Post subject: Re: [PATCH] strstrip incorrectly marked __must_check [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.RemoveThis@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
James Bottomley

External


Since: Sep 12, 2009
Posts: 7



(Msg. 7) Posted: Tue Nov 03, 2009 3:20 pm
Post subject: Re: [PATCH] strstrip incorrectly marked __must_check [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 2009-11-03 at 10:59 -0800, Andrew Morton wrote:
> On Tue, 03 Nov 2009 12:38:08 -0600
> James Bottomley <James.Bottomley.DeleteThis@suse.de> wrote:
>
> > 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.
> >
>
> 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.

What's the problem with the mistake ... additional leading whitespace?

> 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.

> Or..
>
> /*
> * Comment goes here
> */
> static inline void strsrip_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


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.DeleteThis@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
James Bottomley

External


Since: Sep 12, 2009
Posts: 7



(Msg. 8) Posted: Tue Nov 03, 2009 3:20 pm
Post subject: Re: [PATCH] strstrip incorrectly marked __must_check [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 2009-11-03 at 12:04 -0700, Matthew Wilcox wrote:
> static inline void strsrip_tail(char *str)
> {
> - 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


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.TakeThisOut@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Michael Holzheu

External


Since: Feb 16, 2007
Posts: 7



(Msg. 9) Posted: Mon Nov 23, 2009 7:20 am
Post subject: Re: [PATCH] strstrip incorrectly marked __must_check [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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

On Wed, 2009-11-04 at 04:58 +0900, KOSAKI Motohiro wrote:
> 2009/11/4 Alan Cox <alan.TakeThisOut@lxorguk.ukuu.org.uk>:
> >> 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
>
> Okey...
>
> [quick hack and compile check]
>
> done Smile
> sorry for attached file. I'm under poor mail environment now.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.TakeThisOut@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Display posts from previous:   
Related Topics:
[PATCH] slab: add __must_check to krealloc - From: Pekka Enberg <penberg@cs.helsinki.fi> As suggested by Arjan, make GCC warn about classic misuse of the rea...

[PATCH 1/3] IRQ: add __must_check to request_irq - This could help to find buggy drivers where request_irq return value wasn't checked. There's just no reason to ignore..

2.6.19: slight performance optimization for lib/string.c's.. - Hi, my apologies for disobeying all the rules for submitting patches, but I'll suggest a performance optimization for...

[PATCH] more isa/eisa/pci-only drivers marked as such - Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> --- diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig ind...

[PATCH -mm] Log reason why TSC was marked unstable - This patch changes mark_tsc_unstable() so it takes a string argument, which holds the reason the TSC was marked..

__must_check and driver model - I'm still seeing lots of warnings about unchecked return codes from driver model functions. These must have been aroun...
       Soft32 Home -> Linux -> Kernel All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 Windows
  Linux
 Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]