Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp23205pxb; Fri, 15 Jan 2021 04:58:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgJvei6kY1SOb09dzol7QbZ/hVbj6RgDkAlxjcbqvV9uozOMzgi2Jxe05PiKV9hNlA3YZ2 X-Received: by 2002:a17:906:5ad0:: with SMTP id x16mr8674761ejs.135.1610715511088; Fri, 15 Jan 2021 04:58:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610715511; cv=none; d=google.com; s=arc-20160816; b=qaC6bIuSKwVI+Vssf2XLmj4H4E/EWvZHei54lbGCt32lecJTxdiSIG+4rN8awVsBUJ M7eez+Vw0yhXaEMeelG5qM6cyOmzGX0j9j3TA8BWshKgIDiA/e1Gg4gue9asFeRa7sS3 +RrFw+DS/ttzR1me7OQZjRwQjF3W2MwK+YHNn+u3m1vdTKVBOcXy9DCNol00W4UJK31Q GQk7o3CHG9euY4T0PyK5/sXLLAlv+qjCjHGRgMzcM112Wqf0DnCZPaADuIP5dObw2QT8 NzG1VUDN2su1CZgAvdlTrgx23ZOxu1KjIeSXFuaW2mSymCO80MXoHm1GvE3KxVR6hlHX FlgA== 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=yTMvQPLssutlHIBI6UCVPg8T55qb+WOkjVkZgwc84SQ=; b=kmIPcEjnIi9UCy1wUa8vSzdgEC9UWxAQdXar2SFFhZiBbVgFjaFG19uUM6f6l0VSKZ X4vWtpT5IrsFFMnI63BJELKvjgRqXBfUEMWZvhsc8npy0kKCsQYltScPkC5ABiUPWUCa wjpEAZjVORRR6nKf/UeiC8YTJSWF3ecA+QyOearG8LiUaCL6AGlACDZIHLuPq7JzJM7O exf/egOclgYX1MdAGq9M9u1Iop+EAgYaidXnLFiU3Lozc7jmZl3BKrMI5p2UEVbdT2vj cUz1L1PyR8+ce16zJEJul1pfza4vTK4784DPBsOGwwdf2d7AIHKXt1NZrUH0stRyoFTI SPxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DLoIjnRt; 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 v19si3980737edr.303.2021.01.15.04.58.06; Fri, 15 Jan 2021 04:58:31 -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=DLoIjnRt; 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 S2387452AbhAOMeO (ORCPT + 99 others); Fri, 15 Jan 2021 07:34:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:40840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387444AbhAOMeM (ORCPT ); Fri, 15 Jan 2021 07:34:12 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A29C02339D; Fri, 15 Jan 2021 12:33:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610714037; bh=aoInMzShLeeeTg/+4PHS2tDkgza81v84yMhCYK+h/ec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DLoIjnRtjS0DK1B7wOzlWXWUoLaXkUZdZxBiohsD0AZ95c50KzXndvYsAkJXdjVME AWgy1sjRFzsK6exdHbIG2ElLfvMfue2O56h7A5gNBxkdUcL09/UHf4splbs3SHJRi0 07TsUqlHtKMMIfsQwSxKvDyni8zHm9aruQLiEa6U= 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.4 09/62] net/sonic: Fix some resource leaks in error handling paths Date: Fri, 15 Jan 2021 13:27:31 +0100 Message-Id: <20210115121958.849755936@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121958.391610178@linuxfoundation.org> References: <20210115121958.391610178@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 @@ -540,10 +540,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); @@ -618,12 +622,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 @@ -265,11 +265,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);