From patchwork Tue Feb 21 05:00:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 9583863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E5C7560578 for ; Tue, 21 Feb 2017 05:03:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF2DB288DD for ; Tue, 21 Feb 2017 05:03:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D38B9288DC; Tue, 21 Feb 2017 05:03:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 70B37288DD for ; Tue, 21 Feb 2017 05:03:08 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5468482212; Mon, 20 Feb 2017 21:03:08 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from ale.deltatee.com (ale.deltatee.com [207.54.116.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 134428220C for ; Mon, 20 Feb 2017 21:03:07 -0800 (PST) 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-0005v4-98; Mon, 20 Feb 2017 22:01:20 -0700 Received: from gunthorp by cgy1-donard.pmc-sierra.internal with local (Exim 4.84_2) (envelope-from ) id 1cg2ZW-000315-B7; Mon, 20 Feb 2017 22:01:06 -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:49 -0700 Message-Id: <1487653253-11497-11-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 Subject: [PATCH 10/14] mtd: utilize new device_add_cdev helper function 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-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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, linux-media@vger.kernel.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Note: neither of the cdev instances in the mtd tree originally set the kobject parent. Thus, I'm reasonably confident that both these instances would have suffered from a minor use after free bug if the cdevs were open when the backing device was released. Signed-off-by: Logan Gunthorpe --- drivers/mtd/ubi/build.c | 8 +++++--- drivers/mtd/ubi/vmt.c | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 85d54f3..a509f15 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -434,11 +434,10 @@ static int ubi_sysfs_init(struct ubi_device *ubi, int *ref) int err; ubi->dev.release = dev_release; - ubi->dev.devt = ubi->cdev.dev; ubi->dev.class = &ubi_class; ubi->dev.groups = ubi_dev_groups; dev_set_name(&ubi->dev, UBI_NAME_STR"%d", ubi->ubi_num); - err = device_register(&ubi->dev); + err = device_add(&ubi->dev); if (err) return err; @@ -508,12 +507,15 @@ static int uif_init(struct ubi_device *ubi, int *ref) return err; } + device_initialize(&ubi->dev); + ubi->dev.devt = dev; + ubi_assert(MINOR(dev) == 0); cdev_init(&ubi->cdev, &ubi_cdev_operations); dbg_gen("%s major is %u", ubi->ubi_name, MAJOR(dev)); ubi->cdev.owner = THIS_MODULE; - err = cdev_add(&ubi->cdev, dev, 1); + err = device_add_cdev(&ubi->dev, &ubi->cdev); if (err) { ubi_err(ubi, "cannot add character device"); goto out_unreg; diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c index 7ac78c1..df84ba7 100644 --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c @@ -159,7 +159,6 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) struct ubi_volume *vol; struct ubi_vtbl_record vtbl_rec; struct ubi_eba_table *eba_tbl = NULL; - dev_t dev; if (ubi->ro_mode) return -EROFS; @@ -265,11 +264,13 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) vol->last_eb_bytes = vol->usable_leb_size; } + device_initialize(&vol->dev); + vol->dev.devt = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1); + /* Register character device for the volume */ cdev_init(&vol->cdev, &ubi_vol_cdev_operations); vol->cdev.owner = THIS_MODULE; - dev = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1); - err = cdev_add(&vol->cdev, dev, 1); + err = device_add_cdev(&vol->dev, &vol->cdev); if (err) { ubi_err(ubi, "cannot add character device"); goto out_mapping; @@ -277,12 +278,11 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) vol->dev.release = vol_release; vol->dev.parent = &ubi->dev; - vol->dev.devt = dev; vol->dev.class = &ubi_class; vol->dev.groups = volume_dev_groups; dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); - err = device_register(&vol->dev); + err = device_add(&vol->dev); if (err) { ubi_err(ubi, "cannot register device"); goto out_cdev;