From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id B8018A05E9 for ; Sun, 17 Mar 2019 07:16:42 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E3F1B2C54; Sun, 17 Mar 2019 07:16:41 +0100 (CET) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150081.outbound.protection.outlook.com [40.107.15.81]) by dpdk.org (Postfix) with ESMTP id 8488C2BF4 for ; Sun, 17 Mar 2019 07:16:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nPCNrJ6+ZqK9qnMyWS8iSSZHlSbWz5CB9tbOBnvPDlk=; b=JcnnJEDAqQ0mzAF3PDQB7Gk9NDPK1CEKLXTMxJASt/Q9fGgpD4r9uoNhPDkF0A5mLBKjZmdcOT6S72ESEGTq9ddaXxcYnoRyd02xzE0oP3OkkaetorWra33v0I4RP2Y7dVGmkFKgJcd+01afXyaS05jmwP9qHuNmArBLqjiSBB4= Received: from AM0PR0502MB4019.eurprd05.prod.outlook.com (52.133.39.139) by AM0PR0502MB3780.eurprd05.prod.outlook.com (52.133.45.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.14; Sun, 17 Mar 2019 06:16:39 +0000 Received: from AM0PR0502MB4019.eurprd05.prod.outlook.com ([fe80::3cdc:e13a:204e:67a6]) by AM0PR0502MB4019.eurprd05.prod.outlook.com ([fe80::3cdc:e13a:204e:67a6%2]) with mapi id 15.20.1709.011; Sun, 17 Mar 2019 06:16:39 +0000 From: Matan Azrad To: Stephen Hemminger CC: "dev@dpdk.org" Thread-Topic: [PATCH] net/vdev_netvsc: fix erronous cast Thread-Index: AQHU2UJIwXDADuylJE+441t89eFYIaYK+npggABMp4CABBf9wA== Date: Sun, 17 Mar 2019 06:16:39 +0000 Message-ID: References: <20190313021253.525-1-stephen@networkplumber.org> <20190314084435.2cca9735@shemminger-XPS-13-9360> In-Reply-To: <20190314084435.2cca9735@shemminger-XPS-13-9360> Accept-Language: en-US, he-IL Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; x-originating-ip: [193.47.165.251] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8f3d33a5-5fb4-4c24-ecc4-08d6aaa01ddf x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM0PR0502MB3780; x-ms-traffictypediagnostic: AM0PR0502MB3780: x-microsoft-antispam-prvs: x-forefront-prvs: 09796A1B83 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(366004)(346002)(39850400004)(396003)(136003)(199004)(189003)(25786009)(6506007)(8936002)(4326008)(26005)(102836004)(68736007)(76176011)(256004)(5024004)(99286004)(186003)(6916009)(14454004)(81156014)(33656002)(81166006)(8676002)(74316002)(7736002)(316002)(305945005)(52536014)(106356001)(105586002)(11346002)(446003)(229853002)(6436002)(97736004)(6116002)(2906002)(3846002)(476003)(486006)(6246003)(55016002)(66066001)(7696005)(5660300002)(71200400001)(478600001)(71190400001)(9686003)(86362001)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0502MB3780; H:AM0PR0502MB4019.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: A2e9eeFkM+34HjPkbWyg3VneecgTPGApnOKNBkxzkDYKF1CRZ7N/LUzlWnhuF0mBajuH9+eTG5ITvynQ0ZyqeRwrUvzTnrRar7sJMt+KhEfiqRc7yaeERUAr5qoJZRQZnDnCjqvXVmfk7J5R1Je+LVH5kNjE2qcFBWHqtVMQwP8fQ7U+LZv5sFkjnU8sGn/WvK8qNUmMLMkYCbhfG8Nn3OwKA2DrTS6kB7kDJ+hANZRZHvErk1jKT6UkLgQsIbJPBCJWswakxw3Lyxkhblmr+QMVTQ/WRq4kyA8iAn2HD2q2y9auDzpWtjrHgnQ/F56Ws9zdW4GPbGSCRDety3B6KhpqZiskszYhIYGJr3rhyb9ooGQtu1ID506guiSAVfuLQKaViZP7kobn/Gdw2oc8k2wBdPSNioktX5eqPn0rOjo= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f3d33a5-5fb4-4c24-ecc4-08d6aaa01ddf X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Mar 2019 06:16:39.1587 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0502MB3780 Subject: Re: [dpdk-dev] [PATCH] net/vdev_netvsc: fix erronous cast 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Message-ID: <20190317061639.gGRQcTsgyO5hTecCBzpUG9H05P1POr8tfkVlbMTpO6M@z> Hi From: Stephen Hemminger > > Hi > > > > From: Stephen Hemminger > > > The return value from bus->find_device is a rte_device which is not > > > safe to cast to a rte_vdev_device structure. > > > It doesn't really matter since only being checked for NULL but > > > static checkers might find a bug here. > > > > > > > Fix line is missing. > > > > > Signed-off-by: Stephen Hemminger > > > --- > > > drivers/net/vdev_netvsc/vdev_netvsc.c | 7 ++++--- > > > 1 file changed, 4 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/net/vdev_netvsc/vdev_netvsc.c > > > b/drivers/net/vdev_netvsc/vdev_netvsc.c > > > index ba63fac2a598..801f54c96e01 100644 > > > --- a/drivers/net/vdev_netvsc/vdev_netvsc.c > > > +++ b/drivers/net/vdev_netvsc/vdev_netvsc.c > > > @@ -808,7 +808,7 @@ vdev_netvsc_cmp_rte_device(const struct > > > rte_device *dev1, static void > > > vdev_netvsc_scan_callback(__rte_unused > > > void *arg) { > > > - struct rte_vdev_device *dev; > > > + struct rte_device *dev; > > > struct rte_devargs *devargs; > > > struct rte_bus *vbus =3D rte_bus_find_by_name("vdev"); > > > > > > @@ -816,8 +816,9 @@ vdev_netvsc_scan_callback(__rte_unused void > *arg) > > > if (!strncmp(devargs->name, VDEV_NETVSC_DRIVER_NAME, > > > VDEV_NETVSC_DRIVER_NAME_LEN)) > > > return; > > > - dev =3D (struct rte_vdev_device *)vbus->find_device(NULL, > > > - vdev_netvsc_cmp_rte_device, > > > VDEV_NETVSC_DRIVER_NAME); > > > + > > > + dev =3D vbus->find_device(NULL, vdev_netvsc_cmp_rte_device, > > > + VDEV_NETVSC_DRIVER_NAME); > > > > Since the device must be vdev here, > > It is better to use explicit cast to make the checker happy. >=20 > The cast is converting from rte_device to rte_vdev_device which incorrect= . >=20 > The device returned by vbus->find_device is a rte_device not a > rte_vdev_device: >=20 > vbus->find_device points to rte_vdev_find_device >=20 > struct rte_device * > rte_vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, > const void *data) >=20 > but definition of rte_vdev_device is: >=20 > struct rte_vdev_device { > TAILQ_ENTRY(rte_vdev_device) next; /**< Next attached vdev */ > struct rte_device device; /**< Inherit core device */ > }; >=20 > The only safe way to get rte_vdev_device would be to use container_of(). >=20 > dev =3D vbus->find_device(NULL, vdev_netvsc_cmp_rte_device, > VDEV_NETVSC_DRIVER_NAME); > vdev =3D dev ? container_of(dev, struct rte_vdev_device, device) : > NULL; >=20 > But as the PATCH demonstrated, this is not necessary. Yes, you right. Please add fix line to the patch + stable line. Matan =20