Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp4357782pxb; Sat, 5 Feb 2022 10:55:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4LRoJtV615khVRWzS2YLU4BWtjoUyf3HBBCab1KpUbrG/ghaTUeJeCsxbjvDCG5N1U7U2 X-Received: by 2002:a17:90b:2406:: with SMTP id nr6mr5652956pjb.0.1644087343078; Sat, 05 Feb 2022 10:55:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644087343; cv=none; d=google.com; s=arc-20160816; b=q+OG2vv02gBsvTlFdTd54W3z8K9y9vMw1UCW+8VwB8Ui46QEXpRmwACrjhXJE4GsrH 678EUexBdyC/+4AZrcOB7YUE6kT/gjKOsgS1x91C2ZQ832NRpedK7yt1xSBXM6th7gvj Tky/cYwiDgUMC3ymvObsEN/VMadacVVdZPl6i74qQ/j/r77HVzlvkY2TMnXo1Kuk1lEF v272blq569RuffksOSWH4Ngk3bOoqtKavv6H1CU+/FqJy0GJu/bSdMN1rO9/jJRelepx snRmedqcqN1qzkgRBnAG15Px8kzRUzS5PNOSlzds7HHmf2UN2+yBUln+iRlquiX2YVyu ryuQ== 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; bh=qOZe38VfFY9ednk29+mdXfAWax2XfQ9J0GtuoTKCsNQ=; b=A5T/+XAnuAZ5YoL1HMTxPrFCvUyluJlKgo8+aIT4FHW7anz0uUJV+8xg6dZutAj4zG HSbRVSn1vFloKH1B4E2OkRfMAr4TAs9FFwQY3hSM51w2IpwEy87QXTdHyBmDzs1/vdy0 FVIgBsfJ8CG7itcod6U1RYCJzjLlv1lBeTgbF1X4AH+NJ/Viua/sVGBlMMqtGdEtSSaW X7AAOOpqGWnc1qDfcUOWG0eguxuJDglK07NWEsexydRvAocExyfc6dY+9zVvLn5/9Srs LV79/GOwJzJm8uhoLTj3KZqnGXn7y0R3ePqBvj6Kwco+NR4MwSjqQqZhzocbAHVqUFgW KDXA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h13si5284320pfi.361.2022.02.05.10.55.30; Sat, 05 Feb 2022 10:55:43 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379549AbiBEG6v (ORCPT + 99 others); Sat, 5 Feb 2022 01:58:51 -0500 Received: from smtp06.smtpout.orange.fr ([80.12.242.128]:60623 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379537AbiBEG6t (ORCPT ); Sat, 5 Feb 2022 01:58:49 -0500 Received: from pop-os.home ([90.126.236.122]) by smtp.orange.fr with ESMTPA id GF1yn0ylHIQAdGF1znd3Hp; Sat, 05 Feb 2022 07:58:47 +0100 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sat, 05 Feb 2022 07:58:47 +0100 X-ME-IP: 90.126.236.122 From: Christophe JAILLET To: Sanjay R Mehta , Vinod Koul Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , dmaengine@vger.kernel.org Subject: [PATCH v2] dmaengine: ptdma: Fix the error handling path in pt_core_init() Date: Sat, 5 Feb 2022 07:58:44 +0100 Message-Id: <41a963a35173f89c874f5c44df5530dc09fea8da.1644044244.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to free resources correctly in the error handling path of pt_core_init(), 2 goto's have to be switched. Otherwise, some resources will leak and we will try to release things that have not been allocated yet. Also move a dev_err() to a place where it is more meaningful. Fixes: fa5d823b16a9 ("dmaengine: ptdma: Initial driver for the AMD PTDMA") Signed-off-by: Christophe JAILLET --- v2: update label names move dev_err(dev, "unable to allocate an IRQ\n"); --- drivers/dma/ptdma/ptdma-dev.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/dma/ptdma/ptdma-dev.c b/drivers/dma/ptdma/ptdma-dev.c index 8a6bf291a73f..daafea5bc35d 100644 --- a/drivers/dma/ptdma/ptdma-dev.c +++ b/drivers/dma/ptdma/ptdma-dev.c @@ -207,7 +207,7 @@ int pt_core_init(struct pt_device *pt) if (!cmd_q->qbase) { dev_err(dev, "unable to allocate command queue\n"); ret = -ENOMEM; - goto e_dma_alloc; + goto e_destroy_pool; } cmd_q->qidx = 0; @@ -229,8 +229,10 @@ int pt_core_init(struct pt_device *pt) /* Request an irq */ ret = request_irq(pt->pt_irq, pt_core_irq_handler, 0, dev_name(pt->dev), pt); - if (ret) - goto e_pool; + if (ret) { + dev_err(dev, "unable to allocate an IRQ\n"); + goto e_free_dma; + } /* Update the device registers with queue information. */ cmd_q->qcontrol &= ~CMD_Q_SIZE; @@ -250,21 +252,20 @@ int pt_core_init(struct pt_device *pt) /* Register the DMA engine support */ ret = pt_dmaengine_register(pt); if (ret) - goto e_dmaengine; + goto e_free_irq; /* Set up debugfs entries */ ptdma_debugfs_setup(pt); return 0; -e_dmaengine: +e_free_irq: free_irq(pt->pt_irq, pt); -e_dma_alloc: +e_free_dma: dma_free_coherent(dev, cmd_q->qsize, cmd_q->qbase, cmd_q->qbase_dma); -e_pool: - dev_err(dev, "unable to allocate an IRQ\n"); +e_destroy_pool: dma_pool_destroy(pt->cmd_q.dma_pool); return ret; -- 2.32.0