lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Y/XYpLz6K78T2elz@gmail.com>
Date:   Wed, 22 Feb 2023 08:56:04 +0000
From:   Martin Habets <habetsm.xilinx@...il.com>
To:     Edward Cree <ecree.xilinx@...il.com>
Cc:     Leon Romanovsky <leon@...nel.org>, edward.cree@....com,
        linux-net-drivers@....com, davem@...emloft.net, kuba@...nel.org,
        pabeni@...hat.com, edumazet@...gle.com, netdev@...r.kernel.org
Subject: Re: [PATCH net-next] sfc: support offloading TC VLAN push/pop
 actions to the MAE

On Tue, Feb 21, 2023 at 08:32:13PM +0000, Edward Cree wrote:
> On 19/02/2023 09:21, Leon Romanovsky wrote:
> > On Thu, Feb 16, 2023 at 04:04:42PM +0000, edward.cree@....com wrote:
> >> From: Edward Cree <ecree.xilinx@...il.com>
> >>
> >> EF100 can pop and/or push up to two VLAN tags.
> >>
> >> Signed-off-by: Edward Cree <ecree.xilinx@...il.com>
> ...
> >> +	/* Translate vlan actions from bitmask to count */
> >> +	switch (act->vlan_push) {
> >> +	case 0:
> >> +	case 1:
> >> +		vlan_push = act->vlan_push;
> >> +		break;
> >> +	case 2: /* can't happen */
> > 
> > There is no need in case here as "default" will catch.
> > 
> >> +	default:
> >> +		return -EINVAL;
> >> +	case 3:
> >> +		vlan_push = 2;
> >> +		break;
> >> +	}
> >> +	switch (act->vlan_pop) {
> >> +	case 0:
> >> +	case 1:
> >> +		vlan_pop = act->vlan_pop;
> >> +		break;
> >> +	case 2: /* can't happen */
> >> +	default:
> >> +		return -EINVAL;
> > 
> > Please rely switch-case semantics and don't put default in the middle.
> 
> It's legal C and as far as I can tell there's nothing in coding-style.rst
>  about it; I did it this way so as to put the cases in the logical(?)
>  ascending order and try to make the code self-document the possible
>  values of the act-> fields.
> Arguably it's the 'default:' rather than the 'case 2:' that's unnecessary
>  as the switch argument is an unsigned:2 bitfield, so it can only take on
>  these four values.

Can you replace the switch statement with
 vlan_push = act->vlan_push & 1 + act->vlan_push & 2;
Even then it would seem prudent to guard against  act->vlan_push == 2.

Martin

> Although on revisiting this code I wonder if it makes more sense just to
>  use the 'count' (rather than 'bitmask') form throughout, including in
>  act->vlan_push/pop; it makes the tc.c side of the code slightly more
>  involved, but gets rid of this translation entirely.  WDYT?
> 
> -ed

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ