Linux SPARSE checker discussions
 help / color / mirror / Atom feed
* Re: [PATCH] trace: events: fix  error directive in argument list
       [not found] ` <20190327115330.04b5b481@gandalf.local.home>
@ 2019-03-29 23:12   ` Luc Van Oostenryck
  0 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2019-03-29 23:12 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Hariprasad Kelam, mingo, roopa, davem, linux-kernel, linux-sparse

On Wed, Mar 27, 2019 at 11:53:30AM -0400, Steven Rostedt wrote:
> On Tue, 26 Mar 2019 01:23:03 +0530
> Hariprasad Kelam <hariprasad.kelam@gmail.com> wrote:
> 
> > This patch fixes below spare errors.
> > 
> > Sparse error:
> > make C=2 CF=-D__CHECK_ENDIAN__ M=net/core
> > ./include/trace/events/neigh.h:73:1: error: directive in argument list
> > ./include/trace/events/neigh.h:78:1: error: directive in argument list
> > ./include/trace/events/neigh.h:150:1: error: directive in argument list
> > ./include/trace/events/neigh.h:155:1: error: directive in argument list
> > 
> 
> I have nothing really against these patches, but why is the current
> code considered wrong?
> 
> Note, TRACE_EVENTS() are "special macros". They hold structure
> definitions and full code inside the argument list. There should be no
> reason that this is causing a warning.

The problem is that #ifdefs at line 73 & 150 are inside TRACE_EVENT()'s
invocation and this is undefined behaviour. From the standard:
	... If there are sequences of preprocessing tokens within the
	list of arguments that would otherwise act as preprocessing
	directives, the behavior is undefined. 

	[C90 6.8.3, C99 & C11 6.10.3p11]

GCC can handle it (and sparse too) but yes sparse complains about it.

-- Luc Van Oostenryck

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] trace: events: fix  error directive in argument list
       [not found] ` <20190329232215.itsvo3jj3lu4gr7k@ltop.local>
@ 2019-03-30 11:07   ` Hariprasad Kelam
  2019-03-30 12:01     ` Luc Van Oostenryck
  0 siblings, 1 reply; 5+ messages in thread
From: Hariprasad Kelam @ 2019-03-30 11:07 UTC (permalink / raw)
  To: Luc Van Oostenryck, Steven Rostedt, mingo, roopa, davem,
	linux-kernel, linux-sparse

On Sat, Mar 30, 2019 at 12:22:17AM +0100, Luc Van Oostenryck wrote:
> On Tue, Mar 26, 2019 at 01:23:03AM +0530, Hariprasad Kelam wrote:
> > This patch fixes below spare errors.
> > 
> > Sparse error:
> > make C=2 CF=-D__CHECK_ENDIAN__ M=net/core
> > ./include/trace/events/neigh.h:73:1: error: directive in argument list
> > ./include/trace/events/neigh.h:78:1: error: directive in argument list
> > ./include/trace/events/neigh.h:150:1: error: directive in argument list
> > ./include/trace/events/neigh.h:155:1: error: directive in argument list
> > 
> > Changes below two lines to signle line to avoid sparse error
> >  #if IS_ENABLED(CONFIG_IPV6)
> >                if (n->tbl->family == AF_INET6) {
> > to if (IS_ENABLED(CONFIG_IPV6) && n->tbl->family == AF_INET6)
> > 
> > and removes reassigning pin6 pointer when IPV6 is enabled
> > 
> > Signed-off-by: Hariprasad Kelam <hariprasad.kelam@gmail.com>
> > ---
> >  include/trace/events/neigh.h | 19 +++++--------------
> >  1 file changed, 5 insertions(+), 14 deletions(-)
> > 
> > diff --git a/include/trace/events/neigh.h b/include/trace/events/neigh.h
> > index 0bdb085..6e310ea 100644
> > --- a/include/trace/events/neigh.h
> > +++ b/include/trace/events/neigh.h
> > @@ -70,15 +70,11 @@ TRACE_EVENT(neigh_update,
> >  		else
> >  			*p32 = 0;
> >  
> > -#if IS_ENABLED(CONFIG_IPV6)
> > -		if (n->tbl->family == AF_INET6) {
> > -			pin6 = (struct in6_addr *)__entry->primary_key6;
> > +		if (IS_ENABLED(CONFIG_IPV6) && n->tbl->family == AF_INET6)
> >  			*pin6 = *(struct in6_addr *)n->primary_key;
> 
> Why removing the line wheer pin6 is assigned?
> IMO, the patch should be:
> -#if IS_ENABLED(CONFIG_IPV6)
> -		if (n->tbl->family == AF_INET6) {
> +		if (IS_ENABLED(CONFIG_IPV6) && n->tbl->family == AF_INET6)
>  			pin6 = (struct in6_addr *)__entry->primary_key6;
>   			*pin6 = *(struct in6_addr *)n->primary_key;
> 
> > @@ -147,15 +143,10 @@ DECLARE_EVENT_CLASS(neigh__update,
> >  		else
> >  			*p32 = 0;
> >  
> > -#if IS_ENABLED(CONFIG_IPV6)
> > -		if (n->tbl->family == AF_INET6) {
> > -			pin6 = (struct in6_addr *)__entry->primary_key6;
>
pin6  is already assinged .Assinging pin6 is redudant in if loop
 Below is the original code
 <code-snippet>
		pin6 = (struct in6_addr *)__entry->primary_key6;
		p32 = (__be32 *)__entry->primary_key4;

		if (n->tbl->family == AF_INET)
			*p32 = *(__be32 *)n->primary_key;
		else
			*p32 = 0;

#if IS_ENABLED(CONFIG_IPV6)
		if (n->tbl->family == AF_INET6) {
                       pin6 = (struct in6_addr *)__entry->primary_key6;
		       *pin6 = *(struct in6_addr *)n->primary_key;
		} else
#endif
                {
			ipv6_addr_set_v4mapped(*p32, pin6);
		}
 </code-snippet>


> Same here.
> 
> -- Luc Van Oostenryck

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] trace: events: fix  error directive in argument list
  2019-03-30 11:07   ` Hariprasad Kelam
@ 2019-03-30 12:01     ` Luc Van Oostenryck
  2019-03-30 12:40       ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: Luc Van Oostenryck @ 2019-03-30 12:01 UTC (permalink / raw)
  To: Hariprasad Kelam
  Cc: Steven Rostedt, mingo, roopa, davem, linux-kernel, linux-sparse

On Sat, Mar 30, 2019 at 04:37:48PM +0530, Hariprasad Kelam wrote:
> On Sat, Mar 30, 2019 at 12:22:17AM +0100, Luc Van Oostenryck wrote:
> > On Tue, Mar 26, 2019 at 01:23:03AM +0530, Hariprasad Kelam wrote:
> > > This patch fixes below spare errors.
> > > 
> > > Sparse error:
> > > make C=2 CF=-D__CHECK_ENDIAN__ M=net/core
> > > ./include/trace/events/neigh.h:73:1: error: directive in argument list
> > > ./include/trace/events/neigh.h:78:1: error: directive in argument list
> > > ./include/trace/events/neigh.h:150:1: error: directive in argument list
> > > ./include/trace/events/neigh.h:155:1: error: directive in argument list
> > > 
> > > Changes below two lines to signle line to avoid sparse error
> > >  #if IS_ENABLED(CONFIG_IPV6)
> > >                if (n->tbl->family == AF_INET6) {
> > > to if (IS_ENABLED(CONFIG_IPV6) && n->tbl->family == AF_INET6)
> > > 
> > > and removes reassigning pin6 pointer when IPV6 is enabled
> > > 
> > > Signed-off-by: Hariprasad Kelam <hariprasad.kelam@gmail.com>
> > > ---
> > >  include/trace/events/neigh.h | 19 +++++--------------
> > >  1 file changed, 5 insertions(+), 14 deletions(-)
> > > 
> > > diff --git a/include/trace/events/neigh.h b/include/trace/events/neigh.h
> > > index 0bdb085..6e310ea 100644
> > > --- a/include/trace/events/neigh.h
> > > +++ b/include/trace/events/neigh.h
> > > @@ -70,15 +70,11 @@ TRACE_EVENT(neigh_update,
> > >  		else
> > >  			*p32 = 0;
> > >  
> > > -#if IS_ENABLED(CONFIG_IPV6)
> > > -		if (n->tbl->family == AF_INET6) {
> > > -			pin6 = (struct in6_addr *)__entry->primary_key6;
> > > +		if (IS_ENABLED(CONFIG_IPV6) && n->tbl->family == AF_INET6)
> > >  			*pin6 = *(struct in6_addr *)n->primary_key;
> > 
> > Why removing the line wheer pin6 is assigned?
> > IMO, the patch should be:
> > -#if IS_ENABLED(CONFIG_IPV6)
> > -		if (n->tbl->family == AF_INET6) {
> > +		if (IS_ENABLED(CONFIG_IPV6) && n->tbl->family == AF_INET6)
> >  			pin6 = (struct in6_addr *)__entry->primary_key6;
> >   			*pin6 = *(struct in6_addr *)n->primary_key;
> > 
> > > @@ -147,15 +143,10 @@ DECLARE_EVENT_CLASS(neigh__update,
> > >  		else
> > >  			*p32 = 0;
> > >  
> > > -#if IS_ENABLED(CONFIG_IPV6)
> > > -		if (n->tbl->family == AF_INET6) {
> > > -			pin6 = (struct in6_addr *)__entry->primary_key6;
> >
> pin6  is already assigned.

OK, I see. IMO, it would be better to have 2 patches for this:
one for the redundant assignment to pin6 and anotther one for
the IS_ENABLED() change but feel free, if needed, to add my

  Reviewed-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>


-- Luc

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] trace: events: fix  error directive in argument list
  2019-03-30 12:01     ` Luc Van Oostenryck
@ 2019-03-30 12:40       ` Steven Rostedt
  2019-03-30 13:50         ` Roopa Prabhu
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2019-03-30 12:40 UTC (permalink / raw)
  To: Luc Van Oostenryck
  Cc: Hariprasad Kelam, mingo, roopa, davem, linux-kernel, linux-sparse

On Sat, 30 Mar 2019 13:01:41 +0100
Luc Van Oostenryck <luc.vanoostenryck@gmail.com> wrote:

> OK, I see. IMO, it would be better to have 2 patches for this:
> one for the redundant assignment to pin6 and anotther one for
> the IS_ENABLED() change but feel free, if needed, to add my

I agree with it being separate patches. I'm big on the "one patch
accomplishes one task" ideology.

-- Steve

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] trace: events: fix error directive in argument list
  2019-03-30 12:40       ` Steven Rostedt
@ 2019-03-30 13:50         ` Roopa Prabhu
  0 siblings, 0 replies; 5+ messages in thread
From: Roopa Prabhu @ 2019-03-30 13:50 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Luc Van Oostenryck, Hariprasad Kelam, mingo, David Miller,
	Linux Kernel Mailing List, linux-sparse

On Sat, Mar 30, 2019 at 5:40 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Sat, 30 Mar 2019 13:01:41 +0100
> Luc Van Oostenryck <luc.vanoostenryck@gmail.com> wrote:
>
> > OK, I see. IMO, it would be better to have 2 patches for this:
> > one for the redundant assignment to pin6 and anotther one for
> > the IS_ENABLED() change but feel free, if needed, to add my
>
> I agree with it being separate patches. I'm big on the "one patch
> accomplishes one task" ideology.
>

yes, I will take care of the pin6 assignment separately. This patch
can only address the sparse error.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-03-30 13:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20190325195303.GA20629@hari-Inspiron-1545>
     [not found] ` <20190327115330.04b5b481@gandalf.local.home>
2019-03-29 23:12   ` [PATCH] trace: events: fix error directive in argument list Luc Van Oostenryck
     [not found] ` <20190329232215.itsvo3jj3lu4gr7k@ltop.local>
2019-03-30 11:07   ` Hariprasad Kelam
2019-03-30 12:01     ` Luc Van Oostenryck
2019-03-30 12:40       ` Steven Rostedt
2019-03-30 13:50         ` Roopa Prabhu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox