Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1578687rdb; Thu, 7 Dec 2023 03:18:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjL2qEmOa0gJgbzf6pU4Qf1BvtfTrToos/f7CoCYkk6cZEzYxuHVf2Gva3/0NN4UkndPu5 X-Received: by 2002:a17:902:ea0c:b0:1d0:bfb7:6700 with SMTP id s12-20020a170902ea0c00b001d0bfb76700mr5949709plg.58.1701947933394; Thu, 07 Dec 2023 03:18:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701947933; cv=none; d=google.com; s=arc-20160816; b=P8MCj0vP9yAbZVa5vRrmy9z02NTDI92cdugSDZRqJsm40uEAdH44U1AAdySWz+ERoL mb/7+GPjt6piAGd94YMFcM+ojvRd/X0cz9+gX7KfNLfLA8ufiq/o43i5mQk2keRXENfe Pdi35H/UaR63o2AzFYVfiNgNF3BlsPEwNZRDmHbTTm0CJ7QFt3pJdzclbW7knx6kgrKZ yxsqMYurnzKRviMlUnrBtI2wjEYtMcNLFVvRZiSMGPl/2wGEZ0/mdWLZ+bNoPfyIVVgF RPuCZbCF68IKtgPikkWA4OM9LGgje609USL2+ZRbNknWyyFd0+7QBB1EcRnYqwqf5ZSy fO0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=JtRAp/Zuzq7fGbpcbPcumzgHdraAjC7L39RpTXDHPvw=; fh=lHjl0lo+VCxfCUCSywqgfLTGMFYtiOkf4nqiIgEk1ic=; b=Xm9ky/Hs6wbe/WMzNxr+l298lcPO5CSBJorscDpQ3CI+r5WNxoAvmbGmxf1FHIjCYv EdeTd3oQa85qk/nkM5MWd75tXlD9Jcb73ZiAasvjmgxX82dMHGuG8tbPiYx4IcEnEgJt zJ6vM8cZ9tx4jKVHsEFwZcKo0R5tHUsX4S7qwZlZdROWGEnivCVWybAhSd6SIGARjtVP JPw4QCxTdgcbSEp0KP1NsB+PACu752oUdYk3mtTPYktw8btDp2IhJPnrbv8l15SEJSDC +lB3rfoWLyJurjdXTWI/rie8Q6U8l25Mv1wnPjEneum6sGwA7bOG14BiuiNJlV7qtYvk z20A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cKUQhQTJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id z17-20020a170903019100b001d0ad56d893si957458plg.473.2023.12.07.03.18.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 03:18:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cKUQhQTJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4F9AA8026C36; Thu, 7 Dec 2023 03:18:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378921AbjLGLSd (ORCPT + 99 others); Thu, 7 Dec 2023 06:18:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378884AbjLGLSc (ORCPT ); Thu, 7 Dec 2023 06:18:32 -0500 Received: from mail-vk1-xa2a.google.com (mail-vk1-xa2a.google.com [IPv6:2607:f8b0:4864:20::a2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F520A3 for ; Thu, 7 Dec 2023 03:18:38 -0800 (PST) Received: by mail-vk1-xa2a.google.com with SMTP id 71dfb90a1353d-4b2d64a368aso325774e0c.1 for ; Thu, 07 Dec 2023 03:18:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701947917; x=1702552717; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JtRAp/Zuzq7fGbpcbPcumzgHdraAjC7L39RpTXDHPvw=; b=cKUQhQTJ32lgveuo8CgQWvVy6nSpDP4PuSKt/CDSEvtPirm+8NxIPCfoSFUOcaGXwz PChLiRWSZVcR+VXujHkLVOv/IJd19b2+dcBaL/H1CuCtE1hQrq8t/A5xN/aPkjtdjBIT Y28yV7ByOW9Y3wlREo8j8cilqnD5vCWEH0MOI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701947917; x=1702552717; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JtRAp/Zuzq7fGbpcbPcumzgHdraAjC7L39RpTXDHPvw=; b=ojerlnOSg/fMzKUETBrdNaUQ1RXFP9g8rhjFgKzl3VRpfcxINmYXB0Nu9bvA26x1VG 75meTfWhmKTHW5eWjLfZRB/Oy4rq6S3UgXyyBcP35LJKka2hWW9UT4OaFZ2LmThX3nOP tXsxUobv1+8Ng6kcMYSp1IQNhjvkEvNI3xCR9KaeI8If8wG0nEPHztFsvCwzVG7lEAwQ q3EyamjqhLj4bYgA02maGQHMfnaF7VosKGhaNlj6kFjXxUVWUm5tpMzmUIOMI269oX7a /5p+K4jJmDdC2Ctfp7+bRplh0NqW9Y78VtaQE74NF/wD8Ndo4qiWKRIH1z+SHAH5PmxK sS2A== X-Gm-Message-State: AOJu0Yx2QQDyAyFwUouAIlrb5Sl8r0Z+TSTN1xqh/yBpMvmLiANHB5Hd ng+zqoPMeWtGSwv6FViORxb9MG3u1XQphBu8s+c= X-Received: by 2002:a05:6122:3685:b0:4b2:d8c3:981c with SMTP id ec5-20020a056122368500b004b2d8c3981cmr4442918vkb.1.1701947917254; Thu, 07 Dec 2023 03:18:37 -0800 (PST) Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com. [209.85.221.177]) by smtp.gmail.com with ESMTPSA id x23-20020a056122119700b004b28dec2935sm51321vkn.20.2023.12.07.03.18.35 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Dec 2023 03:18:35 -0800 (PST) Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-4b2ceee07e5so329186e0c.1 for ; Thu, 07 Dec 2023 03:18:35 -0800 (PST) X-Received: by 2002:a1f:c401:0:b0:4b2:c554:ccfd with SMTP id u1-20020a1fc401000000b004b2c554ccfdmr1880286vkf.9.1701947914936; Thu, 07 Dec 2023 03:18:34 -0800 (PST) MIME-Version: 1.0 References: <20231113123049.4117280-1-fshao@chromium.org> <20231113123049.4117280-4-fshao@chromium.org> <6c693161-0e89-4f9d-9a92-18f3783eefd2@collabora.com> In-Reply-To: <6c693161-0e89-4f9d-9a92-18f3783eefd2@collabora.com> From: Fei Shao Date: Thu, 7 Dec 2023 19:17:58 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 3/4] media: mediatek: vcodec: Fix mtk_vcodec_mem_free() error log criteria To: AngeloGioacchino Del Regno Cc: Hans Verkuil , Andrew-CT Chen , Matthias Brugger , Mauro Carvalho Chehab , Nicolas Dufresne , =?UTF-8?B?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 07 Dec 2023 03:18:50 -0800 (PST) Hi Angelo, On Wed, Dec 6, 2023 at 6:19=E2=80=AFPM AngeloGioacchino Del Regno wrote: > > Il 13/11/23 13:26, Fei Shao ha scritto: > > mtk_vcodec_mem_free() shouldn't print error if the target DMA buffer ha= s > > 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 fre= e > > nonzero-size buffer with VA being NULL, which indicates something indee= d > > 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 > > 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; When I made the change, I was thinking of kfree() that doesn't warn against a NULL pointer. I imagine mtk_vcodec_mem_free() calls with NULL VA and mem size 0 probably have the similar nuance (if the buffer exists, free it; never mind otherwise), but I could have missed some important differences specific to the MTK vcodec driver. Looking at the mtk_vcodec_mem_free() usages, almost every one of those checks VA beforehand, but nothing else - they don't warn or do anything special when they encounter a NULL VA, and they should if that's a concern. Some even don't check at all (and I think that's why I ended up seeing the errors mentioned in the cover letter). As for that, I think there's nothing else we can fix except prepending "if (mem->va)". So from all this, I feel perhaps we don't need to worry much about those NULL VA, and we can further remove the checks (or at least move it into mtk_vcodec_mem_free()) to trim the lines in the driver. That's the reason for patch [4/4]. Not sure if that makes sense to you. > - 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->s= ize); > return; > } Sure, I can revise the patch with this, but I also want to make sure if the NULL VA print needs to be an error. If you still think it should, I guess I'll drop the current patch [4/4] and instead add the check before every mtk_vcodec_mem_free() calls. This should also work for the issue I want to address in the first place. And thanks for the review. :) Regards, Fei > Cheers, > Angelo >