Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp26145pxb; Fri, 15 Jan 2021 05:02:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPzZqjOAxrzk9QOGO9KKOUsT6qfGJonEMk2TksXaMGAmCyjCZArtAEB9b+Xfc0rTE4NOQs X-Received: by 2002:a50:eb44:: with SMTP id z4mr9205331edp.167.1610715758004; Fri, 15 Jan 2021 05:02:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610715757; cv=none; d=google.com; s=arc-20160816; b=rwHt6MXxmhL5PwesXoQu57Luk+Q51DHWq893DDTaaHVcNu/hBQzumig569bXvud9WH 8KfiqDkqzVJIEPdPNmsbOjLuOaElVZGx9VeVTZSYD9FQiLtklODf2q4GXOqs9whE+LD1 WUKUeUdl92jDixXEOrudFm10QIWshWYw4/PWYScUzgr7k+j/X1Pm8tRHmzC+RMdYuLeU 1nm7o9vE9AA1gWlSz8Hf7jtSh8i1i1/1ojDI0eTIg8JGMR83K3OIwOQQqRVVjd12S5E4 TqLB5ihgj7vLF2LpVWtaZ09ZSRAvU3DxJDLZ7oRGCg0SXoMQmE7rBOmuIUfLufqNqkfK xwUA== 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=XVlIPTeJnk3ZtPUDKQTsWqe7OvA7CP2+1AvIhFIyqQr+gWBIH828Z93+8yP6Mxxq1B mZ+Hsc+26njq5rrW+uW300fRBN2KdXbwH8GSgLPxhtDaZs9HrnQbtOR34ERhCJqAPHLG /lA7phf8wOv39isQSsVIPHatliKadUqcrkwSgsPk8jE4csLnagb628PgiOPnlHViikef n1EHCwYf/BZFE6nEPb7Fp2i74mq316INBfJKwn4tJQIFyPc5kWsTVbsfHKTCWW/u7Wn9 aizbV01b9vRu9BdiYM2mLPCdk6R8fVzOcrV9Blz2gdO4JBi9IHQ1Ls3Rmg9bum45qrRI UKiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sXTwmP2R; 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 u19si2099169edo.333.2021.01.15.05.02.11; Fri, 15 Jan 2021 05:02:37 -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=sXTwmP2R; 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 S1733189AbhAONBq (ORCPT + 99 others); Fri, 15 Jan 2021 08:01:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:39514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731683AbhAOMdA (ORCPT ); Fri, 15 Jan 2021 07:33:00 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 533C92388B; Fri, 15 Jan 2021 12:32:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610713964; bh=aoInMzShLeeeTg/+4PHS2tDkgza81v84yMhCYK+h/ec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sXTwmP2Ru2HT2TwBf2YmrnrsT3t3QHu6cIZBTSYuFIFiPcF+GKgoU5zoLeLPlg12H LEnbWruCCFSsST+7TcwO4ox+4LmFygSocOSN9ijlyy04wKzJ81xaE3wrpfuX8Y7j2+ Fa4uCR7dJ0bySBoXyfJDhDH79hLkDQQVE5JhR2IA= 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 4.19 06/43] net/sonic: Fix some resource leaks in error handling paths Date: Fri, 15 Jan 2021 13:27:36 +0100 Message-Id: <20210115121957.361276182@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121957.037407908@linuxfoundation.org> References: <20210115121957.037407908@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);