From patchwork Tue Feb 19 19:36:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Malat X-Patchwork-Id: 221860 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id BFFD02C008E for ; Wed, 20 Feb 2013 06:33:21 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933834Ab3BSTdS (ORCPT ); Tue, 19 Feb 2013 14:33:18 -0500 Received: from mail-ea0-f173.google.com ([209.85.215.173]:43772 "EHLO mail-ea0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933341Ab3BSTdQ (ORCPT ); Tue, 19 Feb 2013 14:33:16 -0500 Received: by mail-ea0-f173.google.com with SMTP id i1so2962202eaa.4 for ; Tue, 19 Feb 2013 11:33:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:date:from:to:cc:subject:message-id:mime-version :content-type:content-disposition:user-agent:x-gm-message-state; bh=OoE+0p0K14/DK1pFdjckeIa8hYWSRXrnJKP++45T0oM=; b=NxhgEpQi5C4F6YO8VFJDKT2dWw/Vilp8toCEaCCd283+py0dMyJSDJ2EJn5sKGT8vp SPbo9pQF/cPc+lw3h7n0okjmypyoh9a1VLpMfXSfJ/bv8plZ2y1GJUlRNCXi/Iw8gibv QcwZGB/IkzwriqUh2EESqqE4LhR4VveuxOSKt+RM1vEwdD/hn5b++3V1M9fXtSD21eyK XikDVRY+B+79gz4sQx/v8vshbeAnCWBUdCSOg5l3M+M+h5TsaZVYwgrApGcUpcD3K/w+ UESJsQfS3uF7T5pZr2s76TWM2SKuMqnpH1VLdjKZ/6KZdbCuPW9ehfTS6Goi3V/Q5d41 rb2A== X-Received: by 10.14.206.132 with SMTP id l4mr59557957eeo.38.1361302393715; Tue, 19 Feb 2013 11:33:13 -0800 (PST) Received: from bordel.klfree.net (bordel.klfree.cz. [81.201.48.42]) by mx.google.com with ESMTPS id l8sm71514508een.10.2013.02.19.11.33.11 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 19 Feb 2013 11:33:12 -0800 (PST) Date: Tue, 19 Feb 2013 20:36:46 +0100 From: Petr Malat To: netdev@vger.kernel.org Cc: Petr Malat Subject: [PATCH] phy: fix phy_device_free memory leak Message-ID: <20130219193646.GA10851@bordel.klfree.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-Gm-Message-State: ALoCoQnP6qQvDfE6rdJoG7Cv3ZqRtt0/JKLda/JwVGTooDYrdszV++3y2SqbHCnqOKEWcmDoOXWG Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Petr Malat Fix memory leak in phy_device_free() for the case when phy_device* returned by phy_device_create() is not registered in the system. Bug description: phy_device_create() sets name of kobject using dev_set_name(), which allocates memory using kvasprintf(), but this memory isn't freed if the underlying device isn't registered properly, because kobject_cleanup() is not called in that case. This can happen (and actually is happening on our machines) if phy_device_register(), called by mdiobus_scan(), fails. Patch description: Name is freed by phy_device_free(). In the case a device is released trough kobject_cleanup()->device_release()->phy_device_release(), the name is set to NULL and it is not freed by phy_device_free(), because it will be freed later by kobject_cleanup(). Signed-off-by: Petr Malat --- Please put me on CC, I'm not signed into the mailing list. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- linux-v2.6.32.60.orig/drivers/net/phy/phy_device.c 2013-02-06 19:44:11.000000000 +0100 +++ linux-v2.6.32.60/drivers/net/phy/phy_device.c 2013-02-06 20:56:57.000000000 +0100 @@ -41,12 +41,16 @@ MODULE_LICENSE("GPL"); void phy_device_free(struct phy_device *phydev) { + kfree(phydev->dev.kobj.name); kfree(phydev); } EXPORT_SYMBOL(phy_device_free); static void phy_device_release(struct device *dev) { + /* Name will be freed by kobject_cleanup() */ + dev->kobj.name = NULL; + phy_device_free(to_phy_device(dev)); }