Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp865013lqo; Fri, 17 May 2024 04:09:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWM7Yr77neBd098uykur2Iw6yxyiwsQJLClLTRKI9gBZDA22ziMV6tIQ4XtC/tmqn2GCFROF5owMA5yZ+khI6OnrDOMswPJ1x8c10iU9A== X-Google-Smtp-Source: AGHT+IFIza3ymxbaxGCdI5b88Dgt0Fgm3IroHUueJLGkeCBdzvbsh99PMJjgl+nWAQqvgfCIddqe X-Received: by 2002:a17:907:1c27:b0:a59:d39a:8d65 with SMTP id a640c23a62f3a-a5a2d5c7738mr1890689166b.21.1715944187500; Fri, 17 May 2024 04:09:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715944187; cv=pass; d=google.com; s=arc-20160816; b=hO0+al6fdVglzLvtoRJsB0ayEvKRILi9I4dOEJnpxZtpxkY0KKgadjBLkz6HWwAy7s yrUGBa7rQzjaNndAq8q7IoGJawhtkiztEdGo+zYRzD9ttoUm07DLTfPFh0Wi9WC8JsAs ceaRbfLS0hVpu3iSSOILg5mDLWDS0LcCMFdUziWY7JU6kWdtgcB6Xo2zteOOjCuilPnV RgRAlVArw+QdAOKXR+PC07lvtgDZuIYRL8FpegvqzVZzfhYr4ShFes/1nPw15i5UR1ad iuem5zzM8iRJNefAXcp6iUweeOb7g9TPsPyw1qdvU2S7rFBAMj21OTlCOepA9VDG3hk/ 5NHw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=NGmgejglMYdTvwgaCUZSdbx7yOC2MMlZ5cIHeZeG2gI=; fh=adgy52BuVJRnZlMIdH9IY9KOQhjAnuL6TA518TEa4hQ=; b=TPIWaGH8w1QBpCBdp53LRatCU+TTH+slenZh8ceFtNns1bmjkiqB62OnrqjO4NBNWR 4DZ0k8gpMQfcaOo+koQAYw6XZY0qMUboPU4VQKVQqeCPanb7g+FQVa6nSgUhbkbo+UU4 1XS+TgiqqQ3cgFIj08KXWCKmzdezEifC2us430FSsnkWMb9omC58scptssWKP8Ap3GRJ oFmqDQVKxQyhYWjsCuREyWIjh0l3ucn6nxcFjbVVBP3z6jRzDxn5P5gW2+guP8AUtsed rEVmlrfyHnkQivy24GV9JBPVENiV+NfiKB/ttrMwzj5ojP8DAV7CTo43kYPbLzQMXBsb Prxg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=yEouNVPc; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-182027-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182027-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-574eb0fe10fsi3795328a12.261.2024.05.17.04.09.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 04:09:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182027-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=yEouNVPc; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-182027-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182027-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 40F771F21D98 for ; Fri, 17 May 2024 11:09:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 599C63BBD7; Fri, 17 May 2024 11:09:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="yEouNVPc" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5850339BC for ; Fri, 17 May 2024 11:09:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715944180; cv=none; b=p1Tpc2jf5XCYSGWLbIghuDpAl0tD3OjdMRtayAJi7di+OsQ6N4hpwDFkof6fuScGmMqD37MUMeYIb+fMkWdoBQyMjQxLp0+gUZcJOSZA80M0w0MX6exolNAqaIQAsP322k/Xf5N2ypU3UegenRwbGBerRCu11OdhQ4J/xMNn3G8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715944180; c=relaxed/simple; bh=OgjgRDVDsrKTTU1Gi1fg62yVJMn/DK0OzAErludZMeo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FZJaQgVzNgaMtxzJlSX7ePCAxqidXyeEg0QU9l8ozVO4f6jyPxepSRyv9yma1mD7mqQ5u2/9gGDk7YtafkTHaYFoQBQep9LuEiAaDN2yS3yy8vWi3FhxULUv5yNxOUcGezje89mlV0ErQsnkn3Vjcn4AUoiOXzJbZ0/gr5IuTW0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=yEouNVPc; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1715944177; bh=OgjgRDVDsrKTTU1Gi1fg62yVJMn/DK0OzAErludZMeo=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=yEouNVPcBZFKAhWQDyw5oCjcE9frfth6/kaO3NGegFTBDMjqZlxXKZaM7dp3Ftyny SJdL8ZjyPCdpMj0Enk9TZWz9SRaZScU10DAWVjnIVNq4m+C+rpU0nTgce99HqppYGW ABR/wmbIaMsk7M3ocu/FSSA50osWG6QBNXWQcdJjMumaUT9eEa0CPY+F7vsHXCwDlS n12gtfhTnmHfhLEvo77DXAzHrn9C+g4LTkfdMTv1rLT7qH0q0a17fHSg4vQoNrZds1 f+gGTJLo8bUHX5u9A2thq+WmbMnuhCkC++SaVrXFZhoYDcX6qoKEskv3a66PqlNGqp qWSZk5JB7BU+w== Received: from [100.113.186.2] (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 6A4313781116; Fri, 17 May 2024 11:09:36 +0000 (UTC) Message-ID: <0d8f89d4-e16e-4c8d-b983-38df8fcc387e@collabora.com> Date: Fri, 17 May 2024 13:09:35 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] drm/mediatek/dp: fix spurious kfree() To: Michael Walle , Chun-Kuang Hu , Philipp Zabel , David Airlie , Daniel Vetter , Matthias Brugger Cc: Jani Nikula , Chen-Yu Tsai , linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20240517093024.1702750-1-mwalle@kernel.org> From: AngeloGioacchino Del Regno Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Il 17/05/24 13:07, Michael Walle ha scritto: > On Fri May 17, 2024 at 12:35 PM CEST, AngeloGioacchino Del Regno wrote: >> Il 17/05/24 11:30, Michael Walle ha scritto: >>> drm_edid_to_sad() might return an error or just zero. If that is the >>> case, we must not free the SADs because there was no allocation in >>> the first place. >>> >>> Fixes: dab12fa8d2bd ("drm/mediatek/dp: fix memory leak on ->get_edid callback audio detection") >>> Signed-off-by: Michael Walle >>> --- >>> drivers/gpu/drm/mediatek/mtk_dp.c | 10 ++++++++-- >>> 1 file changed, 8 insertions(+), 2 deletions(-) >>> >>> diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c >>> index 536366956447..ada12927bbac 100644 >>> --- a/drivers/gpu/drm/mediatek/mtk_dp.c >>> +++ b/drivers/gpu/drm/mediatek/mtk_dp.c >>> @@ -2073,9 +2073,15 @@ static const struct drm_edid *mtk_dp_edid_read(struct drm_bridge *bridge, >>> */ >>> const struct edid *edid = drm_edid_raw(drm_edid); >>> struct cea_sad *sads; >>> + int ret; >>> >>> - audio_caps->sad_count = drm_edid_to_sad(edid, &sads); >>> - kfree(sads); >>> + ret = drm_edid_to_sad(edid, &sads); >>> + /* Ignore any errors */ >>> + if (ret < 0) >>> + ret = 0; >>> + if (ret) >> >> Eh, this will never work, because you're clearing the error before checking >> if there's any error here?!?! :-P > > Don't get what you mean? Yes, I'm ignoring the error. Thus, in case > of an error ret will be zero and there will be no free. If ret was > zero, there won't be a free either. So you're left with the "normal" > case, where you have to free the sads. Just like before. > >> Anyway in reality, it returns -ENOMEM if the allocation was not successful... >> in the event that any future update adds any other error we'd be back with the same >> issue, but I'm not sure how much should we worry about that. >> >> To be extremely safe, we could do... >> >> if (ret != -ENOMEM) >> kfree(sads) >> >> audio_caps->sad_count = ret < 0 ? 0 : ret; > > Which is the same as above, but you only check for ENOMEM? > Yes, the point is to avoid kfree(sads) for -ENOMEM only, as other errors that may be introduced later might still allocate it and leave it allocated. > -michael > >> >> Cheers! >> Angelo >> >>> + kfree(sads); >>> + audio_caps->sad_count = ret; >>> >>> /* >>> * FIXME: This should use connector->display_info.has_audio from >