From patchwork Wed Oct 19 14:08:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 616441 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp319313pvb; Wed, 19 Oct 2022 07:14:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Dt5nbWBl2YXYoLUUu0OVz1r3eo2bVueGRStwYsMvPv4A0HeDEx4jaTdfNhU9WUaPrusCR X-Received: by 2002:a17:907:2e0d:b0:78e:1d21:8001 with SMTP id ig13-20020a1709072e0d00b0078e1d218001mr6867555ejc.246.1666188861129; Wed, 19 Oct 2022 07:14:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666188861; cv=none; d=google.com; s=arc-20160816; b=dAYA/PDFjKSrqy9iTKbfKJoukgXmlUpFLdqSDoTpF35Uf92wH8vEt5lqunN2JJILU8 EneK8+Z+zEaDpuljMWGZSDsLLxFJAjlIRanqU7gNId26qQPGECMCI/1lootM8N9MRffB UWOdPKzbyX0uLohPwTH93qN69joeeAsUat2PmUUISrnyz8cn1fgCbHhjJLj5DX+scZt+ Vdfzor+Edl7pYgMqJg4Dqe8XkmJaxsKG7+zdVeKatNWke67QtU/cfUDvbfsBAeGX3v2B 2KVWALq5Gb2UZyw+gK2daBSLOkkOO1pH8b57y9JmQFpP/n72qFthBvEPKtJs3cSIManW ZqlA== 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=hj1EPG3PSvqIX1XQQXAVASUgIXm8CXIe84sXSjf/uiI=; b=TuWQlk/0UENESyRi7+SDPZFKOZJZTc6aBl/9V/fiszhbKVS8CR3SO8fBNY1GNPisqt ILxBAweTAC8TsglQBDIafK6s9/IcXgo0kpMoUshYHCW3H19Z+/bSwkY6hsBKTw3HN9Qn uNSkgsBgw/c7tjb2sSC5kPr8iERuMy4+UNQwh7wT5inM6nqHq7hnhEj7Rwqwv0RZ3/hZ wc17xpmsMp1Y6SYrRdNYROW+O+GAJKUq6VrJAn0QTneNJDGJnUflNXvvC8BSE5FAN9cp FK6uAZZedIqKO96ML6H540qJTVaO50DdhHkVh5WBM4GwPwvCD2O6HLb8+vT3jkmyei0x EmJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VQmmuCyo; 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 n25-20020a170906379900b00782b2a97825si12175115ejc.337.2022.10.19.07.14.20; Wed, 19 Oct 2022 07:14:21 -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=VQmmuCyo; 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 AF3AC42B6C; Wed, 19 Oct 2022 16:14:20 +0200 (CEST) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by mails.dpdk.org (Postfix) with ESMTP id B2FF3410D1 for ; Wed, 19 Oct 2022 16:14:18 +0200 (CEST) Received: by mail-wm1-f52.google.com with SMTP id iv17so13025091wmb.4 for ; Wed, 19 Oct 2022 07:14:18 -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=hj1EPG3PSvqIX1XQQXAVASUgIXm8CXIe84sXSjf/uiI=; b=VQmmuCyoJ8T7XIF1Fu2EkH4nap0wx4mF1LEbGO1cXf1rEE90d9ZAIBb8bU51H06/SF xGLm8A0364pBsr09I0BhamCuYwjVrVgyoglJhipEqaxGhuqxOqfqLMT84Z+sBXqKe8QG fbzCBac5G2hL8DfimVQEOFBJr34aWIndwCrwzOyd4YbAvWj8xtq5aieWZUSaVy3TZFLK gMn0n3MESy7H/UAdLwzABE8to+1ohkQNOxw/0oz48FmSByL9LNn7mvMAJd7HBAgMWR2Z D7VITGGv4DGHO1rCsj5MBDf1OoyAL9JiyiCx0nBH9QqIECfJh2Y19WdLstwQXkhvDO6F +sig== 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=hj1EPG3PSvqIX1XQQXAVASUgIXm8CXIe84sXSjf/uiI=; b=YmGRG3uzKEDYx7rmj0nOrqHbLQU3rlCmrBTxlD6LZWEoBlNdCJPpIVwaiNyBjWN1hZ vWJ0biEFdTNmcNuKeB5j2tk7pxFCrePnLh5iNmkakApco4ocRiw/aZWsI90oE0sZzePk dgCWa36DelrWspOYzKLsesQwvBjg8zKwhpPcWcwkaBjTLX9YfRH+EW08LMpA19VGcPLd 0uDK+i3xWl7mTj32XgvuDTxN5BZsJE7quJd2ue0E15RwNt3BCzkR8p2aHgblhg/qpSyB G5kO9E+aQScXJDljAHiuf0JWppWt7PMxN8XWnIBtl/6nJd3hK565k5jW9Rb0ZVnAfKaW 0EdA== X-Gm-Message-State: ACrzQf1kekA1xupiLtATAfLPEEuem/cXWrL8q8MlcNUCTcUKwMWcVyoI jI6mjs3M8XCVRs//BDdmNwTgLw== X-Received: by 2002:a05:600c:3844:b0:3b4:becc:e43 with SMTP id s4-20020a05600c384400b003b4becc0e43mr26905211wmr.33.1666188858488; Wed, 19 Oct 2022 07:14:18 -0700 (PDT) Received: from localhost.localdomain ([213.146.143.36]) by smtp.gmail.com with ESMTPSA id r12-20020adff10c000000b00225239d9265sm14046267wro.74.2022.10.19.07.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 07:14:17 -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 resend] bus/vdev: vdev_cleanup checks dev->device.driver Date: Wed, 19 Oct 2022 22:08:01 +0800 Message-Id: <20221019140801.1700392-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 the probe fails. In vdev_cleanup, drv = container_of(dev->device.driver) drv will be !NULL in this case, causing 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 Reviewed-by: David Marchand --- 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);