From patchwork Wed Jun 14 13:06:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13280028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 96665EB64D9 for ; Wed, 14 Jun 2023 13:07:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Owner; bh=mIVMFxHaTgEzF1/qXQaDLlet6L6XE+T1iQ8eaZLWg6A=; b=tgiWwAgMO4lTvv 6luoqr0aSa0uO+x147t2htbokwddJ8SeaqdZioWukCjkazaXiglY3aCoJSmN1dPK1k7dVaE6uGE7v NtA8eZkV8G1UCRqNkuZ44Fc2z5tDZ8udaYUwLB04dADJGswux89kJzWW46lZsGRMjzJImHMRrlfy9 nYaJZBDKkdBimMr+TJyCgQSAqPqRK5swiTpepU6/r1bs/MvFmqytNzc0o0v1cxuuXXLGA825QVdMp i75vUA6INvhNFVzEPslnTFMnEJ450hRX4Sn3jaMtT+UFJahAQIL2UoTG7ooK9zp6lYXXp2jLhWrue Y05BFecU/6wTUEwfpO4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q9QDJ-00BhnC-09; Wed, 14 Jun 2023 13:07:05 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q9QDF-00Bhkb-2I for linux-arm-kernel@lists.infradead.org; Wed, 14 Jun 2023 13:07:03 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f6283d0d84so8595177e87.1 for ; Wed, 14 Jun 2023 06:06:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686748013; x=1689340013; h=in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=YFfuOxz0aVpxNGfX5VGlWy6rfFH7wm495IfcvMn9LIA=; b=IjZLmnZD83bdyOsNsp6lxqbsqFl1lP2I0hpeUthIyltTZf+t+M9vmPe3Cdv/i29pxX h/bCZSJT21SBsXvv0d4tgcstRLqpx9S8sr+sSgvmt1rkjxqkkcrACVKXIqWqPA/3mw1v sAHcffpzxAw4wIrQdKYzcVZQcZXJzPOidmI+oGR5tlZxGp20gqrmX5wn8VXUIRdHIru7 2VkPTmySQh49bZcleoEzNETQkWlnH6jT0dTJKTPFShNvduawz5hvFh65Qwqxz18O0nZM vwpjG4tR2x1YOVm03LXNe+KTa5LBsGibl/AtYXs22V2xYEiUVCgw2Alr8/5rAGRlloT2 TA+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686748013; x=1689340013; h=in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YFfuOxz0aVpxNGfX5VGlWy6rfFH7wm495IfcvMn9LIA=; b=PlL5gG5JJ3Cn74uPTaBcBNOdQOISNa3MsKO6AZ34/lPtqUL4N4HxF16nCmLmzhrn5F fYOSuMqj0+/FXC+kFgiO/w6vQyi7ce5VIPzgmoN6ZO2CW3Fe28t9Rrz4Bsk+rkrYbV+J S0QzgmfDT/99/RGmGN4HvPOmDlZWfE+sPwQmhKP8UTiKhKs3yn5yLEEhhg+2UtxBO05Z TC1u8fAAx4wjKrVGEoeftBod2ahRGNSvntZU9JXjRrw5dnAalmKw3fPlEbA2K7vUlu7v zbjBNmjJJ/WjjR/ZELJmMmZ40RIugh1SxhStIxtDzkdMtgKHCl7MUKu90rPiz2IzH0Pz eQxw== X-Gm-Message-State: AC+VfDxliW9v8GzLU0npu7L9dOjKwGmGbMvVdZRO4KAE4X93OhYx2sba nUW4HwHheWHz4zYGr8usZdMq3A== X-Google-Smtp-Source: ACHHUZ4+8xYu0TX3myZ8dQQXDqCqdNsFL/Eth3tWWYbfOAZKae4zdc9hxMjPP1fWrusnoL7ln8frLg== X-Received: by 2002:a19:5f19:0:b0:4f6:1433:fca0 with SMTP id t25-20020a195f19000000b004f61433fca0mr4970200lfb.0.1686748012681; Wed, 14 Jun 2023 06:06:52 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id p18-20020a05600c205200b003f74eb308fasm17391390wmg.48.2023.06.14.06.06.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 06:06:51 -0700 (PDT) Date: Wed, 14 Jun 2023 16:06:47 +0300 From: Dan Carpenter To: Yunfei Dong Cc: Tiffany Lin , Andrew-CT Chen , Mauro Carvalho Chehab , Matthias Brugger , AngeloGioacchino Del Regno , Hans Verkuil , Nicolas Dufresne , Xiaoyong Lu , linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel-janitors@vger.kernel.org Subject: [PATCH 2/4] media: mediatek: vcodec: fix resource leaks in vdec_msg_queue_init() Message-ID: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email haha only kidding X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230614_060701_747634_09A3761E X-CRM114-Status: GOOD ( 16.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If we encounter any error in the vdec_msg_queue_init() then we need to set "msg_queue->wdma_addr.size = 0;". Normally, this is done inside the vdec_msg_queue_deinit() function. However, if the first call to allocate &msg_queue->wdma_addr fails, then the vdec_msg_queue_deinit() function is a no-op. For that situation, just set the size to zero explicitly and return. There were two other error paths which did not clean up before returning. Change those error paths to goto mem_alloc_err. Fixes: b199fe46f35c ("media: mtk-vcodec: Add msg queue feature for lat and core architecture") Fixes: 2f5d0aef37c6 ("media: mediatek: vcodec: support stateless AV1 decoder") Signed-off-by: Dan Carpenter Reviewed-by: Nicolas Dufresne --- drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c index 92ac82eb444e..be25d56712d8 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c @@ -307,6 +307,7 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue, err = mtk_vcodec_mem_alloc(ctx, &msg_queue->wdma_addr); if (err) { mtk_v4l2_err("failed to allocate wdma_addr buf"); + msg_queue->wdma_addr.size = 0; return -ENOMEM; } msg_queue->wdma_rptr_addr = msg_queue->wdma_addr.dma_addr; @@ -338,14 +339,14 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue, err = mtk_vcodec_mem_alloc(ctx, &lat_buf->rd_mv_addr); if (err) { mtk_v4l2_err("failed to allocate rd_mv_addr buf[%d]", i); - return -ENOMEM; + goto mem_alloc_err; } lat_buf->tile_addr.size = VDEC_LAT_TILE_SZ; err = mtk_vcodec_mem_alloc(ctx, &lat_buf->tile_addr); if (err) { mtk_v4l2_err("failed to allocate tile_addr buf[%d]", i); - return -ENOMEM; + goto mem_alloc_err; } }