diff mbox

[ovs-dev,v4,1/3] nsh: fix an implicit bug in nsh_hdr_len

Message ID 1503633771-112384-2-git-send-email-yi.y.yang@intel.com
State Accepted
Headers show

Commit Message

Yang, Yi Aug. 25, 2017, 4:02 a.m. UTC
Operator '*' will be executed prior to operator '>>',
but we expect operator '>>' is executed prior to '*',
this patch fixed the issue.

Signed-off-by: Yi Yang <yi.y.yang@intel.com>
---
 include/openvswitch/nsh.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jan Scheurich Aug. 28, 2017, 11:59 a.m. UTC | #1
>  static inline uint16_t
>  nsh_hdr_len(const struct nsh_hdr *nsh)
>  {
> -    return 4 * (ntohs(nsh->ver_flags_len) & NSH_LEN_MASK) >>
> NSH_LEN_SHIFT;
> +    return ((ntohs(nsh->ver_flags_len) & NSH_LEN_MASK) >>
> + NSH_LEN_SHIFT) << 2;
>  }
> 

Why do you not just add the missing braces?

return 4 * ((ntohs(nsh->ver_flags_len) & NSH_LEN_MASK) >> NSH_LEN_SHIFT);

BR, Jan
Ben Pfaff Aug. 29, 2017, 3:42 p.m. UTC | #2
On Fri, Aug 25, 2017 at 12:02:49PM +0800, Yi Yang wrote:
> Operator '*' will be executed prior to operator '>>',
> but we expect operator '>>' is executed prior to '*',
> this patch fixed the issue.
> 
> Signed-off-by: Yi Yang <yi.y.yang@intel.com>

Applied to master and branch-2.8, thanks!
diff mbox

Patch

diff --git a/include/openvswitch/nsh.h b/include/openvswitch/nsh.h
index f4ccadc..a3611d0 100644
--- a/include/openvswitch/nsh.h
+++ b/include/openvswitch/nsh.h
@@ -113,7 +113,7 @@  struct nsh_hdr {
 static inline uint16_t
 nsh_hdr_len(const struct nsh_hdr *nsh)
 {
-    return 4 * (ntohs(nsh->ver_flags_len) & NSH_LEN_MASK) >> NSH_LEN_SHIFT;
+    return ((ntohs(nsh->ver_flags_len) & NSH_LEN_MASK) >> NSH_LEN_SHIFT) << 2;
 }
 
 static inline struct nsh_md1_ctx *