From patchwork Fri Mar 17 18:48:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 740446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vlDtr3Dmqz9ryj for ; Sat, 18 Mar 2017 05:50:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751406AbdCQSul (ORCPT ); Fri, 17 Mar 2017 14:50:41 -0400 Received: from ale.deltatee.com ([207.54.116.67]:56515 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751208AbdCQSuZ (ORCPT ); Fri, 17 Mar 2017 14:50:25 -0400 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1cowvs-0002ZL-Sf; Fri, 17 Mar 2017 12:49:03 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.84_2) (envelope-from ) id 1cowvq-0000qp-Fv; Fri, 17 Mar 2017 12:48:58 -0600 From: Logan Gunthorpe To: Greg Kroah-Hartman , Dan Williams , Hans Verkuil , Alexander Viro , Alexandre Belloni , Jason Gunthorpe , Johannes Thumshirn , Dmitry Torokhov , Linus Walleij , Jarkko Sakkinen , "James E.J. Bottomley" , "Martin K. Petersen" , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Cyrille Pitchen Cc: linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, rtc-linux@googlegroups.com, linux-mtd@lists.infradead.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-nvdimm@lists.01.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Logan Gunthorpe Date: Fri, 17 Mar 2017 12:48:21 -0600 Message-Id: <1489776503-3151-15-git-send-email-logang@deltatee.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1489776503-3151-1-git-send-email-logang@deltatee.com> References: <1489776503-3151-1-git-send-email-logang@deltatee.com> X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: gregkh@linuxfoundation.org, dan.j.williams@intel.com, hans.verkuil@cisco.com, viro@zeniv.linux.org.uk, jgunthorpe@obsidianresearch.com, jthumshirn@suse.de, linus.walleij@linaro.org, jarkko.sakkinen@linux.intel.com, jejb@linux.vnet.ibm.com, martin.petersen@oracle.com, dwmw2@infradead.org, alexandre.belloni@free-electrons.com, boris.brezillon@free-electrons.com, dmitry.torokhov@gmail.com, computersforpeace@gmail.com, marek.vasut@gmail.com, cyrille.pitchen@atmel.com, rtc-linux@googlegroups.com, linux-mtd@lists.infradead.org, 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=-6.5 required=5.0 tests=ALL_TRUSTED,BAYES_00, MYRULES_FREE, MYRULES_NO_TEXT, RP_MATCHES_RCVD autolearn=no autolearn_force=no version=3.4.0 Subject: [PATCH v5 14/16] rtc: utilize new cdev_device_add 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) Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Mostly straightforward, but we had to remove the rtc_dev_add/del_device functions as they split up the cdev_add and the device_add. Doing this also revealed that there was likely another subtle bug: seeing cdev_add was done after device_register, the cdev probably was not ready before device_add when the uevent occurs. This would race with userspace, if it tried to use the device directly after the uevent. This is fixed just by using the new helper function. Another weird thing is this driver would, in some error cases, call cdev_add() without calling cdev_init. This patchset corrects this by avoiding calling cdev_add if the devt is not set. Signed-off-by: Logan Gunthorpe Acked-by: Alexandre Belloni --- drivers/rtc/class.c | 14 ++++++++++---- drivers/rtc/rtc-core.h | 10 ---------- drivers/rtc/rtc-dev.c | 17 ----------------- 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index 74fd974..5fb4398 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c @@ -195,6 +195,8 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, goto exit_ida; } + device_initialize(&rtc->dev); + rtc->id = id; rtc->ops = ops; rtc->owner = owner; @@ -233,14 +235,19 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, rtc_dev_prepare(rtc); - err = device_register(&rtc->dev); + err = cdev_device_add(&rtc->char_dev, &rtc->dev); if (err) { + dev_warn(&rtc->dev, "%s: failed to add char device %d:%d\n", + rtc->name, MAJOR(rtc->dev.devt), rtc->id); + /* This will free both memory and the ID */ put_device(&rtc->dev); goto exit; + } else { + dev_dbg(&rtc->dev, "%s: dev (%d:%d)\n", rtc->name, + MAJOR(rtc->dev.devt), rtc->id); } - rtc_dev_add_device(rtc); rtc_proc_add_device(rtc); dev_info(dev, "rtc core: registered %s as %s\n", @@ -271,9 +278,8 @@ void rtc_device_unregister(struct rtc_device *rtc) * Remove innards of this RTC, then disable it, before * letting any rtc_class_open() users access it again */ - rtc_dev_del_device(rtc); rtc_proc_del_device(rtc); - device_del(&rtc->dev); + cdev_device_del(&rtc->char_dev, &rtc->dev); rtc->ops = NULL; mutex_unlock(&rtc->ops_lock); put_device(&rtc->dev); diff --git a/drivers/rtc/rtc-core.h b/drivers/rtc/rtc-core.h index a098aea..7a4ed2f 100644 --- a/drivers/rtc/rtc-core.h +++ b/drivers/rtc/rtc-core.h @@ -3,8 +3,6 @@ extern void __init rtc_dev_init(void); extern void __exit rtc_dev_exit(void); extern void rtc_dev_prepare(struct rtc_device *rtc); -extern void rtc_dev_add_device(struct rtc_device *rtc); -extern void rtc_dev_del_device(struct rtc_device *rtc); #else @@ -20,14 +18,6 @@ static inline void rtc_dev_prepare(struct rtc_device *rtc) { } -static inline void rtc_dev_add_device(struct rtc_device *rtc) -{ -} - -static inline void rtc_dev_del_device(struct rtc_device *rtc) -{ -} - #endif #ifdef CONFIG_RTC_INTF_PROC diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c index 6dc8f29..e81a871 100644 --- a/drivers/rtc/rtc-dev.c +++ b/drivers/rtc/rtc-dev.c @@ -477,23 +477,6 @@ void rtc_dev_prepare(struct rtc_device *rtc) cdev_init(&rtc->char_dev, &rtc_dev_fops); rtc->char_dev.owner = rtc->owner; - rtc->char_dev.kobj.parent = &rtc->dev.kobj; -} - -void rtc_dev_add_device(struct rtc_device *rtc) -{ - if (cdev_add(&rtc->char_dev, rtc->dev.devt, 1)) - dev_warn(&rtc->dev, "%s: failed to add char device %d:%d\n", - rtc->name, MAJOR(rtc_devt), rtc->id); - else - dev_dbg(&rtc->dev, "%s: dev (%d:%d)\n", rtc->name, - MAJOR(rtc_devt), rtc->id); -} - -void rtc_dev_del_device(struct rtc_device *rtc) -{ - if (rtc->dev.devt) - cdev_del(&rtc->char_dev); } void __init rtc_dev_init(void)