[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230328190031.65422-1-kuniyu@amazon.com>
Date: Tue, 28 Mar 2023 12:00:31 -0700
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: <mbloch@...dia.com>
CC: <davem@...emloft.net>, <dsahern@...nel.org>, <edumazet@...gle.com>,
<kuba@...nel.org>, <kuni1840@...il.com>, <kuniyu@...zon.com>,
<netdev@...r.kernel.org>, <pabeni@...hat.com>
Subject: Re: [PATCH v2 net-next 2/2] 6lowpan: Remove redundant initialisation.
From: Mark Bloch <mbloch@...dia.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@...zon.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) {
Powered by blists - more mailing lists