From patchwork Wed Sep 20 08:27:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 142287 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3975045vqi; Wed, 20 Sep 2023 01:41:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEX/O4oXJyNZtAW75JffXBOl/X4a4JP0hmjjOQCivtrObjjKcQZ1hWIDTEfBTuib5g4FroJ X-Received: by 2002:a05:6871:286:b0:1be:f7d9:c0e2 with SMTP id i6-20020a056871028600b001bef7d9c0e2mr2219220oae.38.1695199302116; Wed, 20 Sep 2023 01:41:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695199302; cv=none; d=google.com; s=arc-20160816; b=S7/y6oUddNHwPYBI2R9tLRKqZqIT2qUpcaOA8pFl2Qbzt1FSouRAcJbc8kniK5q4CA JLSCmzyiQnoixFvUAtwdj9j23iLMwEiWPZvQjjDJJ8P4zR8fHFayGoShJPxUcnpbDz+Z ID4LPr+ykKssoRwYXydIVsp48X7s6R9dX+y3mpTJmTXiFcD2a4BbrdkFfxNYGX6/CIU/ YqBdWj3V+CfSIMkFFeNir2T7hrSnIR/nPLVbtIl4gH/dsDVITMeIvMTPZJLgT1/cSIbt dzyRaOFL8E1Mv4eoQXxVKopUWUbXUb3veMu7VnRsAmANm+Qx4eBADPkh9FCEdF8iTIms yH+A== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=J1UBXJLFcuzq6xKWI0bHPtDV3CXBWcfEshCnek2kuXw=; fh=l/zbhNQBbrfL3t9omnT691ovxrfEGzSTAk1OAVwp8vQ=; b=i8JZewjEDGXiUOTdrPHdqoBURszd9ob+rdRIb55/vefQuqw2IHPm6XrzbCceCbzb4V xaPjEToNsyMBhTd5/qaDSeY2WuMwcKqIlAftf2AiFLXPOOHpjwg31PzH8lnWgDYsIG58 y92hCzAhhLoMqD0plHszQYFdW4laRtRmSkjY+ydVLPv8gQwrbvbe7d0FSM4M+wGrYFpx I1dHo+8ICeNvxfoYag63XA/XWZvwzJPSDH9HGi+c8sih1cxI/V+lfbyxyRMgaWUTGwq3 HdBgcQ37Q90+vVy7TERhG9iXxwuC++RKpvKyxalyH+4fMM9qUNzZxxKdoQ+y1n9YBQcQ RNNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lV+NRHy9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id z37-20020a631925000000b00573f7d09445si11197831pgl.330.2023.09.20.01.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 01:41:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lV+NRHy9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 7EFA680BE86C; Wed, 20 Sep 2023 01:28:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232509AbjITI1w (ORCPT + 26 others); Wed, 20 Sep 2023 04:27:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjITI1v (ORCPT ); Wed, 20 Sep 2023 04:27:51 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 697F790 for ; Wed, 20 Sep 2023 01:27:45 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 4BEBF66003AF; Wed, 20 Sep 2023 09:27:43 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1695198464; bh=DbWGcn6zI7FsJFEu+IPzpjZSXjvXMMCEXJn4aXMt218=; h=From:To:Cc:Subject:Date:From; b=lV+NRHy9R1DzJrhNmu1OqK8DVNExlmtN2Vphj8vkfm0JReVuaE7FnjRtc426NmVX+ SdgJ+NECW6+yMTwVSZSsxZ8L6CR7B9Gl5VpQXzEJVJnLlKZJUTVZQNOhJeIrOLV49j rM8tmDngAf9gWgQRNHQhc+yHVrrzPiJfkTAEEmM/Mq9v2BbVEnnA64THsYqIb2noPd UfFVxgJbixYUadcOwmP1mZZd2ROlztvXAG459sgYKS1Bpf7Aa11vIl9c4Lm0h1d2gn 7IIKSvRXMJ03nsbgTA1xRBZuPtJKfgoLWQhrYw19K6ARmQ4ASh3CwYA5CxVWpOOz9h WA+Nvw+IC9uBA== From: AngeloGioacchino Del Regno To: andrzej.hajda@intel.com Cc: neil.armstrong@linaro.org, rfoss@kernel.org, Laurent.pinchart@ideasonboard.com, jonas@kwiboo.se, jernej.skrabec@gmail.com, airlied@gmail.com, daniel@ffwll.ch, ulf.hansson@linaro.org, victor.liu@nxp.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, ehristev@collabora.com, wenst@chromium.org, AngeloGioacchino Del Regno Subject: [PATCH v2] drm/bridge: panel: Fix device link for DRM_BRIDGE_ATTACH_NO_CONNECTOR Date: Wed, 20 Sep 2023 10:27:27 +0200 Message-ID: <20230920082727.57729-1-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Wed, 20 Sep 2023 01:28:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777545303046018620 X-GMAIL-MSGID: 1777545303046018620 When external bridges are attached with DRM_BRIDGE_ATTACH_NO_CONNECTOR, the panel bridge may also get the same flag, but in the .attach() callback for the panel bridge a device link is added only when this flag is not present; To make things worse, the .detach() callback tries to delete the device link unconditionally and without checking if it was created in the first place, crashing the kernel with a NULL pointer kernel panic upon calling panel_bridge_detach(). Fix that by moving the device_link_add() call before checking if the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag is present. Fixes: 199cf07ebd2b ("drm/bridge: panel: Add a device link between drm device and panel device") Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Liu Ying --- Changes in v2: - Added device_link_del() for (!bridge->encoder) error condition drivers/gpu/drm/bridge/panel.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/bridge/panel.c b/drivers/gpu/drm/bridge/panel.c index e00d2e94c751..e48823a4f1ed 100644 --- a/drivers/gpu/drm/bridge/panel.c +++ b/drivers/gpu/drm/bridge/panel.c @@ -67,14 +67,6 @@ static int panel_bridge_attach(struct drm_bridge *bridge, struct drm_device *drm_dev = bridge->dev; int ret; - if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) - return 0; - - if (!bridge->encoder) { - DRM_ERROR("Missing encoder\n"); - return -ENODEV; - } - panel_bridge->link = device_link_add(drm_dev->dev, panel->dev, DL_FLAG_STATELESS); if (!panel_bridge->link) { @@ -83,6 +75,15 @@ static int panel_bridge_attach(struct drm_bridge *bridge, return -EINVAL; } + if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) + return 0; + + if (!bridge->encoder) { + DRM_ERROR("Missing encoder\n"); + device_link_del(panel_bridge->link); + return -ENODEV; + } + drm_connector_helper_add(connector, &panel_bridge_connector_helper_funcs);