From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 95E1E42E3D; Tue, 11 Jul 2023 03:18:16 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7209640A7D; Tue, 11 Jul 2023 03:18:16 +0200 (CEST) Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by mails.dpdk.org (Postfix) with ESMTP id 637EA4003C for ; Tue, 11 Jul 2023 03:18:15 +0200 (CEST) Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-55adfa72d3fso2632644a12.3 for ; Mon, 10 Jul 2023 18:18:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689038294; x=1691630294; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tM02329k2WewqSub4oLwPyg55k5ntaMpJjr6BB/1qvU=; b=HrJ7JhS4Lv9Q4QQqA3iWTj8mlvHvdPoaylUuN3elvoYOr0KxEhVi+mQtcDQNL4c3ly BW7cGW0hhTE7hXTcqzOKbZTkWFrRmXwZlb6uhNNx1JP8j+8ui2CZ6KEU+/QcXPvdREI3 SeHLrmujp6sLGosR7teVaiKKgS3wp/KwZh4hGvojfq1scDk7qX62D1UsjvKQZB1ND1G2 +Lgc+BrbaV3SZXKmMlzFuy5QpIEE6EoF5kGn03xIBm74m/jESxrhm6tdSRzzehN6Dm/B meKdIS9zAMpE3dFhn6Fif0RPIxBnPBzawT2ltf6XFT19fVpfEk6ETuIw6Pn/c6d0xwYr +kew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689038294; x=1691630294; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tM02329k2WewqSub4oLwPyg55k5ntaMpJjr6BB/1qvU=; b=HwvhJ9eMl4I2kT7ta/xviFyoaXVzgr+ajmQ6Ey5W362Zi/Gq5TW151l2oD3H2SUYcU pfkurowI6yiXiyI6zb1xqmbYpdqunM16cVDa/3oMFaDFRvXzgBqsvR4qknysanY4yj3O 3/ZTBflleuLnLPmNXidhsrK9pqyXu/AqDJwEFMY/nmRhNpnLdu9bQh5ISy3yA6UJ+rti q1m07MS9oN/0Ino8FuG3RqtRWbicuEqB3QOaO9UB57EFyWDtty7NuGtZ+5NOrVYUUeLX QXb/Z8n2STUrBmJWeLO1FPk6ty9pUFzu991AmTY/R7FiBEHkJ4JqIhaF1hw4cfDrYXDG Q6Dg== X-Gm-Message-State: ABy/qLbLIOS1ffSO5gqb13BNGX9M6WLCSusLIlGq1iHb7hSBL5+Mj4wf ynasCPcs3TGexQ1OqN+4HhWMEi8rRmQL X-Google-Smtp-Source: APBJJlHYVMY47e+/tDce38Kp+zMmOcNezQcsCTtevCok4sREbj+yJrJgnZJMlXUgcFsIsuLDjdjAWg== X-Received: by 2002:a05:6a20:8e18:b0:129:b68b:92db with SMTP id y24-20020a056a208e1800b00129b68b92dbmr14768758pzj.42.1689038294420; Mon, 10 Jul 2023 18:18:14 -0700 (PDT) Received: from linux.. ([164.92.112.87]) by smtp.gmail.com with ESMTPSA id jh2-20020a170903328200b001b7feed285csm521335plb.36.2023.07.10.18.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 18:18:14 -0700 (PDT) From: Kaiyu Zhang To: thomas@monjalon.net, ferruh.yigit@amd.com, andrew.rybchenko@oktetlabs.ru Cc: dev@dpdk.org, Kaiyu Zhang Subject: [PATCH] lib/ethdev: sanity check on callback before resource allocation Date: Tue, 11 Jul 2023 01:18:09 +0000 Message-Id: <20230711011809.96677-1-squirrel.prog@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org sanity check is performed after a rte_eth_dev object is allocated. The object is not freed if the check fails, though in the current reality this never happens, but it's better programming paradigm to move the quick check up front to the start of rte_eth_dev_pci_generic_probe. Signed-off-by: Kaiyu Zhang --- lib/ethdev/ethdev_pci.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ethdev/ethdev_pci.h b/lib/ethdev/ethdev_pci.h index 94b8fba5d7..320e3e0093 100644 --- a/lib/ethdev/ethdev_pci.h +++ b/lib/ethdev/ethdev_pci.h @@ -126,12 +126,13 @@ rte_eth_dev_pci_generic_probe(struct rte_pci_device *pci_dev, struct rte_eth_dev *eth_dev; int ret; + if (*dev_init == NULL) + return -EINVAL; + eth_dev = rte_eth_dev_pci_allocate(pci_dev, private_data_size); if (!eth_dev) return -ENOMEM; - if (*dev_init == NULL) - return -EINVAL; ret = dev_init(eth_dev); if (ret) rte_eth_dev_release_port(eth_dev); -- 2.34.1