Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp18232pxb; Fri, 15 Jan 2021 04:49:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxl56L2wPLphdxnIRbDhTNpQU+4fJzzn7su2H7Ri7rpwzsqggqlmthqmYbXFdEqOvyxhMi2 X-Received: by 2002:aa7:cb10:: with SMTP id s16mr9568668edt.304.1610714964199; Fri, 15 Jan 2021 04:49:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610714964; cv=none; d=google.com; s=arc-20160816; b=SiYQyob1MZI5m85oUuMQdyo8UNX/pelUw3G4Dxn6lCDz3LBcrFIbVOFyx+3j2A0Exv nKiLzdBzv9Se2PW6d9vUubj+eexeL4f5MlSmTJE7QlUx5QiCN1SnbbNP3xPvzVLsgEqj RFa99EF3rfH1tDDKvXAXbwGadQgDXdk2AGh8UgJN2cHGEfTH2dIoLbRB9qwBKIh2IzTi aCuRiQUUO6XhhHHG8STTMREg73slgBIywTjbUgejLJALF9Jp80SDkR7y6icbwYKiWxSB wndE2wbXmnURtqyLz8QlQtw+kDJIjYnTDEEBZytvzYELxZ/1aaR0OEgtUOuXi0297/Mf oOCg== 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=5eWsgx6UrbUKiwc1njVGXOqDvk5FVUqwWlc81i78uLA=; b=xPRUIqxKJU/a4NTLVfzyh8NA7+qWt5IScbxPQJ+iVniaGqNBsDxZcl3tbl1Asbb+qx 02EdQDv9UEhj26Hszd6nxHO0uoW7yIaJnpY6XG1HCwH/fa8jEq6Dh/+wpLxOQ/YRj7Ph IHSXE5Kgw7ZVrSxViWzJ+Q7yWwn15OR2AnE5AUnsTmJySH0NVddoUemvb3BCDpJYuV78 XkZQlksRCCd0TlRP9QFb1svVgJw0cg2crkroZIGk6y5xpZSrYVslEqu6PtaKhN9Oz2tE dhDCVnx9kyfVo2eFNneKQ9from562TXkmw/Yng9yz6So7qo7nCmlVhoG/YR8lOdifqgn TbxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RQobqNUn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a25si4267721edn.257.2021.01.15.04.49.00; Fri, 15 Jan 2021 04:49:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RQobqNUn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2388033AbhAOMsY (ORCPT + 99 others); Fri, 15 Jan 2021 07:48:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:44304 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732847AbhAOMhH (ORCPT ); Fri, 15 Jan 2021 07:37:07 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 89E18235F9; Fri, 15 Jan 2021 12:36:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610714187; bh=EdkqPwPfibFnt0IfNrUpnjyVrf/eCJgr+8O75fSZcxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RQobqNUnRWGZJBfOFy5FXw7ElxxvH26odWTsU0Pax0yk2mf3s4w+P5pWJX1spncDe /6W2BEXx8pP9U9F/f2hb1pJyaSFtCrlGlg1Qj334rDmgkmw0LkU8wM1KxTyeScHoHp kn7UHnJ8Oun8my9WMLvPEPxdQmc+7HS5p7l8liuY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET , Thomas Bogendoerfer , Chris Zankel , Finn Thain , "David S. Miller" Subject: [PATCH 5.10 022/103] net/sonic: Fix some resource leaks in error handling paths Date: Fri, 15 Jan 2021 13:27:15 +0100 Message-Id: <20210115122007.122225240@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115122006.047132306@linuxfoundation.org> References: <20210115122006.047132306@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe JAILLET [ Upstream commit 0f7ba7bc46fa0b574ccacf5672991b321e028492 ] A call to dma_alloc_coherent() is wrapped by sonic_alloc_descriptors(). This is correctly freed in the remove function, but not in the error handling path of the probe function. Fix this by adding the missing dma_free_coherent() call. While at it, rename a label in order to be slightly more informative. Cc: Christophe JAILLET Cc: Thomas Bogendoerfer Cc: Chris Zankel Fixes: 74f2a5f0ef64 ("xtensa: Add support for the Sonic Ethernet device for the XT2000 board.") Fixes: efcce839360f ("[PATCH] macsonic/jazzsonic network drivers update") Signed-off-by: Christophe JAILLET Signed-off-by: Finn Thain Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/natsemi/macsonic.c | 12 ++++++++++-- drivers/net/ethernet/natsemi/xtsonic.c | 7 +++++-- 2 files changed, 15 insertions(+), 4 deletions(-) --- a/drivers/net/ethernet/natsemi/macsonic.c +++ b/drivers/net/ethernet/natsemi/macsonic.c @@ -506,10 +506,14 @@ static int mac_sonic_platform_probe(stru err = register_netdev(dev); if (err) - goto out; + goto undo_probe; return 0; +undo_probe: + dma_free_coherent(lp->device, + SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), + lp->descriptors, lp->descriptors_laddr); out: free_netdev(dev); @@ -584,12 +588,16 @@ static int mac_sonic_nubus_probe(struct err = register_netdev(ndev); if (err) - goto out; + goto undo_probe; nubus_set_drvdata(board, ndev); return 0; +undo_probe: + dma_free_coherent(lp->device, + SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), + lp->descriptors, lp->descriptors_laddr); out: free_netdev(ndev); return err; --- a/drivers/net/ethernet/natsemi/xtsonic.c +++ b/drivers/net/ethernet/natsemi/xtsonic.c @@ -229,11 +229,14 @@ int xtsonic_probe(struct platform_device sonic_msg_init(dev); if ((err = register_netdev(dev))) - goto out1; + goto undo_probe1; return 0; -out1: +undo_probe1: + dma_free_coherent(lp->device, + SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), + lp->descriptors, lp->descriptors_laddr); release_region(dev->base_addr, SONIC_MEM_SIZE); out: free_netdev(dev);