All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Riegel <damien.riegel@savoirfairelinux.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: linux-watchdog@vger.kernel.org, Wim Van Sebroeck <wim@iguana.be>,
	kernel@savoirfairelinux.com
Subject: Re: [PATCH v2 1/2] watchdog: core: call device_destroy before watchdog_dev_unregister
Date: Wed, 25 Nov 2015 17:43:51 -0500	[thread overview]
Message-ID: <20151125224351.GC3627@localhost> (raw)
In-Reply-To: <5655F680.5020408@roeck-us.net>

On Wed, Nov 25, 2015 at 09:57:20AM -0800, Guenter Roeck wrote:
> Hi Damien,
> 
> On 11/25/2015 09:09 AM, Damien Riegel wrote:
> >On Tue, Nov 24, 2015 at 06:20:11PM -0800, Guenter Roeck wrote:
> >>On 11/24/2015 03:45 PM, Damien Riegel wrote:
> >>>device_create is called after watchdog_dev_register, so it makes more
> >>>sense to call the cleanup functions in reverse order, ie. device_destroy
> >>>before watchdog_dev_unregister.
> >>>
> >>>Signed-off-by: Damien Riegel <damien.riegel@savoirfairelinux.com>
> >>
> >>Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> >>
> >
> >On second thought, I am wondering if the proper fix would not be to call
> >device_create before watchdog_dev_register. Consider the following
> >scenario:
> >
> >   watchdog_register_device
> >     __watchdog_register_device
> >	  watchdog_dev_register returns successfully, char dev is live
> >       device_create fails, setting wdd->dev to an ERR_PTR
> >	  ...
> >	  meanwhile, a user opens the watchdog, hence ops->start is called.
> >	  If ops->start uses wdd->dev (to print a debug message for
> >	  instance), it will dereference an invalid pointer.
> >
> >Admittedly, it should be quite rare, but there is still a chance for a
> >race condition here.
> >
> Only we should not have race conditions, and this might actually happen
> if user space listens for a udev event on the character device, and device
> creation is delayed for some reasons.
> 
> I think you are right, that is a problem. Back to the drawing board.
> 
> Ok, next question: Does it hurt to call device_create() first ?
> That creates the sysfs entries for the driver.

I can't think of a case where it would be an issue to call
device_create() first. After all, watchdog_dev_register just creates
entries in /dev, so it makes sense to create them only when the watchdog
is fully ready. I will send patches tomorrow.

> 
> If that doesn't work either, the only other idea I have would be to reject
> an attempt to open the character device with -EAGAIN or similar if the
> device node is not yet (or not anymore) available. Or maybe that would
> be the correct approach anyway ? Or can we use some lock to synchronize
> the two operations ?
> 
> Thanks,
> Guenter
> 

      reply	other threads:[~2015-11-25 22:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-24 23:45 [PATCH v2 1/2] watchdog: core: call device_destroy before watchdog_dev_unregister Damien Riegel
2015-11-24 23:45 ` [PATCH v2 2/2] watchdog: core: factorize register error paths Damien Riegel
2015-11-25  2:20   ` Guenter Roeck
2015-11-25  2:20 ` [PATCH v2 1/2] watchdog: core: call device_destroy before watchdog_dev_unregister Guenter Roeck
2015-11-25 17:09   ` Damien Riegel
2015-11-25 17:57     ` Guenter Roeck
2015-11-25 22:43       ` Damien Riegel [this message]

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=20151125224351.GC3627@localhost \
    --to=damien.riegel@savoirfairelinux.com \
    --cc=kernel@savoirfairelinux.com \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=wim@iguana.be \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.