From patchwork Wed Feb 6 23:07:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Malat X-Patchwork-Id: 218792 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 CD7812C02EF for ; Thu, 7 Feb 2013 10:07:24 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757733Ab3BFXHV (ORCPT ); Wed, 6 Feb 2013 18:07:21 -0500 Received: from mail-ee0-f42.google.com ([74.125.83.42]:32819 "EHLO mail-ee0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755489Ab3BFXHS (ORCPT ); Wed, 6 Feb 2013 18:07:18 -0500 Received: by mail-ee0-f42.google.com with SMTP id b47so1020338eek.15 for ; Wed, 06 Feb 2013 15:07:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:subject:date:user-agent:cc:mime-version :content-type:content-transfer-encoding:content-disposition :message-id:x-gm-message-state; bh=V1sbZckYnW42lhaQDnw/qAM4GBXcdaKCBb+oxJdpRA0=; b=oICebtl5mNTDatSQ4C5l8U8vwVO3qItMriRiyePQACS5LXMe3ey2YVQSvAmpqcrOz1 NvMQG1r+WPKzkNAo+TLvZJ8G/0kCZk+9RK4k0aDWSlYIHn4Hypv6kFNCylJWEMedg5M3 Rj3TmBLxUoyYAbYi6hduU30HRoCNkXwd3K6GpaGgOyY//9ctHVu71+YVk4T5Cg6sNYA5 yKxyg11T37teUYAhiIWW0E1RIl7Hb81+vMdOFxzIVwylZCoDw8GICRSHHl6ppyOEtxzX qzOwqDhvd8BRbvty/y9PgQRdjDqik8j+dmlX9Und1pPnpo0mkSJToAF/ts47ytToXnst KAbA== X-Received: by 10.14.173.69 with SMTP id u45mr101977678eel.21.1360192036924; Wed, 06 Feb 2013 15:07:16 -0800 (PST) Received: from [192.168.2.107] (HSI-KBW-082-212-009-221.hsi.kabelbw.de. [82.212.9.221]) by mx.google.com with ESMTPS id s3sm833016eem.4.2013.02.06.15.07.15 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 06 Feb 2013 15:07:16 -0800 (PST) From: Petr Malat To: netdev@vger.kernel.org Subject: [PATCH]: fix phy_device_free memory leak Date: Thu, 7 Feb 2013 00:07:57 +0100 User-Agent: KMail/1.9.10 (enterprise35 0.20100827.1168748) Cc: oss@malat.biz MIME-Version: 1.0 Content-Disposition: inline Message-Id: <201302070007.57434.oss@malat.biz> X-Gm-Message-State: ALoCoQnjG8w0eQ19pRu+yUsyXWCEaDen7VQpm5WozzfLpeCImu9kSjKEhw4OTcjviUcVXI8fXVeJ Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hi, there is a memory leak in phy_device handling: 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. I fixed this by the attached patch, so far it's working fine. 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(). Please put me on CC, I'm not signed into the mailing list. Petr the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/drivers/net/phy/phy_device.c 2013-02-06 19:44:11.000000000 +0100 +++ b/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)); } -- To unsubscribe from this list: send the line "unsubscribe netdev" in