Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762827AbZLKW0B (ORCPT ); Fri, 11 Dec 2009 17:26:01 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1762805AbZLKWZo (ORCPT ); Fri, 11 Dec 2009 17:25:44 -0500 Received: from kroah.org ([198.145.64.141]:32840 "EHLO coco.kroah.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762766AbZLKWZR (ORCPT ); Fri, 11 Dec 2009 17:25:17 -0500 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Alan Stern , stable , Oliver Neukum , Greg Kroah-Hartman Subject: [PATCH 27/27] Driver core: fix race in dev_driver_string Date: Fri, 11 Dec 2009 14:24:49 -0800 Message-Id: <1260570289-6997-27-git-send-email-gregkh@suse.de> X-Mailer: git-send-email 1.6.5.3 In-Reply-To: <20091211212642.GA6624@kroah.com> References: <20091211212642.GA6624@kroah.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1486 Lines: 42 From: Alan Stern This patch (as1310) works around a race in dev_driver_string(). If the device is unbound while the function is running, dev->driver might become NULL after we test it and before we dereference it. Signed-off-by: Alan Stern Cc: stable Cc: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 353b137..f1290cb 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -56,7 +56,14 @@ static inline int device_is_not_partition(struct device *dev) */ const char *dev_driver_string(const struct device *dev) { - return dev->driver ? dev->driver->name : + struct device_driver *drv; + + /* dev->driver can change to NULL underneath us because of unbinding, + * so be careful about accessing it. dev->bus and dev->class should + * never change once they are set, so they don't need special care. + */ + drv = ACCESS_ONCE(dev->driver); + return drv ? drv->name : (dev->bus ? dev->bus->name : (dev->class ? dev->class->name : "")); } -- 1.6.5.5 -- 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/