Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750740AbWIMQik (ORCPT ); Wed, 13 Sep 2006 12:38:40 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1750750AbWIMQii (ORCPT ); Wed, 13 Sep 2006 12:38:38 -0400 Received: from mtagate4.de.ibm.com ([195.212.29.153]:60746 "EHLO mtagate4.de.ibm.com") by vger.kernel.org with ESMTP id S1750745AbWIMQif (ORCPT ); Wed, 13 Sep 2006 12:38:35 -0400 Date: Wed, 13 Sep 2006 18:38:54 +0200 From: Cornelia Huck To: Greg K-H Cc: linux-kernel Subject: [08/12] driver core fixes: device_add() cleanup on error Message-ID: <20060913183854.2dea7c0b@gondolin.boeblingen.de.ibm.com> In-Reply-To: <20060913163007.21cf10a8@gondolin.boeblingen.de.ibm.com> References: <20060913163007.21cf10a8@gondolin.boeblingen.de.ibm.com> X-Mailer: Sylpheed-Claws 2.5.0-rc3 (GTK+ 2.8.20; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1724 Lines: 54 From: Cornelia Huck Check for return code of device_create_file() and correct cleanup in the error case in device_add(). Signed-off-by: Cornelia Huck core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- linux-2.6.18-rc6/drivers/base/core.c 2006-09-12 16:19:43.000000000 +0200 +++ linux-2.6.18-rc6+CH/drivers/base/core.c 2006-09-12 18:27:55.000000000 +0200 @@ -406,14 +406,16 @@ int device_add(struct device *dev) if (dev->driver) dev->uevent_attr.attr.owner = dev->driver->owner; dev->uevent_attr.store = store_uevent; - device_create_file(dev, &dev->uevent_attr); + error = device_create_file(dev, &dev->uevent_attr); + if (error) + goto attrError; if (MAJOR(dev->devt)) { struct device_attribute *attr; attr = kzalloc(sizeof(*attr), GFP_KERNEL); if (!attr) { error = -ENOMEM; - goto PMError; + goto ueventattrError; } attr->attr.name = "dev"; attr->attr.mode = S_IRUGO; @@ -423,7 +425,7 @@ int device_add(struct device *dev) error = device_create_file(dev, attr); if (error) { kfree(attr); - goto attrError; + goto ueventattrError; } dev->devt_attr = attr; @@ -479,6 +481,8 @@ int device_add(struct device *dev) device_remove_file(dev, dev->devt_attr); kfree(dev->devt_attr); } + ueventattrError: + device_remove_file(dev, &dev->uevent_attr); attrError: kobject_uevent(&dev->kobj, KOBJ_REMOVE); kobject_del(&dev->kobj); - 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/