From patchwork Tue Feb 21 05:00:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 733078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vXC672j8Zz9sNY for ; Tue, 28 Feb 2017 06:52:15 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ciRL7-00037y-7G; Mon, 27 Feb 2017 19:52:09 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cg3CX-0004Gm-Ak for tpmdd-devel@lists.sourceforge.net; Tue, 21 Feb 2017 05:41:25 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of deltatee.com designates 207.54.116.67 as permitted sender) client-ip=207.54.116.67; envelope-from=gunthorp@deltatee.com; helo=ale.deltatee.com; Received: from ale.deltatee.com ([207.54.116.67]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1cg3CW-0004Rl-1X for tpmdd-devel@lists.sourceforge.net; Tue, 21 Feb 2017 05:41:25 +0000 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31] helo=cgy1-donard.pmc-sierra.internal) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1cg2Zi-0005v1-99; Mon, 20 Feb 2017 22:01:23 -0700 Received: from gunthorp by cgy1-donard.pmc-sierra.internal with local (Exim 4.84_2) (envelope-from ) id 1cg2ZV-00030q-UO; Mon, 20 Feb 2017 22:01:05 -0700 From: Logan Gunthorpe To: Greg Kroah-Hartman , Dan Williams , Alexander Viro , Johannes Thumshirn , Jan Kara , Arnd Bergmann , Sajjan Vikas C , Dmitry Torokhov , Linus Walleij , Alexandre Courbot , Peter Huewe , Marcel Selhorst , Jarkko Sakkinen , Jason Gunthorpe , Olof Johansson , Doug Ledford , Sean Hefty , Hal Rosenstock , Dmitry Vyukov , Haggai Eran , Parav Pandit , Leon Romanovsky , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Hans Verkuil , Mauro Carvalho Chehab , Artem Bityutskiy , Richard Weinberger , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Cyrille Pitchen , Matt Porter , Alexandre Bounine , Andrew Morton , Joe Perches , Lorenzo Stoakes , Vladimir Zapolskiy , Alessandro Zummo , Alexandre Belloni , Boaz Harrosh , Benny Halevy , "James E.J. Bottomley" , "Martin K. Petersen" , Stephen Bates , Bjorn Helgaas Date: Mon, 20 Feb 2017 22:00:46 -0700 Message-Id: <1487653253-11497-8-git-send-email-logang@deltatee.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1487653253-11497-1-git-send-email-logang@deltatee.com> References: <1487653253-11497-1-git-send-email-logang@deltatee.com> X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk, jthumshirn@suse.de, jack@suse.cz, arnd@arndb.de, vikas.cha.sajjan@hpe.com, linus.walleij@linaro.org, tpmdd@selhorst.net, jarkko.sakkinen@linux.intel.com, jgunthorpe@obsidianresearch.com, olof@lixom.net, dledford@redhat.com, dan.j.williams@intel.com, sean.hefty@intel.com, haggaie@mellanox.com, peterhuewe@gmx.de, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, hans.verkuil@cisco.com, leon@kernel.org, jic23@kernel.org, mchehab@kernel.org, richard@nod.at, dwmw2@infradead.org, cyrille.pitchen@atmel.com, mporter@kernel.crashing.org, alexandre.bounine@idt.com, akpm@linux-foundation.org, joe@perches.com, dmitry.torokhov@gmail.com, gnurou@gmail.com, hal.rosenstock@gmail.com, pandit.parav@gmail.com, dedekind1@gmail.com, computersforpeace@gmail.com, marek.vasut@gmail.com, lstoakes@gmail.com, vz@mleia.com, a.zummo@towertech.it, boris.brezillon@free-electrons.com, alexandre.belloni@free-electrons.com, ooo@electrozaur.com, bhalevy@primarydata.com, jejb@linux.vnet.ibm.com, martin.petersen@oracle.com, stephen.bates@microsemi.com, dvyukov@google.com, bhelgaas@google.com, osd-dev@open-osd.org, rtc-linux@googlegroups.com, linux-mtd@lists.infradead.org, tpmdd-devel@lists.sourceforge.net, linux-nvdimm@lists.01.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, linux-media@vger.kernel.org, linux-iio@vger.kernel.org, linux-rdma@vger.kernel.org, linux-gpio@vger.kernel.org, linux-input@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.5 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE, MYRULES_FREE, MYRULES_NO_TEXT, RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.0 X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1cg3CW-0004Rl-1X X-Mailman-Approved-At: Mon, 27 Feb 2017 19:52:05 +0000 Cc: linux-scsi@vger.kernel.org, rtc-linux@googlegroups.com, linux-gpio@vger.kernel.org, linux-iio@vger.kernel.org, linux-pci@vger.kernel.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, tpmdd-devel@lists.sourceforge.net, linux-mtd@lists.infradead.org, osd-dev@open-osd.org, linux-input@vger.kernel.org, linux-fsdevel@vger.kernel.org, Logan Gunthorpe , linux-media@vger.kernel.org Subject: [tpmdd-devel] [PATCH 07/14] infiniband: utilize new device_add_cdev helper function X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net This patch updates core/ucm.c which didn't originally use the cdev.kobj.parent with it's parent device. I did not look heavily into whether this was a bug or not, but it seems likely to me there would be a use before free. I also took a look at core/uverbs_main.c, core/user_mad.c and hw/hfi1/device.c which utilize cdev.kobj.parent but because the infiniband core seems to use kobjs internally instead of struct devices they could not be converted to use the new helper API and still directly manipulate the internals of the kobj. Signed-off-by: Logan Gunthorpe --- drivers/infiniband/core/ucm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/core/ucm.c b/drivers/infiniband/core/ucm.c index e0a995b..38ea316 100644 --- a/drivers/infiniband/core/ucm.c +++ b/drivers/infiniband/core/ucm.c @@ -1283,18 +1283,20 @@ static void ib_ucm_add_one(struct ib_device *device) set_bit(devnum, dev_map); } + device_initialize(&ucm_dev->dev); + ucm_dev->dev.devt = base; + cdev_init(&ucm_dev->cdev, &ucm_fops); ucm_dev->cdev.owner = THIS_MODULE; kobject_set_name(&ucm_dev->cdev.kobj, "ucm%d", ucm_dev->devnum); - if (cdev_add(&ucm_dev->cdev, base, 1)) + if (device_add_cdev(&ucm_dev->dev, &ucm_dev->cdev)) goto err; ucm_dev->dev.class = &cm_class; ucm_dev->dev.parent = device->dma_device; - ucm_dev->dev.devt = ucm_dev->cdev.dev; ucm_dev->dev.release = ib_ucm_release_dev; dev_set_name(&ucm_dev->dev, "ucm%d", ucm_dev->devnum); - if (device_register(&ucm_dev->dev)) + if (device_add(&ucm_dev->dev)) goto err_cdev; if (device_create_file(&ucm_dev->dev, &dev_attr_ibdev))