Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp374317iog; Wed, 29 Jun 2022 01:55:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1safXQ00tDQ6yzuZkCMj193BOrgzQufMlUNoODH8kYPDnsNmhM/uF1EI1ysJlTXuEqSxr2G X-Received: by 2002:a63:af59:0:b0:40c:a49e:7104 with SMTP id s25-20020a63af59000000b0040ca49e7104mr2134576pgo.279.1656492930179; Wed, 29 Jun 2022 01:55:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656492930; cv=none; d=google.com; s=arc-20160816; b=Y/9VWcinHPXyRmrvEX1ovYuzwIhvHyXNWaOgl6j79d5XWvcAaLGv9O6dx8y0vxVwgT uTprjcz0NLQEQ4CItYhzLLvwh32kNcSTjmKwyb4Fa0vdBw0tvwIpx7ftJ2mVpiw+pCo1 FlACt6w9c0AyuLZUxqp6a5QQ+lMnPvLNMtsjDCePYN+DM1pQ8RaGkWD0ztZ81ePWCY4O c+sopwGT63w894FFQDrpvfU0c5wf1Z9M36icGNKeI599Q6W+UL8XB14HyTZHKDRLT+z1 ojWujI+lhC3SP7L2wna0ndiM7dnIKO3Wk6ZO4G7iXl8MGN884yxw0/XP5Yh8kXvHU3Pi dPeQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Tb64Pu0w0mNUC4InDOg/CyJ1ovpbrmbwN790T5bKgDo=; b=X2Eq2Va25uS20cPmlyAF99v5qJzHB5m34iORrLn6D2tq2JM2dsb8NJNOZRrZAXNIeM 5LGvoLopifHpPxPizVxFOqZhKcx2Q3900+rj3jftzLal2c9LRVZ585P6l2uhPZ6y1UVk 0xUJpvaUkvLzbOXyttsn6HS/6frfuGjgyDnpHM8WudY/9w2/TdiZXusFChvAuqCS2r00 Vrq5XSKe2bRys1W+nkpfHsBe4PA04LduWyjccN8IezIHSuruQ125wk2ajhVu+5skwuxZ NUraktJP0gjDjtBg4zcJTRod2iNuZsYPnN5sj3TZ9Y2U1raBaLuPDL1kcYhyoZDNEzw1 bc0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="jBo16B/k"; 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=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z10-20020a170902d54a00b0016b95376f5dsi4133335plf.242.2022.06.29.01.55.18; Wed, 29 Jun 2022 01:55:30 -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=@163.com header.s=s110527 header.b="jBo16B/k"; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232592AbiF2H4x (ORCPT + 99 others); Wed, 29 Jun 2022 03:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231629AbiF2H4w (ORCPT ); Wed, 29 Jun 2022 03:56:52 -0400 Received: from mail-m973.mail.163.com (mail-m973.mail.163.com [123.126.97.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3BFDE6320; Wed, 29 Jun 2022 00:56:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=Tb64P u0w0mNUC4InDOg/CyJ1ovpbrmbwN790T5bKgDo=; b=jBo16B/kF1Q1pt/MhER+C Fsarx5m+aA4dmrOCB3nawqMQb5dT2AEP0zy0bg3aCfvttWzq/RC94vLBql3uBdXA cDVxer/fDi/pQZgaFS7pkwlgEfOkOQpKFcHwaUR6uM3C0VSIA+/i6O/qfjUTdwhF amjrKv4+xltyAAp6qjhrG4= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp3 (Coremail) with SMTP id G9xpCgDHO22HBbxiTOHrMQ--.37830S4; Wed, 29 Jun 2022 15:56:00 +0800 (CST) From: Jianglei Nie To: 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, Jianglei Nie Subject: [PATCH net v3] net: sfp: fix memory leak in sfp_probe() Date: Wed, 29 Jun 2022 15:55:50 +0800 Message-Id: <20220629075550.2152003-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: G9xpCgDHO22HBbxiTOHrMQ--.37830S4 X-Coremail-Antispam: 1Uf129KBjvdXoWrKr1fJr1UXFyftw4fJrW7XFb_yoW3urb_CF 47XF4fGryUCr4qqw15K34SvrWS9Fy8ZFs5CF1fK3yagFy3Gws8u3yvvF47Jr1UWrW2vr4U uF9rZFsa9r1fKjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xREsqXtUUUUU== X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/xtbB0RAvjFzIBp5wLQAAsz X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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 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 use devm_add_action_or_reset() instead of devm_add_action(). Signed-off-by: Jianglei Nie --- drivers/net/phy/sfp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 9a5d5a10560f..e7b0e12cc75b 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -2516,7 +2516,7 @@ static int sfp_probe(struct platform_device *pdev) platform_set_drvdata(pdev, sfp); - err = devm_add_action(sfp->dev, sfp_cleanup, sfp); + err = devm_add_action_or_reset(sfp->dev, sfp_cleanup, sfp); if (err < 0) return err; -- 2.25.1