2019-03-25 19:55:26

by Hariprasad Kelam

[permalink] [raw]
Subject: [PATCH] trace: events: fix error directive in argument list

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 <[email protected]>
---
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;
- } else
-#endif
- {
+ else
ipv6_addr_set_v4mapped(*p32, pin6);
- }
+
__entry->confirmed = n->confirmed;
__entry->updated = n->updated;
__entry->used = n->used;
@@ -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;
+ if (IS_ENABLED(CONFIG_IPV6) && n->tbl->family == AF_INET6)
*pin6 = *(struct in6_addr *)n->primary_key;
- } else
-#endif
- {
+ else
ipv6_addr_set_v4mapped(*p32, pin6);
- }

__entry->confirmed = n->confirmed;
__entry->updated = n->updated;
--
2.7.4



2019-03-25 20:13:41

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] trace: events: fix error directive in argument list

On Tue, 26 Mar 2019 01:23:03 +0530
Hariprasad Kelam <[email protected]> wrote:


> ---
> 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;
> - } else
> -#endif
> - {
> + else
> ipv6_addr_set_v4mapped(*p32, pin6);
> - }
> +
> __entry->confirmed = n->confirmed;
> __entry->updated = n->updated;
> __entry->used = n->used;

Not sure why the added pin6 assignment was there to begin with:

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

It was already assigned. Looks fine to me, at least from a tracing
point of view.

-- Steve

2019-03-27 00:29:05

by Roopa Prabhu

[permalink] [raw]
Subject: Re: [PATCH] trace: events: fix error directive in argument list

On Mon, Mar 25, 2019 at 1:11 PM Steven Rostedt <[email protected]> wrote:
>
> On Tue, 26 Mar 2019 01:23:03 +0530
> Hariprasad Kelam <[email protected]> wrote:
>
>
> > ---
> > 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;
> > - } else
> > -#endif
> > - {
> > + else
> > ipv6_addr_set_v4mapped(*p32, pin6);
> > - }
> > +
> > __entry->confirmed = n->confirmed;
> > __entry->updated = n->updated;
> > __entry->used = n->used;
>
> Not sure why the added pin6 assignment was there to begin with:
>
> <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>
>
> It was already assigned. Looks fine to me, at least from a tracing
> point of view.

yes, agree. I will send a follow up patch to remove the redundant pin6
assignment.

2019-03-27 00:30:01

by Roopa Prabhu

[permalink] [raw]
Subject: Re: [PATCH] trace: events: fix error directive in argument list

On Mon, Mar 25, 2019 at 12:53 PM Hariprasad Kelam
<[email protected]> 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 <[email protected]>

Acked-by: Roopa Prabhu <[email protected]>

Thanks!

2019-03-27 15:54:32

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] trace: events: fix error directive in argument list

On Tue, 26 Mar 2019 01:23:03 +0530
Hariprasad Kelam <[email protected]> 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.

Perhaps we should blacklist the include/trace directory from sparse
checking for these types of "errors".

-- Steve


> 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 <[email protected]>
> ---
> 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;
> - } else
> -#endif
> - {
> + else
> ipv6_addr_set_v4mapped(*p32, pin6);
> - }
> +
> __entry->confirmed = n->confirmed;
> __entry->updated = n->updated;
> __entry->used = n->used;
> @@ -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;
> + if (IS_ENABLED(CONFIG_IPV6) && n->tbl->family == AF_INET6)
> *pin6 = *(struct in6_addr *)n->primary_key;
> - } else
> -#endif
> - {
> + else
> ipv6_addr_set_v4mapped(*p32, pin6);
> - }
>
> __entry->confirmed = n->confirmed;
> __entry->updated = n->updated;


2019-03-29 23:13:30

by Luc Van Oostenryck

[permalink] [raw]
Subject: Re: [PATCH] trace: events: fix error directive in argument list

On Wed, Mar 27, 2019 at 11:53:30AM -0400, Steven Rostedt wrote:
> On Tue, 26 Mar 2019 01:23:03 +0530
> Hariprasad Kelam <[email protected]> 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

2019-03-29 23:25:19

by Luc Van Oostenryck

[permalink] [raw]
Subject: Re: [PATCH] trace: events: fix error directive in argument list

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 <[email protected]>
> ---
> 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;

Same here.

-- Luc Van Oostenryck

2019-03-30 11:08:53

by Hariprasad Kelam

[permalink] [raw]
Subject: Re: [PATCH] trace: events: fix error directive in argument list

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 <[email protected]>
> > ---
> > 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

2019-03-30 12:04:26

by Luc Van Oostenryck

[permalink] [raw]
Subject: Re: [PATCH] trace: events: fix error directive in argument list

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 <[email protected]>
> > > ---
> > > 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 <[email protected]>


-- Luc

2019-03-30 12:41:59

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] trace: events: fix error directive in argument list

On Sat, 30 Mar 2019 13:01:41 +0100
Luc Van Oostenryck <[email protected]> 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

2019-03-30 13:51:41

by Roopa Prabhu

[permalink] [raw]
Subject: Re: [PATCH] trace: events: fix error directive in argument list

On Sat, Mar 30, 2019 at 5:40 AM Steven Rostedt <[email protected]> wrote:
>
> On Sat, 30 Mar 2019 13:01:41 +0100
> Luc Van Oostenryck <[email protected]> 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.