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: 92486 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1q9QDC-002K4o-GF; Wed, 14 Jun 2023 13:06:58 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243923AbjFNNG4 (ORCPT + 1 other); Wed, 14 Jun 2023 09:06:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236505AbjFNNGz (ORCPT ); Wed, 14 Jun 2023 09:06:55 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 777AD184 for ; Wed, 14 Jun 2023 06:06:54 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4f642a24568so8591602e87.2 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=JQiy9WP+hZZNMD9fx+n/kZC7/S9cuGC59qr4SfNtq73DZG5X8XhuKUPV6r1zfIGTgX zE7XmKM36Bc3IDMxFCwhVbbUpm9K2WBfEjHguww7OA+DeLnWKI84GBq2BYiAKmVwIemY +8jsVtB9twDkgKRY4CtWD0gNbVD6TA+sCGM7vOc0kEh59NKwk0DGXEv+2ykbK05vglJd uSIov2sQqvouwkstVT9wJ2m0bpoQB0L2VIfdqTzKidI7/7jiI8lw0dL2ERXkwphH2Dse jDVuGak1fmw0650bLtGQNM2UWEUYonGX7ECObrR0m5R9cKrRbPM33xwMiscYKQrYHT3I 9aOQ== X-Gm-Message-State: AC+VfDyvu+YxKpJUYVgTz0IlxsHFvFAOWEyA1/aL+D/ThUWp/pZEMLld WzsuGJlmntWCCa+/+HYywIWMog== 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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-media@vger.kernel.org X-LSpam-Score: -4.8 (----) X-LSpam-Report: No, score=-4.8 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3 autolearn=ham autolearn_force=no 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; } }