From patchwork Thu Oct 12 03:57:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Dubey X-Patchwork-Id: 824677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yCHBq2xQ3z9t2Z for ; Thu, 12 Oct 2017 14:58:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752291AbdJLD6M (ORCPT ); Wed, 11 Oct 2017 23:58:12 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:43846 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753296AbdJLD6J (ORCPT ); Wed, 11 Oct 2017 23:58:09 -0400 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20171012035807epoutp01b5229fb1e7702f498df7c37cd55ea5b3~stowQDHIq2632726327epoutp01F; Thu, 12 Oct 2017 03:58:07 +0000 (GMT) Received: from epsmges1p2.samsung.com (unknown [182.195.42.54]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20171012035807epcas1p40883fb7d19617398836978f23b005c42~stovlS24T2596225962epcas1p41; Thu, 12 Oct 2017 03:58:07 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 4A.98.33112.F48EED95; Thu, 12 Oct 2017 12:58:07 +0900 (KST) Received: from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20171012035806epcas1p16df484a0565cfe780416253710464a8f~stouw9zRI2918529185epcas1p1L; Thu, 12 Oct 2017 03:58:06 +0000 (GMT) X-AuditID: b6c32a36-c21ff70000018158-5c-59dee84f42f2 Received: from epmmp1.local.host ( [203.254.227.16]) by epsmgms2p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 93.D5.06995.E48EED95; Thu, 12 Oct 2017 12:58:06 +0900 (KST) Received: from ubuntu.sisodomain.com ([107.108.83.125]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OXO001P9Z038760@mmp1.samsung.com>; Thu, 12 Oct 2017 12:58:06 +0900 (KST) From: Pankaj Dubey To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kishon Vijay Abraham I , Bjorn Helgaas , Pankaj Dubey Subject: [PATCH] PCI: endpoint: handle probable NULL pointer access Date: Thu, 12 Oct 2017 09:27:57 +0530 Message-id: <1507780677-7983-1-git-send-email-pankaj.dubey@samsung.com> X-Mailer: git-send-email 2.7.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprKIsWRmVeSWpSXmKPExsWy7bCmga7/i3uRBpsOcVksacqwuPC0h83i 8q45bBZn5x1ns1i09Qu7A6vHgk2lHn1bVjF6HL+xncnj8ya5AJYoLpuU1JzMstQifbsEroyb rV9ZCxr5Kn6vncrSwPiGu4uRk0NCwERi1cRmFhBbSGAHo8Sdg8xdjFxA9ndGib03JzHCFO25 +Y4FIrGbUeLZtInsEM5PRonDW06DVbEJ6Eo8eT+XGcQWEbCWaHi1ihXEZhaokpjT1g5mCws4 Szx7sZMNxGYRUJW4sKcFLM4r4C5x+ssVFohtchI3z3WCnSEhcJNV4kn3WlaIhItE3+x1bBC2 sMSr41uAruAAsqUlLh21hQhXSzw5+ZoFoncCo8TGg8eZIRL2EgeuzGGBOIhP4t3XHlaIXl6J jjYhiBIPiTln70OtcpS4s6aXDRIssRKb9hxjncAouYCRYRWjWGpBcW56arFhgZFecWJucWle ul5yfu4mRnBkaZntYFx0zucQowAHoxIP7wute5FCrIllxZW5hxglOJiVRHj9dwGFeFMSK6tS i/Lji0pzUosPMUpzsCiJ84quvxYhJJCeWJKanZpakFoEk2Xi4JRqYFy/4XuJdlKplJbefDNn j0qnGRstGtauENHKr6qWeTXNoiOgNETq5bFLFxhidi6Yo7E4cTEXk7DAlp6vbFWfv/nkf/Z7 I/Dtpsf+ti+HHY+e+s4csK5swu2HMd/km+3mTgwMLz37l22j4aES44NFDFtDN9W2aO5+sbMz U7FEs7bt/J2sja/2JSqxFGckGmoxFxUnAgBQe0Q1qAIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrEJMWRmVeSWpSXmKPExsVy+t9jAV2/F/ciDc518VksacqwuPC0h83i 8q45bBZn5x1ns1i09Qu7A6vHgk2lHn1bVjF6HL+xncnj8ya5AJYoLpuU1JzMstQifbsEroyb rV9ZCxr5Kn6vncrSwPiGu4uRk0NCwERiz813LF2MXBxCAjsZJc5duswK4fxklNi8s4MJpIpN QFfiyfu5zCC2iIC1RMOrVUBFHBzMAlUS225ngoSFBZwlnr3YyQZiswioSlzY08IKYvMKuEuc /nKFBWKZnMTNc53MExi5FjAyrGKUTC0ozk3PLTYqMMxLLdcrTswtLs1L10vOz93ECPT5tsNa fTsY7y+JP8QowMGoxMP7QutepBBrYllxZe4hRgkOZiURXv9dQCHelMTKqtSi/Pii0pzU4kOM 0hwsSuK8t/OORQoJpCeWpGanphakFsFkmTg4pRoYDd44TPy985RIFE+WZOEtwfm5rYbLHh7a py7yszFmzced2x1eRXPujTgSJR5w507GzqDzKlMeLm3OW5nFvGqG2lIRTjeDK30mSzbty4hQ D3Hk2ReWJzdr6yw5h6uHeTxufXJwuaLU8nDfKkEj3sg7bW2r1SIeiLK7+p27YvuCd6O1+bu4 KR/+KrEUZyQaajEXFScCANO427L1AQAA X-CMS-MailID: 20171012035806epcas1p16df484a0565cfe780416253710464a8f X-Msg-Generator: CA X-Sender-IP: 182.195.42.142 X-Local-Sender: =?utf-8?b?7YyQ7Lm07KaIG1NTSVItRkRTIFNXG+yCvOyEseyghA==?= =?utf-8?b?7J6QGy4vU2VuaW9yIENoaWVmIEVuZ2luZWVy?= X-Global-Sender: =?utf-8?q?PANKAJ_KUMAR_DUBEY=1BSSIR-FDS_SW=1BSamsung_Ele?= =?utf-8?q?ctronics=1B=2E/Senior_Chief_Engineer?= X-Sender-Code: =?utf-8?q?C10=1BSWAHQ=1BC10ID07ID010997?= CMS-TYPE: 101P X-CMS-RootMailID: 20171012035806epcas1p16df484a0565cfe780416253710464a8f X-RootMTR: 20171012035806epcas1p16df484a0565cfe780416253710464a8f References: Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org controller_group allocation in pci_ep_cfs_init function can fail so we should have a check while using it in pci_ep_cfs_add_epc_group for registering group, else we will hit NULL pointer access. This patch adds required check for the same and returns -EPROBE_DEFER, so that endpoint controller driver probe can be reattempted later in case controller_group is not allocated because pci_ep_cfs_init is not yet called. Signed-off-by: Pankaj Dubey --- drivers/pci/endpoint/pci-ep-cfs.c | 7 ++++++- drivers/pci/endpoint/pci-epc-core.c | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c index 424fdd6..3cac818 100644 --- a/drivers/pci/endpoint/pci-ep-cfs.c +++ b/drivers/pci/endpoint/pci-ep-cfs.c @@ -172,7 +172,12 @@ struct config_group *pci_ep_cfs_add_epc_group(const char *name) group = &epc_group->group; config_group_init_type_name(group, name, &pci_epc_type); - ret = configfs_register_group(controllers_group, group); + + if (controllers_group) + ret = configfs_register_group(controllers_group, group); + else + ret = -EPROBE_DEFER; + if (ret) { pr_err("failed to register configfs group for %s\n", name); goto err_register_group; diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 42c2a11..d327a2a 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -518,6 +518,10 @@ __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops, goto put_dev; epc->group = pci_ep_cfs_add_epc_group(dev_name(dev)); + if (IS_ERR(epc->group)) { + ret = -EPROBE_DEFER; + goto put_dev; + } return epc;