From patchwork Fri May 12 18:45:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 93325 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5333979vqo; Fri, 12 May 2023 12:08:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42Jz1lJlZE9qNrngEohOwTac+sXswDLt1nZhBQxp8xfKb0gteFihBSwTkMwR/+nGGqZMSy X-Received: by 2002:a05:6a00:1391:b0:643:ba77:f265 with SMTP id t17-20020a056a00139100b00643ba77f265mr32168370pfg.25.1683918524515; Fri, 12 May 2023 12:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683918524; cv=none; d=google.com; s=arc-20160816; b=t96IKcAJawUMbB0inMSHtnaBAV8+hj7D/eCS+AT13WdJFc7bFSp5qT5nS5Z18O8ufl ww5Ix9IdsAuDPQP1qQ2L+KbC2Zpkyp8tSBOFB3OcxQY5NkFCP86JXpgZorsNVt5LyRzc vJ3xBF7vP0J6E5122m7+/GDeEmrxGvl77Vf/N1ehSgdZ6mhqY0+6Wu/YeTmrcLGZgjz0 cEl1v5d0KJu/KxHHLOV7jjkfaM/JYo++Hb4pYwlhxfX2GJvMzKdaeT5CJlK9gdLDheeF Fk5wLC7adsbHv7rD+4t5/FhHgj+oruejwoHZ48FPhjBpQK03sYsYvmb2l/Ji+BNE5ZsE pB7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=7TrDa3m7tjfa4HgLLMDPT00oA29VBvrR6GTIJF9iVZg=; b=bs7zfSIK0E4XDEEijZP40/asjlezj+IycCAlxq0gSBoG/SyaDnhvPgkCdlMjMIG/o4 7buBkZIkeH46C7t07h6Jp4zKCMlVaN7fbklQf4wr9XmQ00pVH+96UZAAws2JDPhen/M3 knSLN2lVyFtmWI3PjFPazF2dYtqhQ13vL/riD7982tLMLzmT17XCQJtM3WR9pnPfnZEi cNQZH2AQvxwIOAJ290+RiJwxAzn34anTwjj1hwCt+GSmyqupptiiNlQV+A75TIGgyxxW it+cb9NeslSPeQ5HwgAP43sX96xiDwut+LhDWnWj1f1T0mssa8ECjox6v4bNQnn7yV8G N2Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=KtBsBY+o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x6-20020aa79a46000000b006478fe28452si8528211pfj.27.2023.05.12.12.08.28; Fri, 12 May 2023 12:08:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=KtBsBY+o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239027AbjELSpw (ORCPT + 99 others); Fri, 12 May 2023 14:45:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238273AbjELSpv (ORCPT ); Fri, 12 May 2023 14:45:51 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 637821FF6 for ; Fri, 12 May 2023 11:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1683917134; i=w_armin@gmx.de; bh=+eTiMBMEYCQmTIVOXXB3t4eOtrkdVUr1eVgLYUzYkj4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=KtBsBY+orvFPSjbDjFOEFVrtblOjpOIYob9bSUEjVKfcbJ+fCdfPtiGS1H+89TtD4 np1U/Ry9TG+js6EtLB7rOMSMOF193Q6n3p11r/oipazpmLWjxZjpuncYkNDgG+IGqs 9YQ1BZLNfaPs+g6azmvQcWrULX18qntJfzJMh98lI728NMHI0yyBNkfCxq8fzWBc5Q pr/M4fWuDZL9l1p7OiMHBUcvuQHd0oeFU7rdATkQ3gUY016CB2VRktq2G18worKQFk K782cIl8f60+YErr8x4J82k/45gBkDon91BuhPUTXJ1Lho77Xd1cMiVrz9ut6u3Z/+ TBh1WVq3l+Tqw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MjS9I-1qcgLs376o-00kz94; Fri, 12 May 2023 20:45:34 +0200 From: Armin Wolf To: linux@dominikbrodowski.net Cc: logang@deltatee.com, gregkh@linuxfoundation.org, rafael@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] pcmcia: rsrc_nonstatic: Fix memory leak in nonstatic_release_resource_db() Date: Fri, 12 May 2023 20:45:29 +0200 Message-Id: <20230512184529.5094-1-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Provags-ID: V03:K1:bwpWglXSi456kA93f1yP0W0SEIWl5d5lWj4CdveJSIjyvgA6iHQ TGK6apcrUligWDGiJStxzUCTowgmYFdopmT6MzhykyOT8B4aED//I19KUvprja43uRal3+b vNWwfkKWT2ctPA8I5S3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rDXmzxYo1KIsjjEEKVYoZ wZeFRlsUVtn1f22PIltBgw4uOXw= X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765716550714131169?= X-GMAIL-MSGID: =?utf-8?q?1765716550714131169?= When nonstatic_release_resource_db() frees all resources associated with an PCMCIA socket, it forgets to free socket_data too, causing a memory leak observable with kmemleak: unreferenced object 0xc28d1000 (size 64): comm "systemd-udevd", pid 297, jiffies 4294898478 (age 194.484s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 f0 85 0e c3 00 00 00 00 ................ 00 00 00 00 0c 10 8d c2 00 00 00 00 00 00 00 00 ................ backtrace: [] __kmem_cache_alloc_node+0x2d7/0x4a0 [<7e51f0c8>] kmalloc_trace+0x31/0xa4 [] nonstatic_init+0x24/0x1a4 [pcmcia_rsrc] [] pcmcia_register_socket+0x200/0x35c [pcmcia_core] [] yenta_probe+0x4d8/0xa70 [yenta_socket] [] pci_device_probe+0x99/0x194 [<84b7c690>] really_probe+0x181/0x45c [<8060fe6e>] __driver_probe_device+0x75/0x1f4 [] driver_probe_device+0x28/0xac [<648b766f>] __driver_attach+0xeb/0x1e4 [<6e9659eb>] bus_for_each_dev+0x61/0xb4 [<25a669f3>] driver_attach+0x1e/0x28 [] bus_add_driver+0x102/0x20c [] driver_register+0x5b/0x120 [<942cd8a4>] __pci_register_driver+0x44/0x4c [] __UNIQUE_ID___addressable_cleanup_module188+0x1c/0xfffff000 [iTCO_vendor_support] Fix this by freeing socket_data too. Tested on a Acer Travelmate 4002WLMi by manually binding/unbinding the yenta_cardbus driver (yenta_socket). Signed-off-by: Armin Wolf --- drivers/pcmcia/rsrc_nonstatic.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.30.2 diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 471e0c5815f3..bf9d070a4496 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -1053,6 +1053,8 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s) q = p->next; kfree(p); } + + kfree(data); }