Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp373288pxj; Fri, 7 May 2021 10:26:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQxpWsgMCIerrbuQzKvzVx13Ud+a7VD9hX6E1St/WJwDR8Z/+5z8FBTbvwWDAuezt3qTNt X-Received: by 2002:a17:906:c788:: with SMTP id cw8mr11038093ejb.190.1620408383940; Fri, 07 May 2021 10:26:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620408383; cv=none; d=google.com; s=arc-20160816; b=0OceLfd9X40CVEFOsYTjjqrYVDKGdwUyTAFfduhGmgT2hzGB9HjzSB2J21RJsgVRlb Bi0/mCRGLRgbdYK7gNLZPFXRffijmtv93B1ISdEXEr/Leqbmy8nVtcXg2tMhHKEDGnpv Ygs8Hw+GttrBDsw8e9/LhghdfoHO5A/O9rLoa57MdKJyA3fNm8iVAYVDnQdGhIU7uxgA /RI6UQOineIcxN8bTyjZ+CkOLFqa5qx8WZdM1U/2grdKF5cPgavCaaHR/mTfUlsvYqNl c01MbnCDWoFWPdOIHueOXMUwmY4nmFMzLWNU+FC6gL1ErUTpQsT5GMGVDAkNCmnyk3gl 7/bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=F4W9uyQV74C7UBU/JNa5oUl0tMDHwnh8qM7k1wloo2A=; b=R2Azya3QRK69nT/8V3HYH+huog3gPUfqKGA/i4DXL+V+wYO+NI4DocNkY96FiFWwZD jfXiAOxabMqbEDrE/RHm+B9zmoI1ucVjSFFDt5zaFylDgNESh7m2QhBD6de0IAuf0qm3 v+JGeJgSHWETJ2g6npD3RU0XbNOrIcv9Pxs2nfZ9kiE+1W+gEGN6CbAEmDJm2eFOWyW7 PqPPJBlkznVAhKUR6hIijv+SR83EdQYPgWxWIgIlJpD9kJvIxI4lItO73d5Ym7Sax2ln QEQT/AA/I1OtpsDXEEM5GluW09GSNz+ms4ZFAAVtvKAPV6eSYLDBT5ra3o0ySa70OWSa XihA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=cYs+hi7O; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=mUuwNNZ3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e19si5425424edz.289.2021.05.07.10.25.57; Fri, 07 May 2021 10:26:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=cYs+hi7O; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=mUuwNNZ3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237791AbhEGPGq (ORCPT + 99 others); Fri, 7 May 2021 11:06:46 -0400 Received: from wnew4-smtp.messagingengine.com ([64.147.123.18]:59797 "EHLO wnew4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237794AbhEGPGp (ORCPT ); Fri, 7 May 2021 11:06:45 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.west.internal (Postfix) with ESMTP id 930A61364; Fri, 7 May 2021 11:05:44 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 07 May 2021 11:05:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=F4W9uyQV74C7U BU/JNa5oUl0tMDHwnh8qM7k1wloo2A=; b=cYs+hi7OxdFCs7OJj+Maak3HSLxvw tK/A0evoO4sTZFXIOxy2YJpoOKTSQ59OqStowlOmLB0Na1UBckxxZT8KVTKsWUkE muYpqB2XTBHpTFeFnWXNxcUzuKRjOmsomfnrg7aFFSY/auwbaqlDSq3LLvsVuGWx iKShfRXTWbrVGWBemx21YhP3sdMcz63LPwJvCgwliScOfMjNWe8L1+PCQ+FikjUD H3cmkYU5cQvgNlUv4hGkVPTUseqbMaRHyXylx8NHc9U8KIqnZNTaZqfKhlV/jPb5 s5G+wbhyIZ8FWTI/RqGtKC1TjdmlglmP6yvc8PU2sJYrqKq6yHR/DOsXA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=F4W9uyQV74C7UBU/JNa5oUl0tMDHwnh8qM7k1wloo2A=; b=mUuwNNZ3 j3VtSowW+/tNIwWG4YjJwfUlMCmKJ4qoJ7SnPCaIgoUE3XgnvDRyaH8/jgfhHu69 tnXfyeXYrX7Qvgg0exuNuHTk5xk4cjWMKWsV0UMl2IEjLWbLIVv4T8WfjZwjimso cqezj2C1ixGQNrkHqxqiNj9rQXjhOBoAyBWk0PGEn2xK+7QEBi048bXO8Nwfa9Kk zj12ndhzJARxfhprXFQ81l/IFhBXB6Sm+8ZM5DCoo05KZHkcI+fb73JHaTCAggx7 P07kyQfbANCxCkp+py6DakjdFQjn/Pj812pKjCJWzBza/gT80VkER2algX3bEYFf AHPspGcviLe4lg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdegvddgkeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepvdekleevfeffkeejhfffueelteelfeduieefheduudfggffhhfffheevveeh hedvnecukfhppeeltddrkeelrdeikedrjeeinecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Received: from localhost (lfbn-tou-1-1502-76.w90-89.abo.wanadoo.fr [90.89.68.76]) by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 May 2021 11:05:41 -0400 (EDT) From: Maxime Ripard To: Maarten Lankhorst , Thomas Zimmermann , Maxime Ripard , dri-devel@lists.freedesktop.org, Daniel Vetter , David Airlie Cc: Eric Anholt , Nicolas Saenz Julienne , bcm-kernel-feedback-list@broadcom.com, linux-rpi-kernel@lists.infradead.org, Dave Stevenson , Phil Elwell , Tim Gover , Dom Cobley , linux-kernel@vger.kernel.org Subject: [PATCH v4 04/12] drm/vc4: crtc: Fix vc4_get_crtc_encoder logic Date: Fri, 7 May 2021 17:05:07 +0200 Message-Id: <20210507150515.257424-5-maxime@cerno.tech> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507150515.257424-1-maxime@cerno.tech> References: <20210507150515.257424-1-maxime@cerno.tech> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The vc4_get_crtc_encoder function currently only works when the connector->state->crtc pointer is set, which is only true when the connector is currently enabled. However, we use it as part of the disable path as well, and our lookup will fail in that case, resulting in it returning a null pointer we can't act on. We can access the connector that used to be connected to that crtc though using the old connector state in the disable path. Since we want to support both the enable and disable path, we can support it by passing the state accessor variant as a function pointer, together with the atomic state. Fixes: 792c3132bc1b ("drm/vc4: encoder: Add finer-grained encoder callbacks") Signed-off-by: Maxime Ripard --- drivers/gpu/drm/vc4/vc4_crtc.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_crtc.c b/drivers/gpu/drm/vc4/vc4_crtc.c index 8a19d6c76605..36ea684a349b 100644 --- a/drivers/gpu/drm/vc4/vc4_crtc.c +++ b/drivers/gpu/drm/vc4/vc4_crtc.c @@ -262,14 +262,22 @@ static u32 vc4_crtc_get_fifo_full_level_bits(struct vc4_crtc *vc4_crtc, * allows drivers to push pixels to more than one encoder from the * same CRTC. */ -static struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc) +static struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc, + struct drm_atomic_state *state, + struct drm_connector_state *(*get_state)(struct drm_atomic_state *state, + struct drm_connector *connector)) { struct drm_connector *connector; struct drm_connector_list_iter conn_iter; drm_connector_list_iter_begin(crtc->dev, &conn_iter); drm_for_each_connector_iter(connector, &conn_iter) { - if (connector->state->crtc == crtc) { + struct drm_connector_state *conn_state = get_state(state, connector); + + if (!conn_state) + continue; + + if (conn_state->crtc == crtc) { drm_connector_list_iter_end(&conn_iter); return connector->encoder; } @@ -292,7 +300,8 @@ static void vc4_crtc_config_pv(struct drm_crtc *crtc, struct drm_atomic_state *s { struct drm_device *dev = crtc->dev; struct vc4_dev *vc4 = to_vc4_dev(dev); - struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc); + struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc, state, + drm_atomic_get_new_connector_state); struct vc4_encoder *vc4_encoder = to_vc4_encoder(encoder); struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc); const struct vc4_pv_data *pv_data = vc4_crtc_to_vc4_pv_data(vc4_crtc); @@ -407,7 +416,8 @@ static int vc4_crtc_disable(struct drm_crtc *crtc, struct drm_atomic_state *state, unsigned int channel) { - struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc); + struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc, state, + drm_atomic_get_old_connector_state); struct vc4_encoder *vc4_encoder = to_vc4_encoder(encoder); struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc); struct drm_device *dev = crtc->dev; @@ -507,7 +517,8 @@ static void vc4_crtc_atomic_enable(struct drm_crtc *crtc, { struct drm_device *dev = crtc->dev; struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc); - struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc); + struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc, state, + drm_atomic_get_new_connector_state); struct vc4_encoder *vc4_encoder = to_vc4_encoder(encoder); require_hvs_enabled(dev); -- 2.31.1