public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Cc: netdev@vger.kernel.org, linux-amarula@amarulasolutions.com
Subject: Re: [iproute2, RESEND PATCH 1/2] arpd: use designated initializers for msghdr structure
Date: Fri, 27 Sep 2024 14:06:45 -0700	[thread overview]
Message-ID: <20240927140645.02515695@hermes.local> (raw)
In-Reply-To: <20240922144613.2103760-1-dario.binacchi@amarulasolutions.com>

On Sun, 22 Sep 2024 16:46:12 +0200
Dario Binacchi <dario.binacchi@amarulasolutions.com> wrote:

> This patch fixes the following error:
> 
> arpd.c:442:17: error: initialization of 'int' from 'void *' makes integer from pointer without a cast [-Wint-conversion]
>   442 |                 NULL,   0,
> 
> raised by Buildroot autobuilder [1].
> 
> In the case in question, the analysis of socket.h [2] containing the
> msghdr structure shows that it has been modified with the addition of
> padding fields, which cause the compilation error. The use of designated
> initializers allows the issue to be fixed.
> 
> struct msghdr {
> 	void *msg_name;
> 	socklen_t msg_namelen;
> 	struct iovec *msg_iov;
> #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
> 	int __pad1;
> #endif
> 	int msg_iovlen;
> #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
> 	int __pad1;
> #endif
> 	void *msg_control;
> #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
> 	int __pad2;
> #endif
> 	socklen_t msg_controllen;
> #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
> 	int __pad2;
> #endif
> 	int msg_flags;
> };

That is a really bad idea to put extra padding in there.

> 
> [1] http://autobuild.buildroot.org/results/e4cdfa38ae9578992f1c0ff5c4edae3cc0836e3c/
> [2] iproute2/host/mips64-buildroot-linux-musl/sysroot/usr/include/sys/socket.h
> 
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
> ---
>  misc/arpd.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/misc/arpd.c b/misc/arpd.c
> index e77ef53928a2..b4935c23eebb 100644
> --- a/misc/arpd.c
> +++ b/misc/arpd.c
> @@ -437,10 +437,10 @@ static void get_kern_msg(void)
>  	struct iovec iov;
>  	char   buf[8192];
>  	struct msghdr msg = {
> -		(void *)&nladdr, sizeof(nladdr),
> -		&iov,	1,
> -		NULL,	0,
> -		0
> +		.msg_name = &nladdr, .msg_namelen = sizeof(nladdr),

When converting, to named initializer, please put one per line
like other code does in iproute.

> +		.msg_iov = &iov, .msg_iovlen = 1,
> +		.msg_control = (void *)NULL, .msg_controllen = 0,

The C standard says that NULL can be used for void *, cast there 
is unnecessary.

> +		.msg_flags = 0
>  	};
>  
>  	iov.iov_base = buf;


      parent reply	other threads:[~2024-09-27 21:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-22 14:46 [iproute2, RESEND PATCH 1/2] arpd: use designated initializers for msghdr structure Dario Binacchi
2024-09-22 14:46 ` [iproute2, RESEND PATCH 2/2] arpd: drop useless initializers Dario Binacchi
2024-09-27 21:06 ` Stephen Hemminger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240927140645.02515695@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=linux-amarula@amarulasolutions.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox