DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anoob Joseph <anoob.joseph@caviumnetworks.com>
To: Akhil Goyal <akhil.goyal@nxp.com>,
	Pablo de Lara <pablo.de.lara.guarch@intel.com>
Cc: "Dwivedi, Ankur" <Ankur.Dwivedi@cavium.com>,
	"Jacob,  Jerin" <Jerin.JacobKollanukkaran@cavium.com>,
	"Athreya, Narayana Prasad" <NarayanaPrasad.Athreya@cavium.com>,
	"dev@dpdk.org" <dev@dpdk.org>,
	"Joseph, Anoob" <Anoob.Joseph@cavium.com>
Subject: [dpdk-dev] [PATCH] common/cpt: fix bad shift operation
Date: Thu, 15 Nov 2018 05:10:27 +0000
Message-ID: <1542258584-5779-1-git-send-email-anoob.joseph@caviumnetworks.com> (raw)

From: Ankur Dwivedi <ankur.dwivedi@caviumnetworks.com>

Coverity Issue: 323477

Using the rte_bsf32 function to find last set bit. This avoids
the for loop and hence the bad bit shift operation.

Fixes: 351fbee21986 ("common/cpt: support hash")

Signed-off-by: Ankur Dwivedi <ankur.dwivedi@caviumnetworks.com>
Signed-off-by: Anoob Joseph <anoob.joseph@caviumnetworks.com>
---
 drivers/common/cpt/cpt_ucode.h | 37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/drivers/common/cpt/cpt_ucode.h b/drivers/common/cpt/cpt_ucode.h
index c5a9f34..5933ea7 100644
--- a/drivers/common/cpt/cpt_ucode.h
+++ b/drivers/common/cpt/cpt_ucode.h
@@ -3449,32 +3449,27 @@ find_kasumif9_direction_and_length(uint8_t *src,
 				   uint8_t *addr_direction)
 {
 	uint8_t found = 0;
+	uint32_t pos;
+	uint8_t last_byte;
 	while (!found && counter_num_bytes > 0) {
 		counter_num_bytes--;
 		if (src[counter_num_bytes] == 0x00)
 			continue;
-		if (src[counter_num_bytes] == 0x80) {
-			*addr_direction  =  src[counter_num_bytes - 1] & 0x1;
-			*addr_length_in_bits = counter_num_bytes * 8  - 1;
-			found = 1;
-		} else {
-			int i = 0;
-			uint8_t last_byte = src[counter_num_bytes];
-			for (i = 0; i < 8 && found == 0; i++) {
-				if (last_byte & (1 << i)) {
-					*addr_direction = (last_byte >> (i+1))
-							  & 0x1;
-					if (i != 6)
-						*addr_length_in_bits =
-							counter_num_bytes * 8
-							+ (8 - (i + 2));
-					else
-						*addr_length_in_bits =
-							counter_num_bytes * 8;
-					found = 1;
-					}
-				}
+		pos = rte_bsf32(src[counter_num_bytes]);
+		if (pos == 7) {
+			if (likely(counter_num_bytes > 0)) {
+				last_byte = src[counter_num_bytes - 1];
+				*addr_direction  =  last_byte & 0x1;
+				*addr_length_in_bits = counter_num_bytes * 8
+							- 1;
 			}
+		} else {
+			last_byte = src[counter_num_bytes];
+			*addr_direction = (last_byte >> (pos + 1)) & 0x1;
+			*addr_length_in_bits = counter_num_bytes * 8
+						+ (8 - (pos + 2));
+		}
+		found = 1;
 	}
 }
 
-- 
2.7.4

             reply	other threads:[~2018-11-15  5:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-15  5:10 Anoob Joseph [this message]
2018-11-18 16:36 ` Thomas Monjalon

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=1542258584-5779-1-git-send-email-anoob.joseph@caviumnetworks.com \
    --to=anoob.joseph@caviumnetworks.com \
    --cc=Ankur.Dwivedi@cavium.com \
    --cc=Anoob.Joseph@cavium.com \
    --cc=Jerin.JacobKollanukkaran@cavium.com \
    --cc=NarayanaPrasad.Athreya@cavium.com \
    --cc=akhil.goyal@nxp.com \
    --cc=dev@dpdk.org \
    --cc=pablo.de.lara.guarch@intel.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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git