From patchwork Tue Jul 3 09:00:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kishon Vijay Abraham I X-Patchwork-Id: 140917 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp909178ljj; Tue, 3 Jul 2018 02:00:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKHeZ7uEnZJFWifej73E1en4NDZcyScFWfv18idqxQxW642EMiGmicBcM6wA6iWH/Xx2rVg X-Received: by 2002:a63:a119:: with SMTP id b25-v6mr24222222pgf.279.1530608428761; Tue, 03 Jul 2018 02:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530608428; cv=none; d=google.com; s=arc-20160816; b=RoXktc+EjQuyxramodjIFsQvthiI5TrGx35/edmntWTh8m8QpXX1EydXiNlosUx19g /b5Z90qDOLh+sGOmttDCtI3F9wuVtSDwfFcnHtbWgLZ2P54gPvfXjwI4JFFiv4e3GT3P uID1pv3Op6doa2BzfLJSCK0aEdjBpCGS28pGtvsEwYlKC3e+sivfU5WKNvG0qGn2w3tu 3j6EoPrqeoJYSCpvCdxjESc78o1Ocu5t6c3QWumb05zwYtuLqI96KXkZ4QNKo2Vcq19m mNBexP6jVtB67BYJEwRSvuKTe3ZWd4iwitqcHp0OGGFvxxz+EiV2excU6/Fn3wFTTqJJ o2Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:dkim-signature:arc-authentication-results; bh=6qQXzq5sVskOjFDXqNbUSzMHq1iuyxh6NRYBZDUzlwU=; b=KHo2sM7IoYhjQraR+xoBkxHOgC7wRbL/a2UdD366oBN9yqwDGXIVqEOzfnDKz2VQJN 60wK7OevgIPii6nSKeneApmR3jtO2eIEcR49O3eguviQvw2kIhC1Q5f6Mh8EzLXZS3Ik ru+qCD1b6lsj1gDywTkEIqshUAEpjxJD4BHUJripnMHpal2TofojEhuYM7NRURjyirrk PPeVh0Ofw57nrPLSzDBlrCO4hN9WOr3KZcipfhk0hY7eZjemtKb69qSrS7YXwkYRVYFC p/Cufx59sDQEkFq/Wtkh1C5Pbaft8cZXw0QTBYTytmOblTrr0KTOKP7wB1N4XvVYftnE yWrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=UoclP9sg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 85-v6si721832pfm.264.2018.07.03.02.00.28; Tue, 03 Jul 2018 02:00:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=UoclP9sg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754696AbeGCJA1 (ORCPT + 31 others); Tue, 3 Jul 2018 05:00:27 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:44650 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754382AbeGCJAZ (ORCPT ); Tue, 3 Jul 2018 05:00:25 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id w6390Kus069651; Tue, 3 Jul 2018 04:00:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1530608420; bh=6qQXzq5sVskOjFDXqNbUSzMHq1iuyxh6NRYBZDUzlwU=; h=From:To:CC:Subject:Date; b=UoclP9sgwIGQSVeZWg+x7bSO1PkO4XOSXY4P9vFS0ne965aZdNTtmItdRKcLZc2yI yqugvTkVh+kTl6bEUioGRqaonBjCJBbMYlsNrr79cUIKdjyfaqEk30KEFJsSSkdBV9 W81RSSUGqJVpqkbkH95EAXHYebQWRV8Fcd8mx3Dc= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w6390KaU032031; Tue, 3 Jul 2018 04:00:20 -0500 Received: from DFLE109.ent.ti.com (10.64.6.30) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Tue, 3 Jul 2018 04:00:20 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Tue, 3 Jul 2018 04:00:20 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w6390I41027625; Tue, 3 Jul 2018 04:00:19 -0500 From: Kishon Vijay Abraham I To: Kishon Vijay Abraham I , Lorenzo Pieralisi , Bjorn Helgaas CC: , Subject: [PATCH] PCI: endpoint: Fix NULL pointer dereference error when CONFIGFS is disabled Date: Tue, 3 Jul 2018 14:30:17 +0530 Message-ID: <20180703090017.22734-1-kishon@ti.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit ef1433f717a2c63747a519d86965d73 ("PCI: endpoint: Create configfs entry for each pci_epf_device_id table entry") while adding configfs entry for each pci_epf_device_id table entry introduced a NULL pointer dereference error when CONFIG_PCI_ENDPOINT_CONFIGFS is not enabled. Fix it here. Fixes: ef1433f717a2c63747a519d86965d73 ("PCI: endpoint: Create configfs entry for each pci_epf_device_id table entry") Signed-off-by: Kishon Vijay Abraham I --- drivers/pci/endpoint/pci-epf-core.c | 62 ++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 19 deletions(-) -- 2.17.1 diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 523a8cab3bfb..7fe1930d6589 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -137,25 +137,60 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar) } EXPORT_SYMBOL_GPL(pci_epf_alloc_space); -/** - * pci_epf_unregister_driver() - unregister the PCI EPF driver - * @driver: the PCI EPF driver that has to be unregistered - * - * Invoke to unregister the PCI EPF driver. - */ -void pci_epf_unregister_driver(struct pci_epf_driver *driver) +static void pci_epf_remove_cfs(struct pci_epf_driver *driver) { struct config_group *group; + if (!IS_ENABLED(CONFIG_PCI_ENDPOINT_CONFIGFS)) + return; + mutex_lock(&pci_epf_mutex); list_for_each_entry(group, &driver->epf_group, group_entry) pci_ep_cfs_remove_epf_group(group); list_del(&driver->epf_group); mutex_unlock(&pci_epf_mutex); +} + +/** + * pci_epf_unregister_driver() - unregister the PCI EPF driver + * @driver: the PCI EPF driver that has to be unregistered + * + * Invoke to unregister the PCI EPF driver. + */ +void pci_epf_unregister_driver(struct pci_epf_driver *driver) +{ + pci_epf_remove_cfs(driver); driver_unregister(&driver->driver); } EXPORT_SYMBOL_GPL(pci_epf_unregister_driver); +static int pci_epf_add_cfs(struct pci_epf_driver *driver) +{ + struct config_group *group; + const struct pci_epf_device_id *id; + + if (!IS_ENABLED(CONFIG_PCI_ENDPOINT_CONFIGFS)) + return 0; + + INIT_LIST_HEAD(&driver->epf_group); + + id = driver->id_table; + while (id->name[0]) { + group = pci_ep_cfs_add_epf_group(id->name); + if (IS_ERR(group)) { + pci_epf_remove_cfs(driver); + return PTR_ERR(group); + } + + mutex_lock(&pci_epf_mutex); + list_add_tail(&group->group_entry, &driver->epf_group); + mutex_unlock(&pci_epf_mutex); + id++; + } + + return 0; +} + /** * __pci_epf_register_driver() - register a new PCI EPF driver * @driver: structure representing PCI EPF driver @@ -167,8 +202,6 @@ int __pci_epf_register_driver(struct pci_epf_driver *driver, struct module *owner) { int ret; - struct config_group *group; - const struct pci_epf_device_id *id; if (!driver->ops) return -EINVAL; @@ -183,16 +216,7 @@ int __pci_epf_register_driver(struct pci_epf_driver *driver, if (ret) return ret; - INIT_LIST_HEAD(&driver->epf_group); - - id = driver->id_table; - while (id->name[0]) { - group = pci_ep_cfs_add_epf_group(id->name); - mutex_lock(&pci_epf_mutex); - list_add_tail(&group->group_entry, &driver->epf_group); - mutex_unlock(&pci_epf_mutex); - id++; - } + pci_epf_add_cfs(driver); return 0; }