From patchwork Mon Dec 23 09:39:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Wu X-Patchwork-Id: 304741 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 0B2E12C0078 for ; Mon, 23 Dec 2013 20:40:51 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757033Ab3LWJkt (ORCPT ); Mon, 23 Dec 2013 04:40:49 -0500 Received: from mail-ea0-f171.google.com ([209.85.215.171]:39524 "EHLO mail-ea0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756813Ab3LWJks (ORCPT ); Mon, 23 Dec 2013 04:40:48 -0500 Received: by mail-ea0-f171.google.com with SMTP id h10so2210265eak.2 for ; Mon, 23 Dec 2013 01:40:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MnPbM037yQKXkX6bcbCUE4JpOFvgGD2mXe7LR+s9WOY=; b=rOlkc3fsVDtm4stKbTnz2ADRX9o8rtfoIM/+5CI//c90hSFlxjfDMrXA4Lr//yjWrY 9RkqhhW5G+/RXbWGS5TcAXK8gN6jKjF8JSIN716c741T8qWPmpRcxotTfTCzIHYE1ozs vwjoENDb7hdiLgEBHll8C5B5U3pmDuMH8LsJvGAcIVBIDR6a0pPebinkjMuglsew3UF7 YEAuoM97UGeeN1RDFyK6kAOVfbS0MEuZgE0ZiBAfMkXwcoeqfS24eTKiRbtb1j0Vm3Yj dQkVz6UB05ESeZlffn1gQ7HGGLV+UqdfbdS7mF2xsg01/HuATLGx5V2hZeLWeh8y9mUC ItNQ== X-Received: by 10.15.95.72 with SMTP id bc48mr19232215eeb.49.1387791647179; Mon, 23 Dec 2013 01:40:47 -0800 (PST) Received: from localhost.localdomain (ip4da018ae.direct-adsl.nl. [77.160.24.174]) by mx.google.com with ESMTPSA id b41sm43888764eef.16.2013.12.23.01.40.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Dec 2013 01:40:45 -0800 (PST) From: Peter Wu To: Jean Delvare Cc: linux-i2c@vger.kernel.org, Martin Mokrejs , linux-kernel@vger.kernel.org, Peter Wu Subject: [PATCH] i2c: i801: fix memleak on probe error Date: Mon, 23 Dec 2013 10:39:38 +0100 Message-Id: <1387791578-1372-1-git-send-email-lekensteyn@gmail.com> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <20130123174204.00463f98@endymion.delvare> References: <20130123174204.00463f98@endymion.delvare> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The driver-specific data for i801 was only set for the device on success, that led to a memory leak on error paths (for instance, when there is a resource conflict with ACPI). (The driver core clears the driver data (if set) if the probe routine fails). Fix it by setting the driver data right after successful memory allocation, before reaching any error paths. References: http://lkml.org/lkml/2013/1/23/191 Reported-by: Martin Mokrejs Tested-by: Peter Wu [ACPI conflict error path] Signed-off-by: Peter Wu --- Hi Jean, This memleak issue is still present in v3.13-rc4-256-gb7000ad. From kmemleak: unreferenced object 0xffff88022f501a00 (size 256): comm "systemd-udevd", pid 209, jiffies 4294896115 (age 2872.520s) hex dump (first 32 bytes): 00 00 00 00 ad 4e ad de ff ff ff ff 00 00 00 00 .....N.......... ff ff ff ff ff ff ff ff f4 e2 53 82 ff ff ff ff ..........S..... backtrace: [] kmemleak_alloc+0x4e/0xb0 [] kmem_cache_alloc_trace+0xfa/0x1e0 [] device_private_init+0x23/0x80 [] dev_set_drvdata+0x39/0x50 [] i801_probe+0x59/0x528 [i2c_i801] [] local_pci_probe+0x45/0xa0 [] pci_device_probe+0xd9/0x130 [] driver_probe_device+0x87/0x390 [] __driver_attach+0x93/0xa0 [] bus_for_each_dev+0x6b/0xb0 [] driver_attach+0x1e/0x20 [] bus_add_driver+0x188/0x260 [] driver_register+0x64/0xf0 [] __pci_register_driver+0x60/0x70 [] 0xffffffffa02990af [] do_one_initcall+0xf2/0x1a0 The dmesg for this laptop also contains a resource conflict message, just like the reporter (Martin Mokrejs): [ 15.409772] ACPI Warning: 0x0000000000001840-0x000000000000185f SystemIO conflicts with Region \_SB_.PCI0.SBUS.SMBI 1 (20131115/utaddress-251) [ 15.413439] ACPI: If an ACPI driver is available for this device, you should use it instead of the native driver With this patch applied on top of almost 3.13-rc5 (v3.13-rc4-256-gb7000ad), the memleak is gone. Regards, Peter --- drivers/i2c/busses/i2c-i801.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 737e298..a7096bf 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -1117,6 +1117,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) if (!priv) return -ENOMEM; + pci_set_drvdata(dev, priv); i2c_set_adapdata(&priv->adapter, priv); priv->adapter.owner = THIS_MODULE; priv->adapter.class = i801_get_adapter_class(priv); @@ -1236,8 +1237,6 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) /* We ignore errors - multiplexing is optional */ i801_add_mux(priv); - pci_set_drvdata(dev, priv); - return 0; exit_free_irq: