Re: [PATCH 3/4] media: mediatek: vcodec: Fix mtk_vcodec_mem_free() error log criteria

From: AngeloGioacchino Del Regno
Date: Wed Dec 06 2023 - 05:19:43 EST


Il 13/11/23 13:26, Fei Shao ha scritto:
mtk_vcodec_mem_free() shouldn't print error if the target DMA buffer has
never been allocated or was freed properly in the previous call. That
makes log confusing.

Update the error path to print log only when the caller attempts to free
nonzero-size buffer with VA being NULL, which indicates something indeed
went wrong.

This brings another benefit that the callers no more need to check
mem->va explicitly to avoid the error, which can make the code more
compact and neat.

Signed-off-by: Fei Shao <fshao@xxxxxxxxxxxx>

I think that this error is supposed to catch two issues in one:
- We're called to free no memory (something that does make no sense),
this may happen for example when calling xxx_free() twice, and it
is a mistake that *must* be fixed;
- We're failing to free memory for real (which you covered)

....that said, I think that if you want to clarify the error messages
in this function, it should look something like this:

if (!mem->va) {
mtk_v4l2_err(plat_dev, "%s: Tried to free a NULL VA", __func__);
if (mem->size)
mtk_v4l2_err(plat_dev, "Failed to free %lu bytes", mem->size);
return;
}

Cheers,
Angelo