Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5621634iog; Thu, 23 Jun 2022 01:47:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sjt3SXDRlmjSnwc4u1ESE7A2zGfUL+rcbWVoURppob5A80cBqeDeUp1/PeYQHTf1cNAunG X-Received: by 2002:a17:907:e91:b0:707:c7af:93aa with SMTP id ho17-20020a1709070e9100b00707c7af93aamr7216445ejc.382.1655974042522; Thu, 23 Jun 2022 01:47:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655974042; cv=none; d=google.com; s=arc-20160816; b=ZsdClCDHiDGcKSGPuzZyfIBm7B6TtqbSLDF4EnEHFr3diB6rWjwK2lzAmWIFw0FK6+ rfQ2jn8fKhvZj0phgWS/gKGujhsfAosqAtsCLtR4iYszirxFeNEybQZP46ASkss6RMeN jHCxh3wl7w1jy6VbxKb7btDxx9ZsseancjYWMGzSYupbFvq0upUTNJPOk85BXNn0JAVO otb2D9m+rmSUu8D+iPpcNLJZbpbQcBbEBQJKEYWEs1IIvekkJ3javVl/EtaNR2Le0ETI 6nb5RuuXMK+b2tfQhHc6GIWQlNL6xJnvPncAbyWDJNVpV+Sz7ofrEUC0OJiXeJWZGWAM dfkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=txe4hc1EfWbeYSGTT4JMbZEOKCPz4AUAIB1C5B8xBuY=; b=s7+HZaBTeV0njjue0jdF1grA8sDVHjCtjRkqmbTWsx77AigjCqvTI8b08ul9zfDRiQ agp5EyUOndGYls3YDzOVSnglgaz3bkXo4p0BTAYhjq4Niwgc4nsyQeH4p+XgAH/uOKD8 djUEcE+ZiALMARgcQ85EcdcOxkBGWF+zL/ThRN8dvVYMKMuOPys2g0Ke3XvPELG10I1o k5A/c8/QZO4tGbU1pDuCjdh+qxnu9fz1W7f3xPgZ2787bj0cgfL5Qnvc6qb9GsIQ1HWP 7lsfBzlk0X/aJ5x4HhxL/8nPqILyC6yRT0EajcUC5cLJRWwsFNXtf2JAeRSdPy3/j6Gy CIKw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz30-20020a1709077d9e00b007123ba1f12asi3092505ejc.552.2022.06.23.01.46.57; Thu, 23 Jun 2022 01:47:22 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbiFWIZL (ORCPT + 99 others); Thu, 23 Jun 2022 04:25:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229613AbiFWIZG (ORCPT ); Thu, 23 Jun 2022 04:25:06 -0400 Received: from smtp.smtpout.orange.fr (smtp08.smtpout.orange.fr [80.12.242.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A750488A2 for ; Thu, 23 Jun 2022 01:25:05 -0700 (PDT) Received: from [192.168.1.18] ([90.11.190.129]) by smtp.orange.fr with ESMTPA id 4I96oKg22NUm14I96oB4mn; Thu, 23 Jun 2022 10:25:02 +0200 X-ME-Helo: [192.168.1.18] X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Thu, 23 Jun 2022 10:25:02 +0200 X-ME-IP: 90.11.190.129 Message-ID: <77bdb152-db01-9ad0-fc9f-a8921107a119@wanadoo.fr> Date: Thu, 23 Jun 2022 10:24:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] net: sfp: fix memory leak in sfp_probe() Content-Language: fr To: Jianglei Nie , linux@armlinux.org.uk, andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220623070914.1781700-1-niejianglei2021@163.com> From: Christophe JAILLET In-Reply-To: <20220623070914.1781700-1-niejianglei2021@163.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 Le 23/06/2022 à 09:09, Jianglei Nie a écrit : > sfp_probe() allocates a memory chunk from sfp with sfp_alloc(), when > devm_add_action() fails, sfp is not freed, which leads to a memory leak. > > We should free the sfp with sfp_cleanup() when devm_add_action() fails. > > Signed-off-by: Jianglei Nie > --- > drivers/net/phy/sfp.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c > index 9a5d5a10560f..366a89adabf5 100644 > --- a/drivers/net/phy/sfp.c > +++ b/drivers/net/phy/sfp.c > @@ -2517,8 +2517,10 @@ static int sfp_probe(struct platform_device *pdev) > platform_set_drvdata(pdev, sfp); > > err = devm_add_action(sfp->dev, sfp_cleanup, sfp); > - if (err < 0) > + if (err < 0) { > + sfp_cleanup(sfp); > return err; > + } Hi, or use devm_add_action_or_reset() instead? Just my 2c, CJ > > sff = sfp->type = &sfp_data; >