Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5820iob; Tue, 17 May 2022 16:52:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5wSJVl3iTXzrxwMoy9nn0IkRCu0rMIaYiee46weJF3tbBjTizVUIfKBXeHd7SEY4Q5pG+ X-Received: by 2002:a05:6a00:1ad2:b0:510:72f6:d039 with SMTP id f18-20020a056a001ad200b0051072f6d039mr24921477pfv.2.1652831575237; Tue, 17 May 2022 16:52:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652831575; cv=none; d=google.com; s=arc-20160816; b=tCYetaSYgX4/XTolzcyfMka3RJND5ogzNwULeehgtGmX3VHKSr7wLFEWnBQv2pgHBm 9a0f4fVWpESa0+mO3zsW40VsO9A6eFpEx7z+l+gzAPUdcC/pQcNsl4kUE5V6z80HU5k4 I5VRsw28AqLYf8i01aYxHvulliRrngI0TdmEpLu5uohKYUo2h+AhTcoECnLGaB7mGtqQ 5jfBxSgerHmr3hySrEXULzRcamAtODn0x/4rWB+oWyEfYsuKfemJrhXbwS5Ltkc3+2k4 lCKi4DofU08Q/lhcUgVMj8FLIeaZfxgsyWsAUTVwhx8RmNpE1NjxHplLtgBv/7Qt4s/1 o8LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MqUAo7rjhuTpZFl/+4Z8hvT2xAh0kNjcLGhz5BPw3Wg=; b=q+9gw+bIAbrD2kQsZOBAwnYcUw6KLElmU1Ozx7dq+dBTQVbOaMMoVeO85gxtpzE8tw B8P5502Inqj1xrKUFXw0JSqrjZYjMLSC/qMgM1ay721nodQcXVCKObmC4hlLP3FxscUW OllqE0UKk74W807cqq6DNssRbEj9X9U2EwDY3WTzkrGAbXr52q3n0Ag5sX8XfTwhMul3 0RwzY1c04IJlOfl97cI0SfPoEtHsavSjLL7YJfQ8+DDFVcseOuK1MHUpufijUn6llnWH d8B6ofTwm7vi2FLC4zz5tDjQogGF9OR9ZqoomNgU1dNvphCglajKQuHQSSbZmVEFV0VY dZkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cj5RNqlY; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p22-20020a1709028a9600b00153b2d16643si508891plo.587.2022.05.17.16.52.42; Tue, 17 May 2022 16:52:55 -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=@linuxfoundation.org header.s=korg header.b=cj5RNqlY; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346298AbiEPTtN (ORCPT + 99 others); Mon, 16 May 2022 15:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345854AbiEPTmL (ORCPT ); Mon, 16 May 2022 15:42:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9631041322; Mon, 16 May 2022 12:40:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F2EE8614B6; Mon, 16 May 2022 19:40:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F2B3C385AA; Mon, 16 May 2022 19:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730043; bh=oE7W6xw29WDDgIV+YB10Eo+LSQnZt2ZhTkmKIST7jmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cj5RNqlYMfUNKA/HtQm47LhZxAm41q3HWM02OTErwdT5SobsuXHeVGG41OkUTktyR owtwmmlk3uv83QTVnqYFhvDp9mV6eq7UXBmrWA6K7Wfg6t9sH6Pykd5tHe9HvOX5wp ns6hnyEDy64LgAg4Tb9mi3YroWBf8NAQaOXoyt6Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martin Habets , Taehee Yoo , Jakub Kicinski , Sasha Levin Subject: [PATCH 4.19 13/32] net: sfc: ef10: fix memory leak in efx_ef10_mtd_probe() Date: Mon, 16 May 2022 21:36:27 +0200 Message-Id: <20220516193615.169017131@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193614.773450018@linuxfoundation.org> References: <20220516193614.773450018@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Taehee Yoo [ Upstream commit 1fa89ffbc04545b7582518e57f4b63e2a062870f ] In the NIC ->probe() callback, ->mtd_probe() callback is called. If NIC has 2 ports, ->probe() is called twice and ->mtd_probe() too. In the ->mtd_probe(), which is efx_ef10_mtd_probe() it allocates and initializes mtd partiion. But mtd partition for sfc is shared data. So that allocated mtd partition data from last called efx_ef10_mtd_probe() will not be used. Therefore it must be freed. But it doesn't free a not used mtd partition data in efx_ef10_mtd_probe(). kmemleak reports: unreferenced object 0xffff88811ddb0000 (size 63168): comm "systemd-udevd", pid 265, jiffies 4294681048 (age 348.586s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [] kmalloc_order_trace+0x19/0x120 [] __kmalloc+0x20e/0x250 [] efx_ef10_mtd_probe+0x11f/0x270 [sfc] [] efx_pci_probe.cold.17+0x3df/0x53d [sfc] [] local_pci_probe+0xdc/0x170 [] pci_device_probe+0x235/0x680 [] really_probe+0x1c2/0x8f0 [] __driver_probe_device+0x2ab/0x460 [] driver_probe_device+0x4a/0x120 [] __driver_attach+0x16e/0x320 [] bus_for_each_dev+0x110/0x190 [] bus_add_driver+0x39e/0x560 [] driver_register+0x18e/0x310 [] 0xffffffffc02e2055 [] do_one_initcall+0xc3/0x450 [] do_init_module+0x1b4/0x700 Acked-by: Martin Habets Fixes: 8127d661e77f ("sfc: Add support for Solarflare SFC9100 family") Signed-off-by: Taehee Yoo Link: https://lore.kernel.org/r/20220512054709.12513-1-ap420073@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/sfc/ef10.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ethernet/sfc/ef10.c b/drivers/net/ethernet/sfc/ef10.c index 1f971d31ec30..6b0a4dc1ced1 100644 --- a/drivers/net/ethernet/sfc/ef10.c +++ b/drivers/net/ethernet/sfc/ef10.c @@ -6146,6 +6146,11 @@ static int efx_ef10_mtd_probe(struct efx_nic *efx) n_parts++; } + if (!n_parts) { + kfree(parts); + return 0; + } + rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts)); fail: if (rc) -- 2.35.1