From patchwork Thu Dec 21 09:17:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Shao X-Patchwork-Id: 13501487 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF0C030335 for ; Thu, 21 Dec 2023 09:23:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="axiHFoLp" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-28659348677so420110a91.0 for ; Thu, 21 Dec 2023 01:23:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1703150600; x=1703755400; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1lCEYEMR3ZdMjHY32Gwj2vmlAOglAWDLVN2PPmHFWNo=; b=axiHFoLpP1uLHeHBt18NeiX+NxeOrqpvOQjypTCJ3vbwl5A4kZh1wEnlSS6jCQfLw3 WEhy8ewogCyZPXuzrrTfcjCNJ2e4MdTqD0cy5b32YIV/6gZpzj3eSfkyQn4xJ61LRa/v uA52QVlADhODyDe9VMH3a2nc27W4HQsh8QDh0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703150600; x=1703755400; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1lCEYEMR3ZdMjHY32Gwj2vmlAOglAWDLVN2PPmHFWNo=; b=GQpxlULJSXAgHmtpKsdGxtbp719jMPwDfJDsF8FiHhahFun7Qt2qOYGjGkxU16Nx8i vopEUbJ7188ucCUY/G3io++QI/oqbiTraqaCCORQlbl4VjD1ULiBnAXyF34OInRSuW6F PW+7NFrQRh2ykYbPrIUqEK3UqbrTRJUcubOxgBh1hgdE1YugCnMfbQhDU5mUJi4K0oLp YsD7umQ1e/55RaI0Ky6hI3pshU3kNw2ylw+tVWi4kjUyq3B1IIKvJUpjdYYogxzATp/Z yJ3TsgCqZI8j7Tv+3ayk/S3I2DtWIKzS6EgHHSmCbEal0MxHZ1f6kP4lS2TAdaDhp6YC 3TIw== X-Gm-Message-State: AOJu0Yx7XpMFPO1VidKe0fV/BECXlrJTog2ef2dFzGRzYLk/RC0xf6N6 lz4K40abao7m4x69kg/FY4CsCQ== X-Google-Smtp-Source: AGHT+IGJaFa3W8ttJ0cxva573B0FW+Tv1L0wT9eD1Gl2S44RAoKQalXdgX9vfptXkKSVuDVY4wht4g== X-Received: by 2002:a17:90a:fa96:b0:28b:e0cd:64a3 with SMTP id cu22-20020a17090afa9600b0028be0cd64a3mr481792pjb.26.1703150600225; Thu, 21 Dec 2023 01:23:20 -0800 (PST) Received: from fshao-p620.tpe.corp.google.com ([2401:fa00:1:10:5d8a:fab1:933a:9ae9]) by smtp.gmail.com with ESMTPSA id l6-20020a17090add8600b00274b035246esm1001915pjv.1.2023.12.21.01.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:23:19 -0800 (PST) From: Fei Shao To: Hans Verkuil , AngeloGioacchino Del Regno Cc: Fei Shao , Andrew-CT Chen , Matthias Brugger , Mauro Carvalho Chehab , Nicolas Dufresne , Tiffany Lin , Yunfei Dong , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: [PATCH v2 1/4] media: mediatek: vcodec: Replace dev_name in error string Date: Thu, 21 Dec 2023 17:17:43 +0800 Message-ID: <20231221171727.v2.1.I69223f1e438b93fe02f12ab9ef0a26f8c21f6ae7@changeid> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231221092226.1395427-1-fshao@chromium.org> References: <20231221092226.1395427-1-fshao@chromium.org> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 mtk_v4l2_err() already uses dev_err(), so don't print the device name again. Print function name instead. Signed-off-by: Fei Shao Reviewed-by: AngeloGioacchino Del Regno --- Changes in v2: - rebased on top of next-20231219 .../media/platform/mediatek/vcodec/common/mtk_vcodec_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c index 9ce34a3b5ee6..ea8c35c0e667 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c @@ -67,7 +67,7 @@ int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem) mem->va = dma_alloc_coherent(&plat_dev->dev, size, &mem->dma_addr, GFP_KERNEL); if (!mem->va) { mtk_v4l2_err(plat_dev, "%s dma_alloc size=%ld failed!", - dev_name(&plat_dev->dev), size); + __func__, size); return -ENOMEM; } @@ -99,7 +99,7 @@ void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem) if (!mem->va) { mtk_v4l2_err(plat_dev, "%s dma_free size=%ld failed!", - dev_name(&plat_dev->dev), size); + __func__, size); return; } From patchwork Thu Dec 21 09:17:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Shao X-Patchwork-Id: 13501488 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 060883D972 for ; Thu, 21 Dec 2023 09:23:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="iE8aT0QJ" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-5cd8e2988ddso224499a12.3 for ; Thu, 21 Dec 2023 01:23:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1703150603; x=1703755403; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VZlHGzvCeyHzNr9SWDCy3oc9Vlh9aPeReD6PrS2OHo0=; b=iE8aT0QJf95Xjm5HcQeUS1QubIoa57gaRnyRRJYcIaf6kYioB9EuR0DTMJEnxMrJSJ XR2+EC1iNmKOFglQGdcWfdCBB/i5lOoo4UDBJSPe1bJeDTs/ztvh2M+hCWWLFJtxlfjM RDxoHkiyLwwFqfKuwdkxuvJJg4xfFsPOH4JI4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703150603; x=1703755403; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VZlHGzvCeyHzNr9SWDCy3oc9Vlh9aPeReD6PrS2OHo0=; b=QgUUJ6Ue87ASlvUFqRfP8y++pUCJhzR9f5OHI7BSyfaHGlc9/5Wq561BvWvOKHysxn z1AcwW6HjNn2lC7Es3oBlbEIVE4dbk9KuXlOjEqJAbWfFiGB0QiXqdGBX4OW0FZf0ptT N4/nK/lBO1pFXKc38ypPrC8hXET58TOcfh+LsBZh1643xqTAJK+862shp+rO80IfWMko Cf2jZMBVjB7g5RbS+AB9OyI/LPJQ8Nfh+/IpNB/MApHbcs4FOPvX97hrX3/KuaotN3rI bnQulH+yT6DXuqTXoTPubZdTyU4BKz8kOQGiuk3xxYnVfdGktUzQT/YRRIsy8G9Am0T4 LAJw== X-Gm-Message-State: AOJu0YzFrmnyupiJ21YvDjOi/KKO7arAZ3uB5JApxY6tAqESt0MZF3mh iY+lkxMxOTmVcm848hnB9YPoVA== X-Google-Smtp-Source: AGHT+IEZGq7W1pkg/Rs+wEssdN9+RLN+vhyRsmtLnYaT0dUaoqH0eBHPkdGBNx3aVos33wTulXxRXQ== X-Received: by 2002:a05:6a20:8c84:b0:18f:97c:5ba2 with SMTP id k4-20020a056a208c8400b0018f097c5ba2mr518290pzh.112.1703150603432; Thu, 21 Dec 2023 01:23:23 -0800 (PST) Received: from fshao-p620.tpe.corp.google.com ([2401:fa00:1:10:5d8a:fab1:933a:9ae9]) by smtp.gmail.com with ESMTPSA id l6-20020a17090add8600b00274b035246esm1001915pjv.1.2023.12.21.01.23.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:23:22 -0800 (PST) From: Fei Shao To: Hans Verkuil , AngeloGioacchino Del Regno Cc: Fei Shao , Andrew-CT Chen , Matthias Brugger , Mauro Carvalho Chehab , Nicolas Dufresne , Tiffany Lin , Yunfei Dong , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: [PATCH v2 2/4] media: mediatek: vcodec: Drop unnecessary variable Date: Thu, 21 Dec 2023 17:17:44 +0800 Message-ID: <20231221092226.1395427-2-fshao@chromium.org> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231221092226.1395427-1-fshao@chromium.org> References: <20231221092226.1395427-1-fshao@chromium.org> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In mtk_vcodec_mem_alloc() and mtk_vcodec_mem_free(), the value of mem->size is not expected to change before and when using the DMA APIs and debug print, so there's no point in keeping local copies of it. Drop the local variable "size" in the mentioned functions, and update printk format identifiers accordingly. This makes the code slightly more visually consistent, and retrieve a small amount of memory that is used for no real purpose. Signed-off-by: Fei Shao Reviewed-by: AngeloGioacchino Del Regno --- Changes in v2: - revise commit message for clearer intention and rationale .../mediatek/vcodec/common/mtk_vcodec_util.c | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c index ea8c35c0e667..23bea2702c9a 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c @@ -49,7 +49,6 @@ int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem) { enum mtk_instance_type inst_type = *((unsigned int *)priv); struct platform_device *plat_dev; - unsigned long size = mem->size; int id; if (inst_type == MTK_INST_ENCODER) { @@ -64,15 +63,15 @@ int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem) id = dec_ctx->id; } - mem->va = dma_alloc_coherent(&plat_dev->dev, size, &mem->dma_addr, GFP_KERNEL); + mem->va = dma_alloc_coherent(&plat_dev->dev, mem->size, &mem->dma_addr, GFP_KERNEL); if (!mem->va) { - mtk_v4l2_err(plat_dev, "%s dma_alloc size=%ld failed!", - __func__, size); + mtk_v4l2_err(plat_dev, "%s dma_alloc size=0x%zx failed!", + __func__, mem->size); return -ENOMEM; } - mtk_v4l2_debug(plat_dev, 3, "[%d] - va = %p dma = 0x%lx size = 0x%lx", id, mem->va, - (unsigned long)mem->dma_addr, size); + mtk_v4l2_debug(plat_dev, 3, "[%d] - va = %p dma = 0x%lx size = 0x%zx", id, mem->va, + (unsigned long)mem->dma_addr, mem->size); return 0; } @@ -82,7 +81,6 @@ void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem) { enum mtk_instance_type inst_type = *((unsigned int *)priv); struct platform_device *plat_dev; - unsigned long size = mem->size; int id; if (inst_type == MTK_INST_ENCODER) { @@ -98,15 +96,15 @@ void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem) } if (!mem->va) { - mtk_v4l2_err(plat_dev, "%s dma_free size=%ld failed!", - __func__, size); + mtk_v4l2_err(plat_dev, "%s dma_free size=0x%zx failed!", + __func__, mem->size); return; } - mtk_v4l2_debug(plat_dev, 3, "[%d] - va = %p dma = 0x%lx size = 0x%lx", id, mem->va, - (unsigned long)mem->dma_addr, size); + mtk_v4l2_debug(plat_dev, 3, "[%d] - va = %p dma = 0x%lx size = 0x%zx", id, mem->va, + (unsigned long)mem->dma_addr, mem->size); - dma_free_coherent(&plat_dev->dev, size, mem->va, mem->dma_addr); + dma_free_coherent(&plat_dev->dev, mem->size, mem->va, mem->dma_addr); mem->va = NULL; mem->dma_addr = 0; mem->size = 0; From patchwork Thu Dec 21 09:17:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Shao X-Patchwork-Id: 13501489 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B192C446A5 for ; Thu, 21 Dec 2023 09:23:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AtNvv4dn" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6d7609cb6d2so316634b3a.1 for ; Thu, 21 Dec 2023 01:23:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1703150606; x=1703755406; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YpgYqGOhJKgjrH+Y+gow5aHhwckMqDVFEItsLP1DgtE=; b=AtNvv4dnqqqoQIcnxmMRYfV3RJ3eJvizPDs1/uAi0JFwzaDNsM8EFQzMYINH9G3dG6 hpjm4sz4XML+0gm0W6nchdSW2vBCGJNHF43yiP4U8Ku/pXWin7A24q2vSu1ArtgQEzL+ SUci/2oiqF6PqFKK4K3SMkaX5wDCX9+TcfeYg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703150606; x=1703755406; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YpgYqGOhJKgjrH+Y+gow5aHhwckMqDVFEItsLP1DgtE=; b=O35qLQPdqTAIx9DIjaI8zgAWz+5i22ejlrFQudIkp65MhbPnFubu8FoHGnlMd57nlJ T6Xa64fvVFULn3n/SsxQ+fEawcONHYXZBRJI3zbbtX++so+gEd+mQvePrKr1Bh9cfYWf HKSGJSoElGSDnDow+BYeC6/jp5K0e7iIbjns3FMdrAqUKYdXfOAeiYP8vn6+X9nbvZt1 qltJF0z8gLezuyNgRmftc16Yzyr5N+W5YLwku7pATItIEIuFCq37wgMAj2Fx5JDXP5XT nyXHrYbXNTaDieV27UyjkqhrjMz6y2yacRsP2DUA/oK2a3o3+HWCoZUOEZqoa5ELKoBu D+7Q== X-Gm-Message-State: AOJu0YyevnLFh1CCnlXUi6bbuTNw1JhcPdQeyKN0twN+dLPV/n6Fj2p7 F8EsSunYm0fl3m+A5Q/QnqZACQ== X-Google-Smtp-Source: AGHT+IFnrts3BeDUhUkXV+RyB4brmj4RfCUKgv5oiPG6/u9kJt/qtACQnRiXrrJZ8XuzpZM2y2ZDHg== X-Received: by 2002:a05:6a20:2e25:b0:188:1df7:9afe with SMTP id be37-20020a056a202e2500b001881df79afemr560527pzb.30.1703150606111; Thu, 21 Dec 2023 01:23:26 -0800 (PST) Received: from fshao-p620.tpe.corp.google.com ([2401:fa00:1:10:5d8a:fab1:933a:9ae9]) by smtp.gmail.com with ESMTPSA id l6-20020a17090add8600b00274b035246esm1001915pjv.1.2023.12.21.01.23.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:23:25 -0800 (PST) From: Fei Shao To: Hans Verkuil , AngeloGioacchino Del Regno Cc: Fei Shao , Andrew-CT Chen , Matthias Brugger , Mauro Carvalho Chehab , Nicolas Dufresne , Tiffany Lin , Yunfei Dong , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: [PATCH v2 3/4] media: mediatek: vcodec: Update mtk_vcodec_mem_free() error messages Date: Thu, 21 Dec 2023 17:17:45 +0800 Message-ID: <20231221092226.1395427-3-fshao@chromium.org> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231221092226.1395427-1-fshao@chromium.org> References: <20231221092226.1395427-1-fshao@chromium.org> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In mtk_vcodec_mem_free(), there are two cases where a NULL VA is passed: - mem->size == 0: we are called to free no memory. This may happen when we call mtk_vcodec_mem_free() twice or the memory has never been allocated. - mem->size > 0: we are called to free memory but without VA. This means that we failed to free the memory for real. Both cases are not expected to happen, and we want to have clearer error messages to describe which one we just encountered. Update the error messages to include more information for that purpose. Signed-off-by: Fei Shao Reviewed-by: AngeloGioacchino Del Regno --- Changes in v2: - update the error messages based on the suggestion .../media/platform/mediatek/vcodec/common/mtk_vcodec_util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c index 23bea2702c9a..c60e4c193b25 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c @@ -96,8 +96,9 @@ void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem) } if (!mem->va) { - mtk_v4l2_err(plat_dev, "%s dma_free size=0x%zx failed!", - __func__, mem->size); + mtk_v4l2_err(plat_dev, "%s: Tried to free a NULL VA", __func__); + if (mem->size) + mtk_v4l2_err(plat_dev, "Failed to free %zu bytes", mem->size); return; } From patchwork Thu Dec 21 09:17:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Shao X-Patchwork-Id: 13501490 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 618834B144 for ; Thu, 21 Dec 2023 09:23:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jMo0qkLf" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-5cddfe0cb64so237606a12.0 for ; Thu, 21 Dec 2023 01:23:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1703150609; x=1703755409; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VRGqB+rpK2JtTATUiTfsiyokzdHpJCMrcXkOJidY/3Y=; b=jMo0qkLfG7olI5hdqNNW0qUeXBF6d+1PylmgolOoACRMxLiDnURJUzR307WQLREZG5 Ie+uP5FCeL4q2hPE7L/fpYs7PqRX52UmQKSIsAmANKNJdYh/skpIT/40lufs22LJTZeg Uu2r5HvnZ6nks35A+DXGrRJBIX9PmKA2ZDv6g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703150609; x=1703755409; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VRGqB+rpK2JtTATUiTfsiyokzdHpJCMrcXkOJidY/3Y=; b=cGe4T4xc7o3hktp0g4fG3M+IgIIwH8UqvBXOP4d6ToMlrJJW8QpTxW9v4PVuaE1Duj JJXo+5BC4MiWQcE95JmynZUnDy9bqBXYOY0X9J4XHxGPPUZcs7a0EVGxbFoaionJeEsx fq6xXl/4gj+Er68hXjKUtBgIZyBmIRQjT246YzgvbZPWMTdBZk6wUGyHJ6lhcBzzT9xT tnxWN1OZVnNvqIN/wbO2e+6JOH3re2YhmJexD+g3oBeZwSG/mpVoUiEo8dhFkQUnLjqW tbhyFIaoQLXaRLZqMDNMzCohhnNNbxzpcVPtvAqCZf7FAyRwMHV1Ya/qNmxLKqe/F33E RsIQ== X-Gm-Message-State: AOJu0Yz4urlj19LVVHVxg/SMV/Q82koWnc39s1Rl6ZlPlslcQfyU0XpC ewPEQX72Xh9PHbthfBPPwxLAOg== X-Google-Smtp-Source: AGHT+IGFWfj7wEYiXCBut673fAaKAyWsuJBDh1gl52c86wCwAWY5yMXd3rwbFvkIALXsD38i5TLGMw== X-Received: by 2002:a05:6a20:8f1c:b0:190:7b07:b7c9 with SMTP id b28-20020a056a208f1c00b001907b07b7c9mr659230pzk.66.1703150608903; Thu, 21 Dec 2023 01:23:28 -0800 (PST) Received: from fshao-p620.tpe.corp.google.com ([2401:fa00:1:10:5d8a:fab1:933a:9ae9]) by smtp.gmail.com with ESMTPSA id l6-20020a17090add8600b00274b035246esm1001915pjv.1.2023.12.21.01.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:23:28 -0800 (PST) From: Fei Shao To: Hans Verkuil , AngeloGioacchino Del Regno Cc: Fei Shao , Andrew-CT Chen , Matthias Brugger , Mauro Carvalho Chehab , Nicolas Dufresne , Tiffany Lin , Xiaoyong Lu , Yunfei Dong , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: [PATCH v2 4/4] media: mediatek: vcodec: Only free buffer VA that is not NULL Date: Thu, 21 Dec 2023 17:17:46 +0800 Message-ID: <20231221092226.1395427-4-fshao@chromium.org> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231221092226.1395427-1-fshao@chromium.org> References: <20231221092226.1395427-1-fshao@chromium.org> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the MediaTek vcodec driver, while mtk_vcodec_mem_free() is mostly called only when the buffer to free exists, there are some instances that didn't do the check and triggered warnings in practice. We believe those checks were forgotten unintentionally. Add the checks back to fix the warnings. Signed-off-by: Fei Shao Reviewed-by: AngeloGioacchino Del Regno --- I had discussion with Yunfei, and he also thinks that the developers just forgot to wrap mtk_vcodec_mem_free() with the checks back then. We believe it's safe to add those checks. .../vcodec/decoder/vdec/vdec_av1_req_lat_if.c | 22 +++++++++++++------ .../vcodec/encoder/venc/venc_h264_if.c | 5 +++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c index 2b6a5adbc419..b0e2e59f61b5 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c @@ -1023,18 +1023,26 @@ static void vdec_av1_slice_free_working_buffer(struct vdec_av1_slice_instance *i int i; for (i = 0; i < ARRAY_SIZE(instance->mv); i++) - mtk_vcodec_mem_free(ctx, &instance->mv[i]); + if (instance->mv[i].va) + mtk_vcodec_mem_free(ctx, &instance->mv[i]); for (i = 0; i < ARRAY_SIZE(instance->seg); i++) - mtk_vcodec_mem_free(ctx, &instance->seg[i]); + if (instance->seg[i].va) + mtk_vcodec_mem_free(ctx, &instance->seg[i]); for (i = 0; i < ARRAY_SIZE(instance->cdf); i++) - mtk_vcodec_mem_free(ctx, &instance->cdf[i]); + if (instance->cdf[i].va) + mtk_vcodec_mem_free(ctx, &instance->cdf[i]); + - mtk_vcodec_mem_free(ctx, &instance->tile); - mtk_vcodec_mem_free(ctx, &instance->cdf_temp); - mtk_vcodec_mem_free(ctx, &instance->cdf_table); - mtk_vcodec_mem_free(ctx, &instance->iq_table); + if (instance->tile.va) + mtk_vcodec_mem_free(ctx, &instance->tile); + if (instance->cdf_temp.va) + mtk_vcodec_mem_free(ctx, &instance->cdf_temp); + if (instance->cdf_table.va) + mtk_vcodec_mem_free(ctx, &instance->cdf_table); + if (instance->iq_table.va) + mtk_vcodec_mem_free(ctx, &instance->iq_table); instance->level = AV1_RES_NONE; } diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c index a68dac72c4e4..f8145998fcaf 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c @@ -301,11 +301,12 @@ static void h264_enc_free_work_buf(struct venc_h264_inst *inst) * other buffers need to be freed by AP. */ for (i = 0; i < VENC_H264_VPU_WORK_BUF_MAX; i++) { - if (i != VENC_H264_VPU_WORK_BUF_SKIP_FRAME) + if (i != VENC_H264_VPU_WORK_BUF_SKIP_FRAME && inst->work_bufs[i].va) mtk_vcodec_mem_free(inst->ctx, &inst->work_bufs[i]); } - mtk_vcodec_mem_free(inst->ctx, &inst->pps_buf); + if (inst->pps_buf.va) + mtk_vcodec_mem_free(inst->ctx, &inst->pps_buf); } static int h264_enc_alloc_work_buf(struct venc_h264_inst *inst, bool is_34bit)