Linux-NVDIMM Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Logan Gunthorpe <logang@deltatee.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>, Jan Kara <jack@suse.cz>,
	linux-iio@vger.kernel.org, linux-pci@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>,
	Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
	Alexandre Bounine <alexandre.bounine@idt.com>,
	linux-mtd@lists.infradead.org,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-scsi@vger.kernel.org, Sean Hefty <sean.hefty@intel.com>,
	Parav Pandit <pandit.parav@gmail.com>,
	Peter Huewe <peterhuewe@gmx.de>,
	Alexandre Courbot <gnurou@gmail.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
	rtc-linux@googlegroups.com, Leon Romanovsky <leon@kernel.org>,
	linux-nvdimm@lists.01.org, linux-rdma@vger.kernel.org,
	Richard Weinberger <richard@nod.at>,
	Jason Gunthorpe <jgunthorpe@obsidianresearch.com>,
	Marek Vasut <marek.vasut@gmail.com>,
	Doug Ledford <dledford@redhat.com>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Matt Porter <mporter@kernel.crashing.org>,
	Hal Rosenstock <hal.rosenstock@gmail.com>,
	linux-media@vger.kernel.org, Boaz Harrosh <ooo@electrozaur.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Boris Brezillon <boris.brezillon@free-electrons.com>,
	Sajjan Vikas C <vikas.cha.sajjan@hpe.com>,
	linux-input@vger.kernel.org, Marcel Selhorst <tpmdd@selhorst.net>,
	Vladimir Zapolskiy <vz@mleia.com>, Joe Perches <joe@perches.com>,
	Cyrille Pitchen <cyrille.pitchen@atmel.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Dmitry Vyukov <dvyukov@google.com>,
	Haggai Eran <haggaie@mellanox.com>,
	Lorenzo Stoakes <lstoakes@gmail.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Artem Bityutskiy <dedekind1@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-gpio@vger.kernel.org,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	linux-kernel@vger.kernel.org,
	Stephen Bates <stephen.bates@microsemi.com>,
	Hartmut Knaack <knaack.h@gmx.de>, Olof Johansson <olof@lixom.net>,
	linux-fsdevel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Brian Norris <computersforpeace@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>
Subject: Re: [PATCH v2 14/16] rtc: utilize new cdev_device_add helper function
Date: Mon, 27 Feb 2017 10:46:43 +0100	[thread overview]
Message-ID: <20170227094643.pag5preyj2dueabd@piout.net> (raw)
In-Reply-To: <1488091097-12328-15-git-send-email-logang@deltatee.com>

On 25/02/2017 at 23:38:15 -0700, Logan Gunthorpe wrote:
> 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.
> 
> Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

> ---
>  drivers/rtc/class.c   | 14 ++++++++++----
>  drivers/rtc/rtc-dev.c | 17 -----------------
>  2 files changed, 10 insertions(+), 21 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-dev.c b/drivers/rtc/rtc-dev.c
> index a6d9434..fdd071f 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)
> -- 
> 2.1.4
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

  reply	other threads:[~2017-02-27  9:46 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-26  6:38 [PATCH v2 00/16] Cleanup chardev instances with helper function Logan Gunthorpe
2017-02-26  6:38 ` [PATCH v2 01/16] chardev: add helper function to register char devs with a struct device Logan Gunthorpe
2017-02-26 18:21   ` Dan Williams
2017-02-27 16:56     ` Jason Gunthorpe
2017-02-28  3:27       ` Logan Gunthorpe
2017-02-28  3:36         ` Dan Williams
2017-02-28  5:31           ` Greg Kroah-Hartman
2017-02-27  9:01   ` Hans Verkuil
2017-02-27  9:47   ` Alexandre Belloni
2017-02-26  6:38 ` [PATCH v2 02/16] device-dax: fix cdev leak Logan Gunthorpe
2017-02-26 18:22   ` Dan Williams
2017-02-26  6:38 ` [PATCH v2 03/16] device-dax: utilize new cdev_device_add helper function Logan Gunthorpe
2017-02-26 22:31   ` Dan Williams
2017-02-26  6:38 ` [PATCH v2 04/16] input: " Logan Gunthorpe
2017-02-28 18:27   ` Dmitry Torokhov
2017-02-26  6:38 ` [PATCH v2 05/16] gpiolib: " Logan Gunthorpe
2017-02-26  6:38 ` [PATCH v2 06/16] tpm-chip: " Logan Gunthorpe
     [not found]   ` <1488091097-12328-7-git-send-email-logang-OTvnGxWRz7hWk0Htik3J/w@public.gmane.org>
2017-02-27 16:42     ` Jason Gunthorpe
2017-02-26  6:38 ` [PATCH v2 07/16] platform/chrome: cros_ec_dev - " Logan Gunthorpe
2017-02-26  6:38 ` [PATCH v2 08/16] IB/ucm: " Logan Gunthorpe
2017-02-26  6:38 ` [PATCH v2 09/16] infiniband: utilize the new cdev_set_parent function Logan Gunthorpe
2017-02-26  6:38 ` [PATCH v2 10/16] iio:core: utilize new cdev_device_add helper function Logan Gunthorpe
2017-02-26  6:38 ` [PATCH v2 11/16] media: " Logan Gunthorpe
2017-02-27  9:02   ` Hans Verkuil
2017-03-04 22:57     ` Logan Gunthorpe
2017-02-26  6:38 ` [PATCH v2 12/16] mtd: " Logan Gunthorpe
2017-02-26  6:38 ` [PATCH v2 13/16] rapidio: " Logan Gunthorpe
2017-02-26  6:38 ` [PATCH v2 14/16] rtc: " Logan Gunthorpe
2017-02-27  9:46   ` Alexandre Belloni [this message]
2017-02-26  6:38 ` [PATCH v2 15/16] scsi: " Logan Gunthorpe
2017-02-26  6:38 ` [PATCH v2 16/16] switchtec: utilize new device_add_cdev " Logan Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170227094643.pag5preyj2dueabd@piout.net \
    --to=alexandre.belloni@free-electrons.com \
    --cc=a.zummo@towertech.it \
    --cc=akpm@linux-foundation.org \
    --cc=alexandre.bounine@idt.com \
    --cc=arnd@arndb.de \
    --cc=bhelgaas@google.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@atmel.com \
    --cc=dedekind1@gmail.com \
    --cc=dledford@redhat.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=dvyukov@google.com \
    --cc=dwmw2@infradead.org \
    --cc=gnurou@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=haggaie@mellanox.com \
    --cc=hal.rosenstock@gmail.com \
    --cc=hans.verkuil@cisco.com \
    --cc=jack@suse.cz \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=joe@perches.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=leon@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-nvdimm@lists.01.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=logang@deltatee.com \
    --cc=lstoakes@gmail.com \
    --cc=marek.vasut@gmail.com \
    --cc=martin.petersen@oracle.com \
    --cc=mchehab@kernel.org \
    --cc=mporter@kernel.crashing.org \
    --cc=olof@lixom.net \
    --cc=ooo@electrozaur.com \
    --cc=pandit.parav@gmail.com \
    --cc=peterhuewe@gmx.de \
    --cc=pmeerw@pmeerw.net \
    --cc=richard@nod.at \
    --cc=rtc-linux@googlegroups.com \
    --cc=sean.hefty@intel.com \
    --cc=stephen.bates@microsemi.com \
    --cc=tpmdd@selhorst.net \
    --cc=vikas.cha.sajjan@hpe.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vz@mleia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox