Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4450055imw; Tue, 19 Jul 2022 06:53:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vkVZPMt3RhO+trAdC9M8ONrCmV67+Kyz8Bh8jA7AKTSdrd9j47LeGIOlKe/nLoy9PhQe2R X-Received: by 2002:a05:6871:714:b0:10d:78d9:314e with SMTP id f20-20020a056871071400b0010d78d9314emr623514oap.117.1658238799374; Tue, 19 Jul 2022 06:53:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238799; cv=none; d=google.com; s=arc-20160816; b=XVsf0vnj1rFp0ie7QCqLmJ0Y/sHCX7IweWGo/kkK+wJEeBa+fvAgPSGCY9qs7Qj5sv SN54sBYemqNtYeNvBMhPUaAqdOD/QbkjN4sWGLKsOfuYqYTSTPJaSng650WsgSssu80E b6P1a6g3IkYfq2CVCg1eIufLBNsPLdabfUkRoilMRmNDnNU0lVQgBFqy5dj3OG183x6m sduBfc/FPk5BVeWFh3n28FJ61rlmB1xlVK0G4YVqMyG8lSXLX4minRSPILB9tEJRl5C3 i4UQaWVNyXgffShL6QmhKptZw+Vsx2lDb6C6labiin/hdZfdezRFMCThfgTprKeAgwlx /OIw== 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=dt2BDG6uDL5ppKrJg56Ok+PwRgMYyMPCKdQ4uoriQdE=; b=qAClnTUixXrr7JM3AdV6sZ/QlF6BCJExR7+oy7ziEyh9dua7jpRLKWxMrPd9EdSJx7 wzpD/My6Zzpe/6nO+m89BpvV2Yp5CgkLjD1X48OZkgN1dvlwDx78cAbq3UNaSwjA+bck vFt5IphM5eeRP8xeMYGkk0y4lhq4vX4K25PBGcUn9tQfb4KdyxSXgx1U1p0pDAO3yGqO XWzdQHsykgCMDy8wxZGk2amI/PppUxMEIKAxIM8dXKfd/pG8CVvJqmfGGeDlHAvrnV4z iibtUxTY0EmNDAC8KFGG7FI/cQ7dPHNcGKW4ID0imy6CoEgmFUAunEIQWr8cJrbwmlTq xIQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vW4eiqYD; 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 bj21-20020a056808199500b00339f16b29d6si7958019oib.146.2022.07.19.06.53.06; Tue, 19 Jul 2022 06:53:19 -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=vW4eiqYD; 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 S237906AbiGSMBb (ORCPT + 99 others); Tue, 19 Jul 2022 08:01:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237794AbiGSMAx (ORCPT ); Tue, 19 Jul 2022 08:00:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D6B245F5F; Tue, 19 Jul 2022 04:58:15 -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 ams.source.kernel.org (Postfix) with ESMTPS id 0ED5CB81B2C; Tue, 19 Jul 2022 11:58:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C2BFC385A5; Tue, 19 Jul 2022 11:58:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658231892; bh=SIc6DlfuX0l6uonIbPt33V4X9eiPE/u2ceNGgrYJ224=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vW4eiqYDwm6OWaVdWoalpLJbLUuwp0zx+4o3TAMalwzRWFXfwkwETbDneFq8/CWp0 4jOeyYWbu6JK+nZnBe4XVO7SA/4pY4Rs1cKyIO0mXSavIoSQoeGi0qOj252MR1a8tc My4Z52tq84YolGyIvDxE/gtyAFpr1KXuhVxjDkvk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianglei Nie , "Russell King (Oracle)" , Paolo Abeni , Sasha Levin Subject: [PATCH 4.14 32/43] net: sfp: fix memory leak in sfp_probe() Date: Tue, 19 Jul 2022 13:54:03 +0200 Message-Id: <20220719114524.759310436@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114521.868169025@linuxfoundation.org> References: <20220719114521.868169025@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.8 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 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: Jianglei Nie [ Upstream commit 0a18d802d65cf662644fd1d369c86d84a5630652 ] 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 Reviewed-by: Russell King (Oracle) Link: https://lore.kernel.org/r/20220629075550.2152003-1-niejianglei2021@163.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- 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 9f6e737d9fc9..c0f9de3be217 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -830,7 +830,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.35.1