Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755288AbZLJTct (ORCPT ); Thu, 10 Dec 2009 14:32:49 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754584AbZLJTcs (ORCPT ); Thu, 10 Dec 2009 14:32:48 -0500 Received: from www.tglx.de ([62.245.132.106]:40057 "EHLO www.tglx.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754466AbZLJTcr (ORCPT ); Thu, 10 Dec 2009 14:32:47 -0500 Message-Id: <20091210193057.799393067@linutronix.de> User-Agent: quilt/0.47-1 Date: Thu, 10 Dec 2009 19:32:49 -0000 From: Thomas Gleixner To: LKML Cc: Greg Kroah-Hartman , Kay Sievers Subject: [patch] drivers: Fix bogus 0 error return in device_add() Content-Disposition: inline; filename=drivers-base-fix-error-path.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1413 Lines: 40 If device_add() is called with a device which does not have dev->p set up, then device_private_init() is called. If that succeeds, then the error variable is set to 0. Now if the dev_name(dev) check further down fails, then device_add() correctly terminates, but returns 0. That of course lets the driver progress. If later another driver uses this half set up device as parent then device_add() of the child device explodes and renders sysfs completely unusable. Set the error to -EINVAL if dev_name() check fails. Signed-off-by: Thomas Gleixner Cc: Greg Kroah-Hartman Cc: Kay Sievers --- drivers/base/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) Index: linux-2.6-tip/drivers/base/core.c =================================================================== --- linux-2.6-tip.orig/drivers/base/core.c +++ linux-2.6-tip/drivers/base/core.c @@ -898,8 +898,10 @@ int device_add(struct device *dev) dev->init_name = NULL; } - if (!dev_name(dev)) + if (!dev_name(dev)) { + error = -EINVAL; goto name_error; + } pr_debug("device: '%s': %s\n", dev_name(dev), __func__); -- 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/