From patchwork Wed Oct 19 13:56:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 616440 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp309904pvb; Wed, 19 Oct 2022 07:02:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ZXFJL4MZpO9Xg602DRZnDeMxliFKbp7djig9QZNngEgwGKsU2uY47YVAIKa1bbsn8epdO X-Received: by 2002:a1c:f60d:0:b0:3be:708b:c96c with SMTP id w13-20020a1cf60d000000b003be708bc96cmr27323844wmc.168.1666188147271; Wed, 19 Oct 2022 07:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666188147; cv=none; d=google.com; s=arc-20160816; b=O6oG2WeybHcICIjQvAVyBunm7pTgpNNHmS3xXw+60gytPgW+VLUn4c2TF40aCOw46g H5xnk0Fk/O3YauEUE3aKnpFmK06TL57gC8bT5mh/3PazF2O1ObuVKWtZOGTSUzrncxLA 71N9Kn0/h4R4cFw+bi1BCbHS2ouymU9FDpuiX5gvdSF5x634xZADr4DiFb8YLi3SigvE zdQgGKK/bCCyrAEB0yKVcxWPt3g2tL6HBJ33e+/SeIcUs1g9kT+hpQ20tYoEaIWelSSH JaeZzArhdomgIsmlYa6LzeyedsSyD8CDkMBHKFBm9EedDoRLpn8M9cwtaB3Q3uIWma8h BdqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CnNZzug3jZjk+H/4cA/xi2RKomHEIL308AcbNwjOMpg=; b=ukpQShjCqM/2c7UjtIhWxY0izFJkezQPL2JYNptLqbYhm8g+zO1NLkQaZdM0JL48Vl Pn8zBvsOXuSaCmkzLvYP+0njjlvFrW2YUOWXCKP5yEl08pTj3Q1IN1tQS2dzIAD4V2CV cFWU70Zr/tGqLihDsFNYuEXVfo8iPlYByp2pzveT08MeCxA4itO653ipLQucHPtmQR/p lWG9ocVdF80+IBMiBasQJUCMzrjzPI44Kpue5yVLpwbNKQutoBtUAbYehj8luma/Uwdf 1FOUSBkGkm54CggjfffIoRiQZuxOowXqTC8eoxo3om6hOikvo/5+/AUwEaiW2BcLCa57 AEqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tYqfMQdj; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mails.dpdk.org (mails.dpdk.org. [217.70.189.124]) by mx.google.com with ESMTP id r9-20020a5d6c69000000b0022e4244b036si10378463wrz.881.2022.10.19.07.02.27; Wed, 19 Oct 2022 07:02:27 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) client-ip=217.70.189.124; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tYqfMQdj; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B94A642B6C; Wed, 19 Oct 2022 16:02:26 +0200 (CEST) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by mails.dpdk.org (Postfix) with ESMTP id C36C8410D1 for ; Wed, 19 Oct 2022 16:02:25 +0200 (CEST) Received: by mail-wm1-f49.google.com with SMTP id bh7-20020a05600c3d0700b003c6fb3b2052so72893wmb.2 for ; Wed, 19 Oct 2022 07:02:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CnNZzug3jZjk+H/4cA/xi2RKomHEIL308AcbNwjOMpg=; b=tYqfMQdjxwtAw1G02D3lnJyMNVBSC7QCKDJYILYpEtnUcAaAsNqMdYn1cOYmf9kuKl /Ug9t723xfjTZJKRZMpIZaj5NS0KqSt/eVlW+iMCtWYMSBcw2+gCCbhmXfiYbma0GPgB D2QSObD8uyrIpCX22ymu7iENR7qt2SkNY/LZenclFMUKYO9oZQG/QsIyFmxdFcs4u8yo A7x1x0tmDTMNYCH2xVEKXOoD99g1zGvksOS1U9+K48haGY4dv7Aw53rYECi+qrCilZHe Rv7KKriS/Ve/iUO6mQjTO1NrNhhrwEdZlsfUDvjQnfXnbDI+AHyMjk/26o7NIjztiXpg OW1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CnNZzug3jZjk+H/4cA/xi2RKomHEIL308AcbNwjOMpg=; b=iYQYA1H0HVB7mK8CWNNAh6hwJclAPgyk4n4pXKlxW9DGlVW0kmiKkIHhw+yaNiED3T ZSLP34vDfuVnyvp1rGUfdi+M/QVrF1TKJ0GGR0YyyMm6hm6U1bWj6/tLYHE/EEFxfv49 hbV78+QQgdOa1SVysZk08JWSqAis8mSgXynCC1irdO2e0IXTugQ/UxpnAfXW1HId/Ite o6eTTYIZlH1muo12HhtSw3okznd96iVZHa0rgVsUTTvuseKItaNSK7vFTc6vSKA00G2X z7U0NBfZP1OYngULDEULCPk6kkqf2tDI2Vp6/vvUu6lPDMFbngLhSkcoAt3fvgVF3srx d0Tw== X-Gm-Message-State: ACrzQf0m5ke6GXaCQuknBF842yl3MGEvt8q09MTQOeHPUMFZDpXmN7e7 iCpA/IaqBfoga7zMhnrxR58o3g== X-Received: by 2002:a05:600c:6885:b0:3c4:de24:638 with SMTP id fn5-20020a05600c688500b003c4de240638mr26552775wmb.183.1666188145462; Wed, 19 Oct 2022 07:02:25 -0700 (PDT) Received: from localhost.localdomain ([213.146.143.36]) by smtp.gmail.com with ESMTPSA id p39-20020a05600c1da700b003c6d21a19a0sm16501854wms.29.2022.10.19.07.02.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 07:02:25 -0700 (PDT) From: Zhangfei Gao To: Anatoly Burakov , Akhil Goyal , Fan Zhang , David Marchand Cc: dev@dpdk.org, acc@openeuler.org, Zhangfei Gao Subject: [PATCH v2] bus/vdev: vdev_cleanup checks dev->device.driver Date: Wed, 19 Oct 2022 21:56:06 +0800 Message-Id: <20221019135606.1700219-1-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019104847.1699872-1-zhangfei.gao@linaro.org> References: <20221019104847.1699872-1-zhangfei.gao@linaro.org> MIME-Version: 1.0 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 vdev_probe calls driver->probe and set dev->device.driver, which will be NULL if probe fails. In vdev_cleanup, drv = container_of(dev->device.driver) drv will be !NULL in this case. anc cause drv->remove Segmentation fault. Fixed by checking dev->device.driver before. Log: $ sudo dpdk-test --vdev=crypto_uadk --log-level=6 vdev_probe(): failed to initialize crypto_uadk device EAL: Bus (vdev) probe failed. RTE>>quit Segmentation fault Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown") Signed-off-by: Zhangfei Gao --- v2: Suggested by David Marchand 1. Add Fixes 2. "If dev->device.driver != NULL, then drv won't be NULL", so remove it drivers/bus/vdev/vdev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index f5b43f1930..41bc07dde7 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -577,9 +577,12 @@ vdev_cleanup(void) const struct rte_vdev_driver *drv; int ret = 0; + if (dev->device.driver == NULL) + continue; + drv = container_of(dev->device.driver, const struct rte_vdev_driver, driver); - if (drv == NULL || drv->remove == NULL) + if (drv->remove == NULL) continue; ret = drv->remove(dev);