Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756286Ab2FHNkc (ORCPT ); Fri, 8 Jun 2012 09:40:32 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:36319 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752032Ab2FHNka (ORCPT ); Fri, 8 Jun 2012 09:40:30 -0400 Date: Fri, 8 Jun 2012 09:40:29 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Ming Lei cc: Greg Kroah-Hartman , , , Subject: Re: [PATCH] driver core: fix shutdown races with probe/remove(v1) In-Reply-To: <1339133929-30679-1-git-send-email-ming.lei@canonical.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1413 Lines: 42 On Fri, 8 Jun 2012, Ming Lei wrote: > Firstly, .shutdown callback may touch a uninitialized hardware > if dev->driver is set and .probe is not completed. > > Secondly, device_shutdown() may dereference a null pointer to cause > oops when dev->driver is cleared after it is checked in > device_shutdown(). > > So just hold device lock and its parent lock if it has to fix the > races. > > Cc: Alan Stern > Cc: stable@vger.kernel.org > Signed-off-by: Ming Lei > --- > drivers/base/core.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/drivers/base/core.c b/drivers/base/core.c > index 346be8b..cbc8bd2 100644 > --- a/drivers/base/core.c > +++ b/drivers/base/core.c > @@ -1820,6 +1820,11 @@ void device_shutdown(void) > list_del_init(&dev->kobj.entry); > spin_unlock(&devices_kset->list_lock); > > + /*hold lock[s] to avoid races with .probe/.release*/ > + if (dev->parent) > + device_lock(dev->parent); > + device_lock(dev); Would you prefer to use device_trylock in a loop? I guess this comes down to which you prefer: a hang during shutdown, or a crash. :-) Alan Stern -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/