From patchwork Tue Apr 28 07:36:06 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 20343 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n3S7ctTW013623 for ; Tue, 28 Apr 2009 07:38:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760054AbZD1Hix (ORCPT ); Tue, 28 Apr 2009 03:38:53 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1760148AbZD1Hix (ORCPT ); Tue, 28 Apr 2009 03:38:53 -0400 Received: from hera.kernel.org ([140.211.167.34]:49281 "EHLO hera.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760251AbZD1Hiw (ORCPT ); Tue, 28 Apr 2009 03:38:52 -0400 Received: from [192.168.101.6] (adsl-75-36-240-162.dsl.pltn13.sbcglobal.net [75.36.240.162]) (authenticated bits=0) by hera.kernel.org (8.14.2/8.13.8) with ESMTP id n3S7aI9o027920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 28 Apr 2009 07:36:34 GMT Message-ID: <49F6B1E6.7050008@kernel.org> Date: Tue, 28 Apr 2009 00:36:06 -0700 From: Yinghai Lu User-Agent: Thunderbird 2.0.0.19 (X11/20081227) MIME-Version: 1.0 To: Ingo Molnar , Kay Sievers , Greg KH , Linus Torvalds CC: Jesse Barnes , Andrew Morton , "H. Peter Anvin" , Thomas Gleixner , "linux-kernel@vger.kernel.org" , linux-pci@vger.kernel.org Subject: [PATCH] driver: make dev_set_name(, NULL) work References: <20090416235452.GE21405@elte.hu> <20090417131633.GA30578@elte.hu> <49E8FD0B.2050308@zytor.com> <49E96731.1000501@kernel.org> <49EA27B9.3030004@kernel.org> <20090418192314.GA22107@suse.de> <1240086446.2411.9.camel@poy> <20090418203718.GD30144@elte.hu> <49EA4EB9.2030307@kernel.org> In-Reply-To: <49EA4EB9.2030307@kernel.org> X-Virus-Scanned: ClamAV 0.93.3/9297/Mon Apr 27 20:30:26 2009 on hera.kernel.org X-Virus-Status: Clean Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org while looking dev_set_name() calling, there is one dev_set_name(&dev->dev, NULL) to used to try to free the device name, before kfree that device. need to move the check for device_add in | commit 8a577ffc75d9194fe8cdb7479236f2081c26ca1f | Author: Kay Sievers | Date: Sat Apr 18 15:05:45 2009 -0700 | | driver: dont update dev_name via device_add path from kobject_set_name_vargs to kobject_add_vargs instead. in kobject_set_name_vargs will check if fmt is NULL. actually we need to use dev_set_name(,NULL) later on failing path and release to prevent leaking [ Impact: make dev_set_name(, NULL) could kfree old name ] Signed-off-by: Yinghai Lu --- lib/kobject.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-2.6/lib/kobject.c =================================================================== --- linux-2.6.orig/lib/kobject.c +++ linux-2.6/lib/kobject.c @@ -218,8 +218,8 @@ int kobject_set_name_vargs(struct kobjec const char *old_name = kobj->name; char *s; - if (kobj->name && !fmt) - return 0; + if (!fmt) + goto out; kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs); if (!kobj->name) @@ -229,6 +229,7 @@ int kobject_set_name_vargs(struct kobjec while ((s = strchr(kobj->name, '/'))) s[0] = '!'; +out: kfree(old_name); return 0; } @@ -301,11 +302,16 @@ static int kobject_add_varg(struct kobje { int retval; + if (kobj->name && !fmt) + goto add_with_name; + retval = kobject_set_name_vargs(kobj, fmt, vargs); if (retval) { printk(KERN_ERR "kobject: can not set name properly!\n"); return retval; } + +add_with_name: kobj->parent = parent; return kobject_add_internal(kobj); }