All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <mbloch@nvidia.com>
Cc: <davem@davemloft.net>, <dsahern@kernel.org>,
	<edumazet@google.com>, <kuba@kernel.org>, <kuni1840@gmail.com>,
	<kuniyu@amazon.com>, <netdev@vger.kernel.org>,
	<pabeni@redhat.com>
Subject: Re: [PATCH v2 net-next 2/2] 6lowpan: Remove redundant initialisation.
Date: Tue, 28 Mar 2023 12:00:31 -0700	[thread overview]
Message-ID: <20230328190031.65422-1-kuniyu@amazon.com> (raw)
In-Reply-To: <b880d6ef-fe6b-4b39-d023-b66efeae4fc8@nvidia.com>

From:   Mark Bloch <mbloch@nvidia.com>
Date:   Tue, 28 Mar 2023 09:27:43 +0300
> On 28/03/2023 2:54, Kuniyuki Iwashima wrote:
> > We'll call memset(&tmp, 0, sizeof(tmp)) later.
> 
> Why not just remove the first memset() then?

The same pattern (memset(), init, compare) is repeated twice, and
I thought it's cleaner.  I don't have no strong preference though.

Also, we need not init it if we hit 'goto out' in the first switch.

---8<---
static u8 lowpan_compress_ctx_addr(u8 **hc_ptr, const struct net_device *dev,
				   const struct in6_addr *ipaddr,
				   const struct lowpan_iphc_ctx *ctx,
				   const unsigned char *lladdr, bool sam)
{
	struct in6_addr tmp;
	u8 dam;

	switch (lowpan_dev(dev)->lltype) {
	case LOWPAN_LLTYPE_IEEE802154:
		if (lowpan_iphc_compress_ctx_802154_lladdr(ipaddr, ctx,
							   lladdr)) {
			dam = LOWPAN_IPHC_DAM_11;
			goto out;
		}
		break;
	default:
		if (lowpan_iphc_addr_equal(dev, ctx, ipaddr, lladdr)) {
			dam = LOWPAN_IPHC_DAM_11;
			goto out;
		}
		break;
	}

	memset(&tmp, 0, sizeof(tmp));
	/* check for SAM/DAM = 10 */
	tmp.s6_addr[11] = 0xFF;
	tmp.s6_addr[12] = 0xFE;
	memcpy(&tmp.s6_addr[14], &ipaddr->s6_addr[14], 2);
	/* context information are always used */
	ipv6_addr_prefix_copy(&tmp, &ctx->pfx, ctx->plen);
	if (ipv6_addr_equal(&tmp, ipaddr)) {
		lowpan_push_hc_data(hc_ptr, &ipaddr->s6_addr[14], 2);
		dam = LOWPAN_IPHC_DAM_10;
		goto out;
	}

	memset(&tmp, 0, sizeof(tmp));
	/* check for SAM/DAM = 01, should always match */
	memcpy(&tmp.s6_addr[8], &ipaddr->s6_addr[8], 8);
	/* context information are always used */
	ipv6_addr_prefix_copy(&tmp, &ctx->pfx, ctx->plen);
	if (ipv6_addr_equal(&tmp, ipaddr)) {
		lowpan_push_hc_data(hc_ptr, &ipaddr->s6_addr[8], 8);
		dam = LOWPAN_IPHC_DAM_01;
		goto out;
	}
...
}
---8<---


> 
> Mark
> 
> > 
> > Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> > ---
> >  net/6lowpan/iphc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/net/6lowpan/iphc.c b/net/6lowpan/iphc.c
> > index 52fad5dad9f7..e116d308a8df 100644
> > --- a/net/6lowpan/iphc.c
> > +++ b/net/6lowpan/iphc.c
> > @@ -848,7 +848,7 @@ static u8 lowpan_compress_ctx_addr(u8 **hc_ptr, const struct net_device *dev,
> >  				   const struct lowpan_iphc_ctx *ctx,
> >  				   const unsigned char *lladdr, bool sam)
> >  {
> > -	struct in6_addr tmp = {};
> > +	struct in6_addr tmp;
> >  	u8 dam;
> >  
> >  	switch (lowpan_dev(dev)->lltype) {

  reply	other threads:[~2023-03-28 19:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-27 23:54 [PATCH v2 net-next 0/2] ipv6: Random cleanup for in6addr_any Kuniyuki Iwashima
2023-03-27 23:54 ` [PATCH v2 net-next 1/2] ipv6: Remove in6addr_any alternatives Kuniyuki Iwashima
2023-03-28  6:27   ` Mark Bloch
2023-03-28 14:32   ` David Ahern
2023-03-27 23:54 ` [PATCH v2 net-next 2/2] 6lowpan: Remove redundant initialisation Kuniyuki Iwashima
2023-03-28  6:27   ` Mark Bloch
2023-03-28 19:00     ` Kuniyuki Iwashima [this message]
2023-03-29  8:00 ` [PATCH v2 net-next 0/2] ipv6: Random cleanup for in6addr_any patchwork-bot+netdevbpf

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=20230328190031.65422-1-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.