From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-eopbgr790047.outbound.protection.outlook.com [40.107.79.47]) by dpdk.org (Postfix) with ESMTP id 470EC2F42 for ; Thu, 15 Nov 2018 06:10:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zfd3z6m00YDOktLJMT6ozew20l1y1DVJ5cXmeBM3Z70=; b=XNSywygicjoeYiRnpg6ooTTPMDhQaoiAcyLm/9s8W+MZ7+LmuXQnmD3gy95G5Mmm4zGfUKTGwM0I4iNUQTr3U1ZIS6LjgFKL0w+jcdIYTxRLMisInoo3zcOu9AT0PM0dbRl6vFD67GGNU6dLPwV5XxZydidNj61nTDQOYFv3kT8= Received: from DM6PR07MB4905.namprd07.prod.outlook.com (20.176.81.138) by DM6PR07MB5531.namprd07.prod.outlook.com (20.178.2.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.25; Thu, 15 Nov 2018 05:10:28 +0000 Received: from DM6PR07MB4905.namprd07.prod.outlook.com ([fe80::4519:873:f63b:b136]) by DM6PR07MB4905.namprd07.prod.outlook.com ([fe80::4519:873:f63b:b136%5]) with mapi id 15.20.1294.045; Thu, 15 Nov 2018 05:10:28 +0000 From: Anoob Joseph To: Akhil Goyal , Pablo de Lara CC: "Dwivedi, Ankur" , "Jacob, Jerin" , "Athreya, Narayana Prasad" , "dev@dpdk.org" , "Joseph, Anoob" Thread-Topic: [PATCH] common/cpt: fix bad shift operation Thread-Index: AQHUfKGFVFIsirjeUU2V9/IrilYAsA== Date: Thu, 15 Nov 2018 05:10:27 +0000 Message-ID: <1542258584-5779-1-git-send-email-anoob.joseph@caviumnetworks.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [115.113.156.2] x-clientproxiedby: BMXPR01CA0013.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:d::23) To DM6PR07MB4905.namprd07.prod.outlook.com (2603:10b6:5:a3::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Anoob.Joseph@cavium.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM6PR07MB5531; 6:4AWK5Oro4utn8VJqfS7L4nqkD35MCASAyjkQNcIoF9gtdKqBLIWc+F+IQJZgVbHskHfy4v56o+zBW8giNIGwYhlo4KAm/liY7RJbt5SyT94NmWhqp3ZOUHe+PYUZdFXrRQAKg1/ljuSUpxsGqKYnkrxaDW7fkHDkfHZVtRCjWuHPgzCgcSGiEz3Pg799q/ASSDe3+rdNW9LQ4+QHONI78l5Yb26/tOmz1cW7F2HkZKSYbf2tOzxwn7sVHgk1Zxs0AIWYA1cGqzxwYAbQahLMech0IEOdvUSnELL+hqUsaSnlcfoG7kWJVx5m/Bb3LzeId2Nc/X83Rt+IqrqIsX24ra5isp47wxSAgolr0uPDL7cCevPiUZ+FAhwWFdU0UuSgA58fAiHfYcVGwlS0k5eGPqWCUTBoq0xSTtkBVh/kGN7+kRERQChblo7PIjm+Ox5Pzas0uPxh8peybDmLRm7YMA==; 5:dhPBRGNn1BdEgMXAwr895ak+ClBV9vDz2lK/9qb3e1XzBhj/sqVYLao5m99P+RGQAkukxqI/DKGlVv2bfzYFccYrJ91/lYwNZ6BcKzzVmqqDlGfiV1/KRRNaYqlrFaew05jov1jqRmv/sBx5C9BQShBi1CCDzsJrWLFT1i0LpCQ=; 7:K++UH0CugL4af7DQg61ujG1b4GUbU0HdHEmHfcVKfLWctTQEr3glVz1AH6phoH1BrVvoPW/3E8z/YU+gmpxn8B7XtT6/jk6xzxFwlSwdPneKrW2mQGo68IigACTRksbOie6xAbV+95xtWm3WxpTDig== x-ms-office365-filtering-correlation-id: b58c9274-caaf-46c2-e020-08d64ab8a7ef x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DM6PR07MB5531; x-ms-traffictypediagnostic: DM6PR07MB5531: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(3231415)(944501410)(52105112)(10201501046)(93006095)(148016)(149066)(150057)(6041310)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM6PR07MB5531; BCL:0; PCL:0; RULEID:; SRVR:DM6PR07MB5531; x-forefront-prvs: 08572BD77F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(136003)(39860400002)(376002)(346002)(366004)(199004)(189003)(36756003)(2906002)(386003)(55236004)(316002)(42882007)(102836004)(26005)(14454004)(256004)(2900100001)(81156014)(81166006)(8676002)(8936002)(6512007)(7736002)(110136005)(305945005)(6506007)(68736007)(53936002)(6436002)(54906003)(186003)(97736004)(6116002)(486006)(52116002)(5660300001)(478600001)(25786009)(4326008)(107886003)(66066001)(2616005)(6486002)(1857600001)(99286004)(71190400001)(105586002)(476003)(72206003)(71200400001)(3846002)(106356001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR07MB5531; H:DM6PR07MB4905.namprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: aOfRvBGeR+z/hWOt7CGzoGD7UDpWMN4vDzwo36GCCD4kkA9tvTpgYSkMX5tg5MpbuQrSssSwm+OYNORQwAL3cRufKW22DuO5nwFeSKEasqneJvMiRvC2uGpLzFqAEnRKGqgBRhRYXbsHxerCxHdxI7CQKcClVbBdWEsGenxrIU+JLhYJlP/IU/JHHZklEDbALQoG7TOLdG1wRBaLzqNSZMCHAe8CvDVbyRfJRvmdzkTvQtAn+gdLzFqnaqknccTPA6E/BUrOsI9jUOBfIs2uZ9LrOjm2gSn8EKRO9icvCI+rgeHjTr32rKLy38GO3dWBtHk3HxRDqN7Fvcg3R8ovZUS47Gf7EsR0NbxzQpRoLI8= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-Network-Message-Id: b58c9274-caaf-46c2-e020-08d64ab8a7ef X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Nov 2018 05:10:27.9502 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR07MB5531 Subject: [dpdk-dev] [PATCH] common/cpt: fix bad shift operation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Nov 2018 05:10:30 -0000 From: Ankur Dwivedi 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 Signed-off-by: Anoob Joseph --- 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 =3D 0; + uint32_t pos; + uint8_t last_byte; while (!found && counter_num_bytes > 0) { counter_num_bytes--; if (src[counter_num_bytes] =3D=3D 0x00) continue; - if (src[counter_num_bytes] =3D=3D 0x80) { - *addr_direction =3D src[counter_num_bytes - 1] & 0x1; - *addr_length_in_bits =3D counter_num_bytes * 8 - 1; - found =3D 1; - } else { - int i =3D 0; - uint8_t last_byte =3D src[counter_num_bytes]; - for (i =3D 0; i < 8 && found =3D=3D 0; i++) { - if (last_byte & (1 << i)) { - *addr_direction =3D (last_byte >> (i+1)) - & 0x1; - if (i !=3D 6) - *addr_length_in_bits =3D - counter_num_bytes * 8 - + (8 - (i + 2)); - else - *addr_length_in_bits =3D - counter_num_bytes * 8; - found =3D 1; - } - } + pos =3D rte_bsf32(src[counter_num_bytes]); + if (pos =3D=3D 7) { + if (likely(counter_num_bytes > 0)) { + last_byte =3D src[counter_num_bytes - 1]; + *addr_direction =3D last_byte & 0x1; + *addr_length_in_bits =3D counter_num_bytes * 8 + - 1; } + } else { + last_byte =3D src[counter_num_bytes]; + *addr_direction =3D (last_byte >> (pos + 1)) & 0x1; + *addr_length_in_bits =3D counter_num_bytes * 8 + + (8 - (pos + 2)); + } + found =3D 1; } } =20 --=20 2.7.4