From patchwork Thu Sep 12 08:44:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13801739 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72C68EEB568 for ; Thu, 12 Sep 2024 08:46:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=Iwn1or/bBYSNEeUGyuhOfxUWx3sWzISGdpZDtEwQt38=; b=fMqBiyswNFPWt8e7OnWAVFg1QY 4wV2m3meC1Wey9gWeQQ1HS/Q0JEH4F5P+ohjeVFvogtQ+HnFvmhZmC8TwV2e1pwI1de4pXcHEgf9c KTYElBuRi9uZpQ52QrcZFYVOdxkBaCpAHEorVbTSPBmEYmagboc1sy9Mb73dLo7ujoH0VSZvlac/E J3QGWzkWhWC3eG44x9aaeHLBYm2iSuxlC3B9Sv+hPREuNoYmjawH3xkYhj+gd1zP8zohPMwJ2TKLq sWMKJi9iDn5N2uhRpMsMhFRj8dE5oAza3r5oVWM3a7KKVzhmOci+tZb9yJMdUN+J2pz4XZEbpZ5D7 +uDRnccw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sofSs-0000000CQBx-46FK; Thu, 12 Sep 2024 08:46:11 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sofRp-0000000CQ2l-21LW for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 08:45:06 +0000 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-374c4c6cb29so658681f8f.3 for ; Thu, 12 Sep 2024 01:45:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726130704; x=1726735504; darn=lists.infradead.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=Iwn1or/bBYSNEeUGyuhOfxUWx3sWzISGdpZDtEwQt38=; b=YS80CzBHEINzs9TETL4ZEcNzkZsv+LdILhTLORFPcHsT9icj1aE3uCqawyUAVRu5KX JW1+hGNjVe2YkDx55IADD+vToaFArJ4exlLCM8dgROlJo9XuscNH5qWsm8Hs9kl3hikI KHhZ/nC7teuEzvLhkVBc+B1R/JDpuhPSkPFRQrYgoCJ5+HYnpoBWGL/4pbd3b/JAV/2q JQAKTXQ0mgfMPn0WPAH8Q1MbpPtvC1G9WCSZ5QWXXBzEuU4g9ag8ma3lrm7BflfuovGm 5qbM4IdrKDogpQ2KyUz4/OE90Ged08K8XN9CV0CQUQmFMKefC+T0qCsiNeC8tduHLIdL ezZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726130704; x=1726735504; h=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=Iwn1or/bBYSNEeUGyuhOfxUWx3sWzISGdpZDtEwQt38=; b=BMQqJgCwakas6jrztNRAbkAKYZFpsvXGqilnt+nQL58dO4Z5MNCjzom6OyNcMen6b6 MWbJ13fxVQC4LZF74kwgB2ACs08LayQFwAgQvDw20LvZxnSemtkSCHBrrL08rX80b+sP 0PRiwVFDk5dPck6NpiofbFPYwaKpsfVFRZXB/KYE/0sJ5brp7/85OSK8/xW7pcigmYgp B9q5u2ykb2KhBasG7ud1V0ZAYZPezd5tRrGWmhLpRTswAa7PJ9OusF3Kcr7+G3GUCXwt lOsUKT8tKZnmyVCCe7qiWguBTY7BMZjYfaJgods8wmg72anSeslViN22UMO7ickjl7xm DyYA== X-Forwarded-Encrypted: i=1; AJvYcCVyPiOQ4WV2nvyb8XUOXPAnfqAQzRHrXtqsQeJ04/+KeK3HVYwzCiYvTBDbi0K8IsBZd49BIQzD/i7uSmBZyzS1@lists.infradead.org X-Gm-Message-State: AOJu0YxUC08CGjknc9uaWVx4Hb1c0T9L+o9KwTptLol2i+8TNaMOcmje ULCHKW0ENRaqweHbE3fpCDUgcC7KiGRFVSnCuM4QVlgvb42HT/SasGNq8ZYdIM8= X-Google-Smtp-Source: AGHT+IE3jIKp1LsMR7cNfJjwontG8p+Vo7dQ6rcRj2YQpKpztKUglDivYbVOWQlxSgzVuxQlXUEEiQ== X-Received: by 2002:adf:ae51:0:b0:374:c7f8:3d50 with SMTP id ffacd0b85a97d-378c2d588d5mr1389741f8f.58.1726130703593; Thu, 12 Sep 2024 01:45:03 -0700 (PDT) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956de262sm13712489f8f.112.2024.09.12.01.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 01:45:03 -0700 (PDT) Date: Thu, 12 Sep 2024 11:44:59 +0300 From: Dan Carpenter To: Chun-Kuang Hu Cc: Philipp Zabel , David Airlie , Simona Vetter , Matthias Brugger , AngeloGioacchino Del Regno , dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-janitors@vger.kernel.org, Jason-JH Lin =?utf-8?b?KOael+edv+elpSk=?= Subject: [PATCH] drm/mediatek: Fix potential NULL dereference in mtk_crtc_destroy() Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240912_014505_531372_BCF97523 X-CRM114-Status: GOOD ( 14.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In mtk_crtc_create(), if the call to mbox_request_channel() fails then we set the "mtk_crtc->cmdq_client.chan" pointer to NULL. In that situation, we do not call cmdq_pkt_create(). During the cleanup, we need to check if the "mtk_crtc->cmdq_client.chan" is NULL first before calling cmdq_pkt_destroy(). Calling cmdq_pkt_destroy() is unnecessary if we didn't call cmdq_pkt_create() and it will result in a NULL pointer dereference. Fixes: 7627122fd1c0 ("drm/mediatek: Add cmdq_handle in mtk_crtc") Signed-off-by: Dan Carpenter Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: CK Hu --- drivers/gpu/drm/mediatek/mtk_crtc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c index 175b00e5a253..c15013792583 100644 --- a/drivers/gpu/drm/mediatek/mtk_crtc.c +++ b/drivers/gpu/drm/mediatek/mtk_crtc.c @@ -127,9 +127,8 @@ static void mtk_crtc_destroy(struct drm_crtc *crtc) mtk_mutex_put(mtk_crtc->mutex); #if IS_REACHABLE(CONFIG_MTK_CMDQ) - cmdq_pkt_destroy(&mtk_crtc->cmdq_client, &mtk_crtc->cmdq_handle); - if (mtk_crtc->cmdq_client.chan) { + cmdq_pkt_destroy(&mtk_crtc->cmdq_client, &mtk_crtc->cmdq_handle); mbox_free_channel(mtk_crtc->cmdq_client.chan); mtk_crtc->cmdq_client.chan = NULL; }