Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4435173pxb; Mon, 21 Feb 2022 21:31:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxV4SulWjNIB42LIetVIogjq85U4emP6jvm2Mestk7nzfw14B9IAeJU4hROvlVCsbv73Bz2 X-Received: by 2002:aa7:8f33:0:b0:4cb:95a7:928c with SMTP id y19-20020aa78f33000000b004cb95a7928cmr23200430pfr.42.1645507919443; Mon, 21 Feb 2022 21:31:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645507919; cv=none; d=google.com; s=arc-20160816; b=FhHEHq7jDg6ze2D6QzlRUDVVKWUD9PJEPgunz20NoVn/is6uIogvkrPDglQFCyAPCX Eam/wp/arJvLt6XkZrTvC2OJp1zsiZRdgvVm6Du1IHPhjDSPqBTqXhIGfTrzJKbSy0MN MP+mZjH78kG3NVEerfYpqIVnTnNmY4AmQxmTkvuSkGfTOXNK/JFoxJaYcrcBwPnGHKgB xnJPt2RVkNYWQGWVn2hEvWUYk/ZYEuDUGV9ZDSSmKNJWYDJrDtVwvw9lSVftLk+626E+ gQvNNCuHLRUHKvKlZpuDelwyYhzU5PIEro0rUqVxfYlMuJ9znOy0JjANvu+O7rOfLqhl pWsA== 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=Ec6iF8HpzmWM2jIt5yNQOZ0Cbl0PXNvZYbOACxdTpns=; b=rhkE4pGbocawmDdEjhwBAiQD2jRIQ6eAHNKev6FtFd9SaVtFwlOop4uLZ/W0WDnptr 0gJy+O94wr4EU5P4iSLXD5NNAkm/zX/m0/Ndk13KpcSlYitSAfAB/5kED2zeksS7w5C+ /9K8oD30dWnQsn6jJ3nAyai2slPG4HKNP3Dlf+qVtqk8Lvbppon7V2pYgXYKZssDuaSa oeRtScnyRpZKWJUuldrDpLrZr3byNBlVe/sngB6clDNRKE0WV3U7oANeG5axH27MY3iv J9tNqhRHAqI1egshrw134JzNyaQfiSShQKUhq8cq5e0LRteTTE/MYlNPZKgnijb1vh1d HurQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z1gAxmVC; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id e12si8255485plx.0.2022.02.21.21.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:31:59 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z1gAxmVC; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7AE3411109B; Mon, 21 Feb 2022 21:00:14 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353729AbiBUKL2 (ORCPT + 99 others); Mon, 21 Feb 2022 05:11:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353504AbiBUJ53 (ORCPT ); Mon, 21 Feb 2022 04:57:29 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 231D1F20; Mon, 21 Feb 2022 01:26:34 -0800 (PST) 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 CB9C0B80EB9; Mon, 21 Feb 2022 09:26:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00ECDC340E9; Mon, 21 Feb 2022 09:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435591; bh=3klJNZS5cTv0/+dhcZrqlbPKPKUl1hoZQNAt892OVZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z1gAxmVCQiWhvSx9MtGMjMfX6GJFWy97nKK0P677n3QlCw9dwvs+Nt1gWnOksFl/M tXzO6TyKhsiQt7EbXOhPoNHU6X8r/ScVtqW/CzNvxNxggGtA4Of5/nw7q4tQ1rpf4l p2LQg9/NsqWYYZ2KNb/X0ba0Ef3H9mhh44Z+nb4U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET , Sanjay R Mehta , Dan Carpenter , Vinod Koul Subject: [PATCH 5.16 185/227] dmaengine: ptdma: Fix the error handling path in pt_core_init() Date: Mon, 21 Feb 2022 09:50:04 +0100 Message-Id: <20220221084940.967470358@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Christophe JAILLET commit 3c62fd3406e0b2277c76a6984d3979c7f3f1d129 upstream. 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 Acked-by: Sanjay R Mehta Reviewed-by: Dan Carpenter Link: https://lore.kernel.org/r/41a963a35173f89c874f5c44df5530dc09fea8da.1644044244.git.christophe.jaillet@wanadoo.fr Signed-off-by: Vinod Koul Signed-off-by: Greg Kroah-Hartman --- drivers/dma/ptdma/ptdma-dev.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) --- 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;