| Message ID | 20230123151212.269082-3-jagan@amarulasolutions.com |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-amarula+bncBD7MFH7A7EEBB3WHXKPAMGQEKRTVP7Y@amarulasolutions.com> X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 19B413F046 for <linux-amarula@patchwork.amarulasolutions.com>; Mon, 23 Jan 2023 16:12:48 +0100 (CET) Received: by mail-pf1-f200.google.com with SMTP id dc11-20020a056a0035cb00b00589a6a97519sf5366779pfb.8 for <linux-amarula@patchwork.amarulasolutions.com>; Mon, 23 Jan 2023 07:12:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674486766; cv=pass; d=google.com; s=arc-20160816; b=TWM9FdX5DH1HTjP2C3l9rTmV0UoHD/dcRN2MW7q1EP4dL7qlFT8T2l0H0Tu+6Dqsxs drd/gbnfMRpcYlZQa6w9zCv6pBvDmP/dud6BiscJtJY7GGW5HW9/QDpFYthUPVvzX5VD C9pZDSFGGrIm6zYGvGGJh5uL6ufzG0j2R3CnKKkVnZFp73i0gOfkMI/c+ELlBnuyuetK eOYVvvoEMruLIlNYpxcOIDMW013jH8AWl7e6lvJos5OKroo16F0+UIowoUVcac2nWPMR cfPnbmrKtijJMqzh9OnaO2k6LEzAehpom0kwFWrLNfN1f1RYh2bYYzCfncKDGTMlshy8 6npw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=jwuk9rSWQ8k8RLMJbV9PvQBNt+q4cA55Uql6eCk+MiI=; b=Ne70DcHuvtek86dD+nM8BgxBjhzXR4Y6wI18X+Prh1uFGwa+r0OZZVFJfjLlaMo2um BMXtmhI3tKbNSKX9msIRNeqCWNyOBM4L7R2J6ESZZzwGUGJ9B0KK9bFoObPf6VaOOfeB X7dwBJSFH13vEMqEJ+HzQHl8RwwMVGGhg+WVtKJzT64vGEqnncb83Oo1qsK2B+HIa6e0 B4TyjiVoJgH5xqREw0XAmP9yP+uZHfEaLyvop+V7g+gumT5TxAE/uDK6pqlS7H9QbZGS P30bdBiy++3pD1Uy1UhF5v2+aEM1HdfxbDuRMPIe8MONStJpLuVapsPSe/ACsmy7k06X Gl1Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kjwzEN1J; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=jwuk9rSWQ8k8RLMJbV9PvQBNt+q4cA55Uql6eCk+MiI=; b=eKKhnS1wb+F7LsueM9K3FbDJcJQ8DWQk2HOJ5ScUiK5cH8r0PMMJvPPMJwoOSPLsh7 itv2C39x4aUngbavjjuPaia3ESwezZa3mPk/I81TqrBHdRnxQpqLKW1kPSzt8+WtDbxc RZ4Z25Sm3nr83bB9r6JyHZkCb6fL7seZYpeSY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jwuk9rSWQ8k8RLMJbV9PvQBNt+q4cA55Uql6eCk+MiI=; b=A4Q+aex/O8gfGy99WAXUR20ZRjbJaIk7rqEokQ1f7T7oyHVKxLmDxflz7dh2K6Y32B XO3du7YIvTPldBsqam+TUacByeXbpkm2BrgHdkCINw7r2KRQwTIjiey84rAGdjhYJyQa do9u2cfgEg2o4aDJrtUifvQsy+sRDQUA2YsX9aLGXf8oTCcRNZhF1mDy8r98/qPGuUKM d0CCQAzZFm4k6wBToJ6AMarSCjCY1bqQL84ffdO3/buSAzH4xIgQlZbY8x3dnFbT5IbT YtDZznbIk/7zl6Rsran3KsOJZ3hMf/PXyfiGGWrKtOcui0Fm+KeIEnVAUx04g+aVkZWe ZhMg== X-Gm-Message-State: AFqh2kpcw1WXML2zGf1Q4BLJeS2Yeebd4+YUBu95DBv4dmuztVNKIbya K7WhDQLxBjyqcBGQ+EtRAWoQto+X X-Google-Smtp-Source: AMrXdXvHtDtkrjgv5Ld5nru3l2BZXPk5WZOnd0cDkTUG5fxG5IV29wRR9AIUHkZHm8oYKIY4+Dyxmg== X-Received: by 2002:a62:7b10:0:b0:588:fea7:15bb with SMTP id w16-20020a627b10000000b00588fea715bbmr2276525pfc.76.1674486766742; Mon, 23 Jan 2023 07:12:46 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90a:3801:b0:227:1b53:908c with SMTP id w1-20020a17090a380100b002271b53908cls16960483pjb.1.-pod-canary-gmail; Mon, 23 Jan 2023 07:12:46 -0800 (PST) X-Received: by 2002:a17:902:8541:b0:194:d3df:a9d1 with SMTP id d1-20020a170902854100b00194d3dfa9d1mr15053527plo.4.1674486765733; Mon, 23 Jan 2023 07:12:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674486765; cv=none; d=google.com; s=arc-20160816; b=Z3pn2fEP7HDBftMm0q+vi02OtBgPLL2dsvqk6L2q6tiZW983plKMhmwV5MomBZlQHl TFfBdgfCuRfIqmGo0v9fLJwrNL5uDl8WQAbbxjJFsMiGKlaZFiNi/pC7TN0LB3cHOARl 2KrvWnO6F9KyiWa93IJUplgORZCF1Rbc4XWPhgk06KloomGIocPqpwrbKg9j3xpRpPWM 5YyXcLOKzlgRj9gdubgGV6n+fQVvqOAVpjr+GUdItyac0+/2oc+Ycn0Gpk2C5ikBrYEX 7r19ypcjoIJvcZGUtHHL87f44o+uygLwxy2or/Yvou0bS5kpO7TOTr57JtwTTjqpOvPD Enew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=tSTOOV1UI3u7LdjXOPnQjVzALAHz+1al5IvaQmAe3co=; b=h46fV5hRdZGboJFIaY7bkNbQaikxMly+ZqDou/5S2sHsKqB+ySDhuVHWhIzMh3sn9+ wpNHcP8YM4IwqfuC1aZ3p2ofLzUELrqHrHOZt18pD43SA6oRb8NoqGQ48cJHzhhszd+h QXhClUFJHFNepaBSJcdjHGnie/bOTInIdJN/dK4dWWRhzhf8RUqJpVNyLObtoCjePr2k Fw0lg1VunsMbMfgSqCsqwKVdwqzMWI8xRRzFnUPNl62+XsywlXf+H1kDnE6tShpmPd9y zEoYx3tky6oUThXVsiqGJjuYz1km2W3GjzTw6VQfyai6J03vnDc1Fpk/wjwFYO66YYmx Ztbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kjwzEN1J; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id o8-20020a1709026b0800b0019304d850bbsor1943593plk.118.2023.01.23.07.12.45 for <linux-amarula@amarulasolutions.com> (Google Transport Security); Mon, 23 Jan 2023 07:12:45 -0800 (PST) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:902:c24c:b0:194:7696:b0f9 with SMTP id 12-20020a170902c24c00b001947696b0f9mr38420938plg.66.1674486765410; Mon, 23 Jan 2023 07:12:45 -0800 (PST) Received: from localhost.localdomain ([2405:201:c00a:a15f:2279:f361:f93b:7971]) by smtp.gmail.com with ESMTPSA id d5-20020a170903230500b001754fa42065sm19207111plh.143.2023.01.23.07.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:12:44 -0800 (PST) From: Jagan Teki <jagan@amarulasolutions.com> To: Andrzej Hajda <andrzej.hajda@intel.com>, Inki Dae <inki.dae@samsung.com>, Marek Szyprowski <m.szyprowski@samsung.com>, Joonyoung Shim <jy0922.shim@samsung.com>, Seung-Woo Kim <sw0312.kim@samsung.com>, Kyungmin Park <kyungmin.park@samsung.com>, Frieder Schrempf <frieder.schrempf@kontron.de>, Fancy Fang <chen.fang@nxp.com>, Tim Harvey <tharvey@gateworks.com>, Michael Nazzareno Trimarchi <michael@amarulasolutions.com>, Adam Ford <aford173@gmail.com>, Neil Armstrong <narmstrong@linaro.org>, Robert Foss <robert.foss@linaro.org>, Laurent Pinchart <Laurent.pinchart@ideasonboard.com>, Tommaso Merciai <tommaso.merciai@amarulasolutions.com>, Marek Vasut <marex@denx.de> Cc: Matteo Lisi <matteo.lisi@engicam.com>, dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, NXP Linux Team <linux-imx@nxp.com>, linux-amarula <linux-amarula@amarulasolutions.com>, Jagan Teki <jagan@amarulasolutions.com>, Maxime Ripard <mripard@kernel.org>, Linus Walleij <linus.walleij@linaro.org>, Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Subject: [RESEND PATCH v11 02/18] drm: bridge: panel: Add devm_drm_of_dsi_get_bridge helper Date: Mon, 23 Jan 2023 20:41:56 +0530 Message-Id: <20230123151212.269082-3-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230123151212.269082-1-jagan@amarulasolutions.com> References: <20230123151212.269082-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kjwzEN1J; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: <linux-amarula.amarulasolutions.com> X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/post>, <mailto:linux-amarula@amarulasolutions.com> List-Help: <https://support.google.com/a/amarulasolutions.com/bin/topic.py?topic=25838>, <mailto:linux-amarula+help@amarulasolutions.com> List-Archive: <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/> List-Unsubscribe: <mailto:googlegroups-manage+476853432473+unsubscribe@googlegroups.com>, <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/subscribe> |
| Series |
drm: Add Samsung MIPI DSIM bridge
|
|
Commit Message
Jagan Teki
Jan. 23, 2023, 3:11 p.m. UTC
Add devm OF helper to return the next DSI bridge in the chain.
Unlike general bridge return helper devm_drm_of_get_bridge, this
helper uses the dsi specific panel_or_bridge helper to find the
next DSI device in the pipeline.
Helper lookup a given child DSI node or a DT node's port and
endpoint number, find the connected node and return either
the associated struct drm_panel or drm_bridge device.
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Laurent Pinchart <Laurent.pinchart@ideasonboard.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
---
Changes for v11:
- none
Changes for v10:
- new patch
drivers/gpu/drm/bridge/panel.c | 34 ++++++++++++++++++++++++++++++++++
include/drm/drm_bridge.h | 2 ++
2 files changed, 36 insertions(+)
Comments
Hi, On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > Add devm OF helper to return the next DSI bridge in the chain. > > Unlike general bridge return helper devm_drm_of_get_bridge, this > helper uses the dsi specific panel_or_bridge helper to find the > next DSI device in the pipeline. > > Helper lookup a given child DSI node or a DT node's port and > endpoint number, find the connected node and return either > the associated struct drm_panel or drm_bridge device. I'm not sure that using a device managed helper is the right choice here. The bridge will stay longer than the backing device so it will create a use-after-free. You should probably use a DRM-managed action here instead. Maxime
On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > Hi, > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > Add devm OF helper to return the next DSI bridge in the chain. > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > helper uses the dsi specific panel_or_bridge helper to find the > > next DSI device in the pipeline. > > > > Helper lookup a given child DSI node or a DT node's port and > > endpoint number, find the connected node and return either > > the associated struct drm_panel or drm_bridge device. > > I'm not sure that using a device managed helper is the right choice > here. The bridge will stay longer than the backing device so it will > create a use-after-free. You should probably use a DRM-managed action > here instead. Thanks for the comments. If I understand correctly we can use drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found the panel or bridge - am I correct? Jagan.
Hi, On Thu, Jan 26, 2023 at 8:48 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > Hi, > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > helper uses the dsi specific panel_or_bridge helper to find the > > > next DSI device in the pipeline. > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > endpoint number, find the connected node and return either > > > the associated struct drm_panel or drm_bridge device. > > > > I'm not sure that using a device managed helper is the right choice > > here. The bridge will stay longer than the backing device so it will > > create a use-after-free. You should probably use a DRM-managed action > > here instead. > > Thanks for the comments. If I understand correctly we can use > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > the panel or bridge - am I correct? Look like it is not possible to use DRM-managed action helper here as devm_drm_of_dsi_get_bridge is calling from the DSI host attach hook in which we cannot find drm_device pointer (as drm_device pointer is mandatory for using DRM-managed action). https://github.com/openedev/kernel/blob/imx8mm-dsi-v12/drivers/gpu/drm/bridge/samsung-dsim.c#L1545 Please check and correct me if I mentioned any incorrect details. Thanks, Jagan.
On Fri, Jan 27, 2023 at 11:09:26PM +0530, Jagan Teki wrote: > Hi, > > On Thu, Jan 26, 2023 at 8:48 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > Hi, > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > next DSI device in the pipeline. > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > endpoint number, find the connected node and return either > > > > the associated struct drm_panel or drm_bridge device. > > > > > > I'm not sure that using a device managed helper is the right choice > > > here. The bridge will stay longer than the backing device so it will > > > create a use-after-free. You should probably use a DRM-managed action > > > here instead. > > > > Thanks for the comments. If I understand correctly we can use > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > the panel or bridge - am I correct? > > Look like it is not possible to use DRM-managed action helper here as > devm_drm_of_dsi_get_bridge is calling from the DSI host attach hook in > which we cannot find drm_device pointer (as drm_device pointer is > mandatory for using DRM-managed action). > https://github.com/openedev/kernel/blob/imx8mm-dsi-v12/drivers/gpu/drm/bridge/samsung-dsim.c#L1545 > > Please check and correct me if I mentioned any incorrect details. You shouldn't call that function from attach anyway: https://dri.freedesktop.org/docs/drm/gpu/drm-kms-helpers.html#special-care-with-mipi-dsi-bridges Maxime
On Thu, Jan 26, 2023 at 08:48:48PM +0530, Jagan Teki wrote: > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > Hi, > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > helper uses the dsi specific panel_or_bridge helper to find the > > > next DSI device in the pipeline. > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > endpoint number, find the connected node and return either > > > the associated struct drm_panel or drm_bridge device. > > > > I'm not sure that using a device managed helper is the right choice > > here. The bridge will stay longer than the backing device so it will > > create a use-after-free. You should probably use a DRM-managed action > > here instead. > > Thanks for the comments. If I understand correctly we can use > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > the panel or bridge - am I correct? It's not that we can, it's that the devm_panel_bridge_add is unsafe: when the module is removed the device will go away and all the devm resources freed, but the DRM device sticks around until the last application with a fd open closes that fd. Maxime
On Mon, Jan 30, 2023 at 6:28 PM Maxime Ripard <maxime@cerno.tech> wrote: > > On Thu, Jan 26, 2023 at 08:48:48PM +0530, Jagan Teki wrote: > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > Hi, > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > next DSI device in the pipeline. > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > endpoint number, find the connected node and return either > > > > the associated struct drm_panel or drm_bridge device. > > > > > > I'm not sure that using a device managed helper is the right choice > > > here. The bridge will stay longer than the backing device so it will > > > create a use-after-free. You should probably use a DRM-managed action > > > here instead. > > > > Thanks for the comments. If I understand correctly we can use > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > the panel or bridge - am I correct? > > It's not that we can, it's that the devm_panel_bridge_add is unsafe: > when the module is removed the device will go away and all the devm > resources freed, but the DRM device sticks around until the last > application with a fd open closes that fd. Thanks for the details. I think this is the reason you have introduced this DRM-managed action helper - drmm_of_get_bridge. Initially, i thought of adding similar, but as you are aware it is not possible to call it from the host attach. Jagan.
On Mon, Jan 30, 2023 at 6:26 PM Maxime Ripard <maxime@cerno.tech> wrote: > > On Fri, Jan 27, 2023 at 11:09:26PM +0530, Jagan Teki wrote: > > Hi, > > > > On Thu, Jan 26, 2023 at 8:48 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > > > > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > Hi, > > > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > > next DSI device in the pipeline. > > > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > > endpoint number, find the connected node and return either > > > > > the associated struct drm_panel or drm_bridge device. > > > > > > > > I'm not sure that using a device managed helper is the right choice > > > > here. The bridge will stay longer than the backing device so it will > > > > create a use-after-free. You should probably use a DRM-managed action > > > > here instead. > > > > > > Thanks for the comments. If I understand correctly we can use > > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > > the panel or bridge - am I correct? > > > > Look like it is not possible to use DRM-managed action helper here as > > devm_drm_of_dsi_get_bridge is calling from the DSI host attach hook in > > which we cannot find drm_device pointer (as drm_device pointer is > > mandatory for using DRM-managed action). > > https://github.com/openedev/kernel/blob/imx8mm-dsi-v12/drivers/gpu/drm/bridge/samsung-dsim.c#L1545 > > > > Please check and correct me if I mentioned any incorrect details. > > You shouldn't call that function from attach anyway: > https://dri.freedesktop.org/docs/drm/gpu/drm-kms-helpers.html#special-care-with-mipi-dsi-bridges True, If I remember we have bridges earlier to find the downstream bridge/panels from the bridge ops and attach the hook, if that is the case maybe we can use this DRM-managed action as we can get the drm_device pointer from the bridge pointer. So, what is the best we can do here, add any TODO comment to follow up the same in the future or something else, please let me know? Thanks, Jagan.
On Mon, Jan 30, 2023 at 06:54:54PM +0530, Jagan Teki wrote: > On Mon, Jan 30, 2023 at 6:26 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > On Fri, Jan 27, 2023 at 11:09:26PM +0530, Jagan Teki wrote: > > > Hi, > > > > > > On Thu, Jan 26, 2023 at 8:48 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > > > > > > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > Hi, > > > > > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > > > next DSI device in the pipeline. > > > > > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > > > endpoint number, find the connected node and return either > > > > > > the associated struct drm_panel or drm_bridge device. > > > > > > > > > > I'm not sure that using a device managed helper is the right choice > > > > > here. The bridge will stay longer than the backing device so it will > > > > > create a use-after-free. You should probably use a DRM-managed action > > > > > here instead. > > > > > > > > Thanks for the comments. If I understand correctly we can use > > > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > > > the panel or bridge - am I correct? > > > > > > Look like it is not possible to use DRM-managed action helper here as > > > devm_drm_of_dsi_get_bridge is calling from the DSI host attach hook in > > > which we cannot find drm_device pointer (as drm_device pointer is > > > mandatory for using DRM-managed action). > > > https://github.com/openedev/kernel/blob/imx8mm-dsi-v12/drivers/gpu/drm/bridge/samsung-dsim.c#L1545 > > > > > > Please check and correct me if I mentioned any incorrect details. > > > > You shouldn't call that function from attach anyway: > > https://dri.freedesktop.org/docs/drm/gpu/drm-kms-helpers.html#special-care-with-mipi-dsi-bridges > > True, If I remember we have bridges earlier to find the downstream > bridge/panels from the bridge ops and attach the hook, if that is the > case maybe we can use this DRM-managed action as we can get the > drm_device pointer from the bridge pointer. I'm not quite sure what you mean. You shouldn't retrieve the bridge from the attach hook but from the probe / bind ones. If that's not working for you, this is a bug in the documentation we should address. > So, what is the best we can do here, add any TODO comment to follow up > the same in the future or something else, please let me know? Make it work in a safe way, as described in the documentation? Maxime
On Tue, Jan 31, 2023 at 6:16 PM Maxime Ripard <maxime@cerno.tech> wrote: > > On Mon, Jan 30, 2023 at 06:54:54PM +0530, Jagan Teki wrote: > > On Mon, Jan 30, 2023 at 6:26 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > On Fri, Jan 27, 2023 at 11:09:26PM +0530, Jagan Teki wrote: > > > > Hi, > > > > > > > > On Thu, Jan 26, 2023 at 8:48 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > > > > > > > > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > > > Hi, > > > > > > > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > > > > next DSI device in the pipeline. > > > > > > > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > > > > endpoint number, find the connected node and return either > > > > > > > the associated struct drm_panel or drm_bridge device. > > > > > > > > > > > > I'm not sure that using a device managed helper is the right choice > > > > > > here. The bridge will stay longer than the backing device so it will > > > > > > create a use-after-free. You should probably use a DRM-managed action > > > > > > here instead. > > > > > > > > > > Thanks for the comments. If I understand correctly we can use > > > > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > > > > the panel or bridge - am I correct? > > > > > > > > Look like it is not possible to use DRM-managed action helper here as > > > > devm_drm_of_dsi_get_bridge is calling from the DSI host attach hook in > > > > which we cannot find drm_device pointer (as drm_device pointer is > > > > mandatory for using DRM-managed action). > > > > https://github.com/openedev/kernel/blob/imx8mm-dsi-v12/drivers/gpu/drm/bridge/samsung-dsim.c#L1545 > > > > > > > > Please check and correct me if I mentioned any incorrect details. > > > > > > You shouldn't call that function from attach anyway: > > > https://dri.freedesktop.org/docs/drm/gpu/drm-kms-helpers.html#special-care-with-mipi-dsi-bridges > > > > True, If I remember we have bridges earlier to find the downstream > > bridge/panels from the bridge ops and attach the hook, if that is the > > case maybe we can use this DRM-managed action as we can get the > > drm_device pointer from the bridge pointer. > > I'm not quite sure what you mean. You shouldn't retrieve the bridge from > the attach hook but from the probe / bind ones. If that's not working > for you, this is a bug in the documentation we should address. Something like this, afterward the design has updated to move the panel or bridge found to be in host attach. https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/bridge/nwl-dsi.c?h=v5.10#n911 > > > So, what is the best we can do here, add any TODO comment to follow up > > the same in the future or something else, please let me know? > > Make it work in a safe way, as described in the documentation? Yeah, it is a clear deadlock. It is not possible to use DM-managed action helper in host attach as there is no drm_device pointer and we cannot move panel or bridge finding out of host attach as per design documentation. I'm thinking of go-ahead with adding TODO for adding the safe way with an existing patch. Please let me know. Thanks, Jagan.
On Tue, Jan 31, 2023 at 07:17:50PM +0530, Jagan Teki wrote: > On Tue, Jan 31, 2023 at 6:16 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > On Mon, Jan 30, 2023 at 06:54:54PM +0530, Jagan Teki wrote: > > > On Mon, Jan 30, 2023 at 6:26 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > On Fri, Jan 27, 2023 at 11:09:26PM +0530, Jagan Teki wrote: > > > > > Hi, > > > > > > > > > > On Thu, Jan 26, 2023 at 8:48 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > > > > > > > > > > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > > > > > Hi, > > > > > > > > > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > > > > > next DSI device in the pipeline. > > > > > > > > > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > > > > > endpoint number, find the connected node and return either > > > > > > > > the associated struct drm_panel or drm_bridge device. > > > > > > > > > > > > > > I'm not sure that using a device managed helper is the right choice > > > > > > > here. The bridge will stay longer than the backing device so it will > > > > > > > create a use-after-free. You should probably use a DRM-managed action > > > > > > > here instead. > > > > > > > > > > > > Thanks for the comments. If I understand correctly we can use > > > > > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > > > > > the panel or bridge - am I correct? > > > > > > > > > > Look like it is not possible to use DRM-managed action helper here as > > > > > devm_drm_of_dsi_get_bridge is calling from the DSI host attach hook in > > > > > which we cannot find drm_device pointer (as drm_device pointer is > > > > > mandatory for using DRM-managed action). > > > > > https://github.com/openedev/kernel/blob/imx8mm-dsi-v12/drivers/gpu/drm/bridge/samsung-dsim.c#L1545 > > > > > > > > > > Please check and correct me if I mentioned any incorrect details. > > > > > > > > You shouldn't call that function from attach anyway: > > > > https://dri.freedesktop.org/docs/drm/gpu/drm-kms-helpers.html#special-care-with-mipi-dsi-bridges > > > > > > True, If I remember we have bridges earlier to find the downstream > > > bridge/panels from the bridge ops and attach the hook, if that is the > > > case maybe we can use this DRM-managed action as we can get the > > > drm_device pointer from the bridge pointer. > > > > I'm not quite sure what you mean. You shouldn't retrieve the bridge from > > the attach hook but from the probe / bind ones. If that's not working > > for you, this is a bug in the documentation we should address. > > Something like this, afterward the design has updated to move the > panel or bridge found to be in host attach. > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/bridge/nwl-dsi.c?h=v5.10#n911 What are you pointing to exactly, it's not a MIPI-DSI host attach, that's a bridge attach, you have access to the DRM device there. > > > > > So, what is the best we can do here, add any TODO comment to follow up > > > the same in the future or something else, please let me know? > > > > Make it work in a safe way, as described in the documentation? > > Yeah, it is a clear deadlock. It is not possible to use DM-managed > action helper in host attach as there is no drm_device pointer and we > cannot move panel or bridge finding out of host attach as per design > documentation. I'm thinking of go-ahead with adding TODO for adding > the safe way with an existing patch. Please let me know. I've been telling you for three mails now that it's not acceptable. So, again, no, it's not acceptable. Do something else and follow the documentation instead. Maxime
On Tue, Jan 31, 2023 at 7:29 PM Maxime Ripard <maxime@cerno.tech> wrote: > > On Tue, Jan 31, 2023 at 07:17:50PM +0530, Jagan Teki wrote: > > On Tue, Jan 31, 2023 at 6:16 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > On Mon, Jan 30, 2023 at 06:54:54PM +0530, Jagan Teki wrote: > > > > On Mon, Jan 30, 2023 at 6:26 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > On Fri, Jan 27, 2023 at 11:09:26PM +0530, Jagan Teki wrote: > > > > > > Hi, > > > > > > > > > > > > On Thu, Jan 26, 2023 at 8:48 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > > > > > > > > > > > > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > > > > > > > Hi, > > > > > > > > > > > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > > > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > > > > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > > > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > > > > > > next DSI device in the pipeline. > > > > > > > > > > > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > > > > > > endpoint number, find the connected node and return either > > > > > > > > > the associated struct drm_panel or drm_bridge device. > > > > > > > > > > > > > > > > I'm not sure that using a device managed helper is the right choice > > > > > > > > here. The bridge will stay longer than the backing device so it will > > > > > > > > create a use-after-free. You should probably use a DRM-managed action > > > > > > > > here instead. > > > > > > > > > > > > > > Thanks for the comments. If I understand correctly we can use > > > > > > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > > > > > > the panel or bridge - am I correct? > > > > > > > > > > > > Look like it is not possible to use DRM-managed action helper here as > > > > > > devm_drm_of_dsi_get_bridge is calling from the DSI host attach hook in > > > > > > which we cannot find drm_device pointer (as drm_device pointer is > > > > > > mandatory for using DRM-managed action). > > > > > > https://github.com/openedev/kernel/blob/imx8mm-dsi-v12/drivers/gpu/drm/bridge/samsung-dsim.c#L1545 > > > > > > > > > > > > Please check and correct me if I mentioned any incorrect details. > > > > > > > > > > You shouldn't call that function from attach anyway: > > > > > https://dri.freedesktop.org/docs/drm/gpu/drm-kms-helpers.html#special-care-with-mipi-dsi-bridges > > > > > > > > True, If I remember we have bridges earlier to find the downstream > > > > bridge/panels from the bridge ops and attach the hook, if that is the > > > > case maybe we can use this DRM-managed action as we can get the > > > > drm_device pointer from the bridge pointer. > > > > > > I'm not quite sure what you mean. You shouldn't retrieve the bridge from > > > the attach hook but from the probe / bind ones. If that's not working > > > for you, this is a bug in the documentation we should address. > > > > Something like this, afterward the design has updated to move the > > panel or bridge found to be in host attach. > > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/bridge/nwl-dsi.c?h=v5.10#n911 > > What are you pointing to exactly, it's not a MIPI-DSI host attach, > that's a bridge attach, you have access to the DRM device there. Yes, what I'm saying here is we can have the option to use a DRM device pointer so finding the panel or bridge by using a DRM-managed action helper can be possible rather than host attach. Something like this, struct drm_bridge *drmm_of_dsi_get_bridge(struct drm_device *drm, struct device_node *np, u32 port, u32 endpoint) { struct drm_bridge *bridge; struct drm_panel *panel; int ret; ret = drm_of_dsi_find_panel_or_bridge(np, port, endpoint, &panel, &bridge); if (ret) return ERR_PTR(ret); if (panel) bridge = drmm_panel_bridge_add(drm, panel); return bridge; } static int nwl_dsi_bridge_attach(struct drm_bridge *bridge, enum drm_bridge_attach_flags flags) { struct nwl_dsi *dsi = bridge_to_dsi(bridge); struct drm_bridge *bridge; int ret; bridge = drmm_of_dsi_get_bridge(bridge->dev, dsi->dev->of_node, 1, 0); if (IS_ERR(bridge)) ret = PTR_ERR(dsi->out_bridge); return drm_bridge_attach(bridge->encoder, dsi->panel_bridge, bridge, flags); } static const struct drm_bridge_funcs nwl_dsi_bridge_funcs = { .attach = nwl_dsi_bridge_attach, }; > > > > > > > > So, what is the best we can do here, add any TODO comment to follow up > > > > the same in the future or something else, please let me know? > > > > > > Make it work in a safe way, as described in the documentation? > > > > Yeah, it is a clear deadlock. It is not possible to use DM-managed > > action helper in host attach as there is no drm_device pointer and we > > cannot move panel or bridge finding out of host attach as per design > > documentation. I'm thinking of go-ahead with adding TODO for adding > > the safe way with an existing patch. Please let me know. > > I've been telling you for three mails now that it's not acceptable. So, > again, no, it's not acceptable. Do something else and follow the > documentation instead. Ohh, look like I didn't get this in the first e-mail. Okay, now I got it, thanks. On the other hand, this series recurring for more than a year, so to merge things go quickly can you please suggest some solution based on this discussion? Thanks, Jagan.
Hi Maxime, On Mon, Jan 30, 2023 at 6:28 PM Maxime Ripard <maxime@cerno.tech> wrote: > > On Thu, Jan 26, 2023 at 08:48:48PM +0530, Jagan Teki wrote: > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > Hi, > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > next DSI device in the pipeline. > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > endpoint number, find the connected node and return either > > > > the associated struct drm_panel or drm_bridge device. > > > > > > I'm not sure that using a device managed helper is the right choice > > > here. The bridge will stay longer than the backing device so it will > > > create a use-after-free. You should probably use a DRM-managed action > > > here instead. > > > > Thanks for the comments. If I understand correctly we can use > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > the panel or bridge - am I correct? > > It's not that we can, it's that the devm_panel_bridge_add is unsafe: > when the module is removed the device will go away and all the devm > resources freed, but the DRM device sticks around until the last > application with a fd open closes that fd. Would you please check this, Here I'm trying to do 1. find a panel or bridge 2. if panel add it as a panel bridge 3. add DRM-managed action with the help of bridge->dev after step 2. Didn't test the behavior, just wanted to check whether it can be a possibility to use bridge->dev as this dev is assigned with encoder->dev during the bridge attach the chain. Please check and let me know. struct drm_bridge *devm_drm_of_dsi_get_bridge(struct device *dev, struct device_node *np, u32 port, u32 endpoint) { struct drm_bridge *bridge; struct drm_panel *panel; int ret; ret = drm_of_dsi_find_panel_or_bridge(np, port, endpoint, &panel, &bridge); if (ret) return ERR_PTR(ret); if (panel) bridge = devm_drm_panel_bridge_add(dev, panel); if (IS_ERR(bridge)) return bridge; ret = drmm_add_action_or_reset(bridge->dev, drmm_drm_panel_bridge_release, bridge); if (ret) return ERR_PTR(ret); return bridge; } Thanks, Jagan.
On Thu, Feb 02, 2023 at 10:22:42PM +0530, Jagan Teki wrote: > Hi Maxime, > > On Mon, Jan 30, 2023 at 6:28 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > On Thu, Jan 26, 2023 at 08:48:48PM +0530, Jagan Teki wrote: > > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > Hi, > > > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > > next DSI device in the pipeline. > > > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > > endpoint number, find the connected node and return either > > > > > the associated struct drm_panel or drm_bridge device. > > > > > > > > I'm not sure that using a device managed helper is the right choice > > > > here. The bridge will stay longer than the backing device so it will > > > > create a use-after-free. You should probably use a DRM-managed action > > > > here instead. > > > > > > Thanks for the comments. If I understand correctly we can use > > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > > the panel or bridge - am I correct? > > > > It's not that we can, it's that the devm_panel_bridge_add is unsafe: > > when the module is removed the device will go away and all the devm > > resources freed, but the DRM device sticks around until the last > > application with a fd open closes that fd. > > Would you please check this, Here I'm trying to do > > 1. find a panel or bridge > 2. if panel add it as a panel bridge > 3. add DRM-managed action with the help of bridge->dev after step 2. The logic is sound in your patch > Didn't test the behavior, just wanted to check whether it can be a > possibility to use bridge->dev as this dev is assigned with > encoder->dev during the bridge attach the chain. Please check and let > me know. > > struct drm_bridge *devm_drm_of_dsi_get_bridge(struct device *dev, > struct device_node *np, > u32 port, u32 endpoint) > { > struct drm_bridge *bridge; > struct drm_panel *panel; > int ret; > > ret = drm_of_dsi_find_panel_or_bridge(np, port, endpoint, > &panel, &bridge); > if (ret) > return ERR_PTR(ret); > > if (panel) > bridge = devm_drm_panel_bridge_add(dev, panel); > > if (IS_ERR(bridge)) > return bridge; > > ret = drmm_add_action_or_reset(bridge->dev, > drmm_drm_panel_bridge_release, > bridge); > if (ret) > return ERR_PTR(ret); > > return bridge; > } It's the implementation that isn't. You cannot use a devm hook to register a KMS structure, so it's not that you should add a drmm_add_action call, it's that you shouldn't call devm_drm_panel_bridge_add in the first place. So either you use drm_panel_bridge_add and a custom drmm action, or you add a drmm_panel_bridge_add function and use it. Maxime
On Fri, Feb 3, 2023 at 1:56 PM Maxime Ripard <maxime@cerno.tech> wrote: > > On Thu, Feb 02, 2023 at 10:22:42PM +0530, Jagan Teki wrote: > > Hi Maxime, > > > > On Mon, Jan 30, 2023 at 6:28 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > On Thu, Jan 26, 2023 at 08:48:48PM +0530, Jagan Teki wrote: > > > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > Hi, > > > > > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > > > next DSI device in the pipeline. > > > > > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > > > endpoint number, find the connected node and return either > > > > > > the associated struct drm_panel or drm_bridge device. > > > > > > > > > > I'm not sure that using a device managed helper is the right choice > > > > > here. The bridge will stay longer than the backing device so it will > > > > > create a use-after-free. You should probably use a DRM-managed action > > > > > here instead. > > > > > > > > Thanks for the comments. If I understand correctly we can use > > > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > > > the panel or bridge - am I correct? > > > > > > It's not that we can, it's that the devm_panel_bridge_add is unsafe: > > > when the module is removed the device will go away and all the devm > > > resources freed, but the DRM device sticks around until the last > > > application with a fd open closes that fd. > > > > Would you please check this, Here I'm trying to do > > > > 1. find a panel or bridge > > 2. if panel add it as a panel bridge > > 3. add DRM-managed action with the help of bridge->dev after step 2. > > The logic is sound in your patch > > > Didn't test the behavior, just wanted to check whether it can be a > > possibility to use bridge->dev as this dev is assigned with > > encoder->dev during the bridge attach the chain. Please check and let > > me know. > > > > struct drm_bridge *devm_drm_of_dsi_get_bridge(struct device *dev, > > struct device_node *np, > > u32 port, u32 endpoint) > > { > > struct drm_bridge *bridge; > > struct drm_panel *panel; > > int ret; > > > > ret = drm_of_dsi_find_panel_or_bridge(np, port, endpoint, > > &panel, &bridge); > > if (ret) > > return ERR_PTR(ret); > > > > if (panel) > > bridge = devm_drm_panel_bridge_add(dev, panel); > > > > if (IS_ERR(bridge)) > > return bridge; > > > > ret = drmm_add_action_or_reset(bridge->dev, > > drmm_drm_panel_bridge_release, > > bridge); > > if (ret) > > return ERR_PTR(ret); > > > > return bridge; > > } > > It's the implementation that isn't. You cannot use a devm hook to > register a KMS structure, so it's not that you should add a > drmm_add_action call, it's that you shouldn't call > devm_drm_panel_bridge_add in the first place. I think it is because the remove action helper uses drm_panel_bridge_remove instead of devm hook. > > So either you use drm_panel_bridge_add and a custom drmm action, or you > add a drmm_panel_bridge_add function and use it. It is not possible to use this helper as it is expecting drm_device point that would get only if we found panel_bridge, so combined calls here can help. Would you please check this updated implementation and let me know? struct drm_bridge *drmm_panel_bridge_add_nodrm(struct drm_panel *panel) { struct drm_bridge *bridge; int ret; bridge = drm_panel_bridge_add_typed(panel, panel->connector_type); if (IS_ERR(bridge)) return bridge; ret = drmm_add_action_or_reset(bridge->dev, drmm_drm_panel_bridge_release, bridge); if (ret) return ERR_PTR(ret); bridge->pre_enable_prev_first = panel->prepare_prev_first; return bridge; } struct drm_bridge *drm_of_dsi_get_bridge(struct device_node *np, u32 port, u32 endpoint) { struct drm_bridge *bridge; struct drm_panel *panel; int ret; ret = drm_of_dsi_find_panel_or_bridge(np, port, endpoint, &panel, &bridge); if (ret) return ERR_PTR(ret); if (panel) bridge = drmm_panel_bridge_add_nodrm(panel); return bridge; } Thanks, Jagan.
On Fri, Feb 03, 2023 at 04:13:49PM +0530, Jagan Teki wrote: > On Fri, Feb 3, 2023 at 1:56 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > On Thu, Feb 02, 2023 at 10:22:42PM +0530, Jagan Teki wrote: > > > Hi Maxime, > > > > > > On Mon, Jan 30, 2023 at 6:28 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > On Thu, Jan 26, 2023 at 08:48:48PM +0530, Jagan Teki wrote: > > > > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > > > Hi, > > > > > > > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > > > > next DSI device in the pipeline. > > > > > > > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > > > > endpoint number, find the connected node and return either > > > > > > > the associated struct drm_panel or drm_bridge device. > > > > > > > > > > > > I'm not sure that using a device managed helper is the right choice > > > > > > here. The bridge will stay longer than the backing device so it will > > > > > > create a use-after-free. You should probably use a DRM-managed action > > > > > > here instead. > > > > > > > > > > Thanks for the comments. If I understand correctly we can use > > > > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > > > > the panel or bridge - am I correct? > > > > > > > > It's not that we can, it's that the devm_panel_bridge_add is unsafe: > > > > when the module is removed the device will go away and all the devm > > > > resources freed, but the DRM device sticks around until the last > > > > application with a fd open closes that fd. > > > > > > Would you please check this, Here I'm trying to do > > > > > > 1. find a panel or bridge > > > 2. if panel add it as a panel bridge > > > 3. add DRM-managed action with the help of bridge->dev after step 2. > > > > The logic is sound in your patch > > > > > Didn't test the behavior, just wanted to check whether it can be a > > > possibility to use bridge->dev as this dev is assigned with > > > encoder->dev during the bridge attach the chain. Please check and let > > > me know. > > > > > > struct drm_bridge *devm_drm_of_dsi_get_bridge(struct device *dev, > > > struct device_node *np, > > > u32 port, u32 endpoint) > > > { > > > struct drm_bridge *bridge; > > > struct drm_panel *panel; > > > int ret; > > > > > > ret = drm_of_dsi_find_panel_or_bridge(np, port, endpoint, > > > &panel, &bridge); > > > if (ret) > > > return ERR_PTR(ret); > > > > > > if (panel) > > > bridge = devm_drm_panel_bridge_add(dev, panel); > > > > > > if (IS_ERR(bridge)) > > > return bridge; > > > > > > ret = drmm_add_action_or_reset(bridge->dev, > > > drmm_drm_panel_bridge_release, > > > bridge); > > > if (ret) > > > return ERR_PTR(ret); > > > > > > return bridge; > > > } > > > > It's the implementation that isn't. You cannot use a devm hook to > > register a KMS structure, so it's not that you should add a > > drmm_add_action call, it's that you shouldn't call > > devm_drm_panel_bridge_add in the first place. > > I think it is because the remove action helper uses > drm_panel_bridge_remove instead of devm hook. > > > > So either you use drm_panel_bridge_add and a custom drmm action, or you > > add a drmm_panel_bridge_add function and use it. > > It is not possible to use this helper as it is expecting drm_device It's definitely possible, just change the prototype of the function to take a drm_device pointer, just like any other drmm_* function. Maxime
On Fri, Feb 3, 2023 at 4:19 PM Maxime Ripard <maxime@cerno.tech> wrote: > > On Fri, Feb 03, 2023 at 04:13:49PM +0530, Jagan Teki wrote: > > On Fri, Feb 3, 2023 at 1:56 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > On Thu, Feb 02, 2023 at 10:22:42PM +0530, Jagan Teki wrote: > > > > Hi Maxime, > > > > > > > > On Mon, Jan 30, 2023 at 6:28 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > On Thu, Jan 26, 2023 at 08:48:48PM +0530, Jagan Teki wrote: > > > > > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > > > > > Hi, > > > > > > > > > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > > > > > next DSI device in the pipeline. > > > > > > > > > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > > > > > endpoint number, find the connected node and return either > > > > > > > > the associated struct drm_panel or drm_bridge device. > > > > > > > > > > > > > > I'm not sure that using a device managed helper is the right choice > > > > > > > here. The bridge will stay longer than the backing device so it will > > > > > > > create a use-after-free. You should probably use a DRM-managed action > > > > > > > here instead. > > > > > > > > > > > > Thanks for the comments. If I understand correctly we can use > > > > > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > > > > > the panel or bridge - am I correct? > > > > > > > > > > It's not that we can, it's that the devm_panel_bridge_add is unsafe: > > > > > when the module is removed the device will go away and all the devm > > > > > resources freed, but the DRM device sticks around until the last > > > > > application with a fd open closes that fd. > > > > > > > > Would you please check this, Here I'm trying to do > > > > > > > > 1. find a panel or bridge > > > > 2. if panel add it as a panel bridge > > > > 3. add DRM-managed action with the help of bridge->dev after step 2. > > > > > > The logic is sound in your patch > > > > > > > Didn't test the behavior, just wanted to check whether it can be a > > > > possibility to use bridge->dev as this dev is assigned with > > > > encoder->dev during the bridge attach the chain. Please check and let > > > > me know. > > > > > > > > struct drm_bridge *devm_drm_of_dsi_get_bridge(struct device *dev, > > > > struct device_node *np, > > > > u32 port, u32 endpoint) > > > > { > > > > struct drm_bridge *bridge; > > > > struct drm_panel *panel; > > > > int ret; > > > > > > > > ret = drm_of_dsi_find_panel_or_bridge(np, port, endpoint, > > > > &panel, &bridge); > > > > if (ret) > > > > return ERR_PTR(ret); > > > > > > > > if (panel) > > > > bridge = devm_drm_panel_bridge_add(dev, panel); > > > > > > > > if (IS_ERR(bridge)) > > > > return bridge; > > > > > > > > ret = drmm_add_action_or_reset(bridge->dev, > > > > drmm_drm_panel_bridge_release, > > > > bridge); > > > > if (ret) > > > > return ERR_PTR(ret); > > > > > > > > return bridge; > > > > } > > > > > > It's the implementation that isn't. You cannot use a devm hook to > > > register a KMS structure, so it's not that you should add a > > > drmm_add_action call, it's that you shouldn't call > > > devm_drm_panel_bridge_add in the first place. > > > > I think it is because the remove action helper uses > > drm_panel_bridge_remove instead of devm hook. > > > > > > So either you use drm_panel_bridge_add and a custom drmm action, or you > > > add a drmm_panel_bridge_add function and use it. > > > > It is not possible to use this helper as it is expecting drm_device > > It's definitely possible, just change the prototype of the function to > take a drm_device pointer, just like any other drmm_* function. But, in my case, I only get the drm_device pointer once I found the bridge pointer of panel_bridge but the actual bridge finding for panel_bridge is happening in the drmm_panel_bridge_add definition. Doesn't it redundant if I find the panel_bridge and pass drm_device and panel pointer for calling drmm_panel_bridge_add? Jagan.
On Fri, Feb 03, 2023 at 04:28:30PM +0530, Jagan Teki wrote: > On Fri, Feb 3, 2023 at 4:19 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > On Fri, Feb 03, 2023 at 04:13:49PM +0530, Jagan Teki wrote: > > > On Fri, Feb 3, 2023 at 1:56 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > On Thu, Feb 02, 2023 at 10:22:42PM +0530, Jagan Teki wrote: > > > > > Hi Maxime, > > > > > > > > > > On Mon, Jan 30, 2023 at 6:28 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > > > On Thu, Jan 26, 2023 at 08:48:48PM +0530, Jagan Teki wrote: > > > > > > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > > > > > > > Hi, > > > > > > > > > > > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > > > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > > > > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > > > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > > > > > > next DSI device in the pipeline. > > > > > > > > > > > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > > > > > > endpoint number, find the connected node and return either > > > > > > > > > the associated struct drm_panel or drm_bridge device. > > > > > > > > > > > > > > > > I'm not sure that using a device managed helper is the right choice > > > > > > > > here. The bridge will stay longer than the backing device so it will > > > > > > > > create a use-after-free. You should probably use a DRM-managed action > > > > > > > > here instead. > > > > > > > > > > > > > > Thanks for the comments. If I understand correctly we can use > > > > > > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > > > > > > the panel or bridge - am I correct? > > > > > > > > > > > > It's not that we can, it's that the devm_panel_bridge_add is unsafe: > > > > > > when the module is removed the device will go away and all the devm > > > > > > resources freed, but the DRM device sticks around until the last > > > > > > application with a fd open closes that fd. > > > > > > > > > > Would you please check this, Here I'm trying to do > > > > > > > > > > 1. find a panel or bridge > > > > > 2. if panel add it as a panel bridge > > > > > 3. add DRM-managed action with the help of bridge->dev after step 2. > > > > > > > > The logic is sound in your patch > > > > > > > > > Didn't test the behavior, just wanted to check whether it can be a > > > > > possibility to use bridge->dev as this dev is assigned with > > > > > encoder->dev during the bridge attach the chain. Please check and let > > > > > me know. > > > > > > > > > > struct drm_bridge *devm_drm_of_dsi_get_bridge(struct device *dev, > > > > > struct device_node *np, > > > > > u32 port, u32 endpoint) > > > > > { > > > > > struct drm_bridge *bridge; > > > > > struct drm_panel *panel; > > > > > int ret; > > > > > > > > > > ret = drm_of_dsi_find_panel_or_bridge(np, port, endpoint, > > > > > &panel, &bridge); > > > > > if (ret) > > > > > return ERR_PTR(ret); > > > > > > > > > > if (panel) > > > > > bridge = devm_drm_panel_bridge_add(dev, panel); > > > > > > > > > > if (IS_ERR(bridge)) > > > > > return bridge; > > > > > > > > > > ret = drmm_add_action_or_reset(bridge->dev, > > > > > drmm_drm_panel_bridge_release, > > > > > bridge); > > > > > if (ret) > > > > > return ERR_PTR(ret); > > > > > > > > > > return bridge; > > > > > } > > > > > > > > It's the implementation that isn't. You cannot use a devm hook to > > > > register a KMS structure, so it's not that you should add a > > > > drmm_add_action call, it's that you shouldn't call > > > > devm_drm_panel_bridge_add in the first place. > > > > > > I think it is because the remove action helper uses > > > drm_panel_bridge_remove instead of devm hook. > > > > > > > > So either you use drm_panel_bridge_add and a custom drmm action, or you > > > > add a drmm_panel_bridge_add function and use it. > > > > > > It is not possible to use this helper as it is expecting drm_device > > > > It's definitely possible, just change the prototype of the function to > > take a drm_device pointer, just like any other drmm_* function. > > But, in my case, I only get the drm_device pointer once I found the > bridge pointer of panel_bridge but the actual bridge finding for > panel_bridge is happening in the drmm_panel_bridge_add definition. > Doesn't it redundant if I find the panel_bridge and pass drm_device > and panel pointer for calling drmm_panel_bridge_add? We've already discussed this, but you can't use devm_drm_of_dsi_get_bridge() from the MIPI-DSI host attach function. So fix that first, and then you'll have access to the DRM device in your driver.
On Fri, Feb 3, 2023 at 4:34 PM Maxime Ripard <maxime@cerno.tech> wrote: > > On Fri, Feb 03, 2023 at 04:28:30PM +0530, Jagan Teki wrote: > > On Fri, Feb 3, 2023 at 4:19 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > On Fri, Feb 03, 2023 at 04:13:49PM +0530, Jagan Teki wrote: > > > > On Fri, Feb 3, 2023 at 1:56 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > On Thu, Feb 02, 2023 at 10:22:42PM +0530, Jagan Teki wrote: > > > > > > Hi Maxime, > > > > > > > > > > > > On Mon, Jan 30, 2023 at 6:28 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > > > > > On Thu, Jan 26, 2023 at 08:48:48PM +0530, Jagan Teki wrote: > > > > > > > > On Thu, Jan 26, 2023 at 5:42 PM Maxime Ripard <maxime@cerno.tech> wrote: > > > > > > > > > > > > > > > > > > Hi, > > > > > > > > > > > > > > > > > > On Mon, Jan 23, 2023 at 08:41:56PM +0530, Jagan Teki wrote: > > > > > > > > > > Add devm OF helper to return the next DSI bridge in the chain. > > > > > > > > > > > > > > > > > > > > Unlike general bridge return helper devm_drm_of_get_bridge, this > > > > > > > > > > helper uses the dsi specific panel_or_bridge helper to find the > > > > > > > > > > next DSI device in the pipeline. > > > > > > > > > > > > > > > > > > > > Helper lookup a given child DSI node or a DT node's port and > > > > > > > > > > endpoint number, find the connected node and return either > > > > > > > > > > the associated struct drm_panel or drm_bridge device. > > > > > > > > > > > > > > > > > > I'm not sure that using a device managed helper is the right choice > > > > > > > > > here. The bridge will stay longer than the backing device so it will > > > > > > > > > create a use-after-free. You should probably use a DRM-managed action > > > > > > > > > here instead. > > > > > > > > > > > > > > > > Thanks for the comments. If I understand correctly we can use > > > > > > > > drmm_panel_bridge_add instead devm_drm_panel_bridge_add once we found > > > > > > > > the panel or bridge - am I correct? > > > > > > > > > > > > > > It's not that we can, it's that the devm_panel_bridge_add is unsafe: > > > > > > > when the module is removed the device will go away and all the devm > > > > > > > resources freed, but the DRM device sticks around until the last > > > > > > > application with a fd open closes that fd. > > > > > > > > > > > > Would you please check this, Here I'm trying to do > > > > > > > > > > > > 1. find a panel or bridge > > > > > > 2. if panel add it as a panel bridge > > > > > > 3. add DRM-managed action with the help of bridge->dev after step 2. > > > > > > > > > > The logic is sound in your patch > > > > > > > > > > > Didn't test the behavior, just wanted to check whether it can be a > > > > > > possibility to use bridge->dev as this dev is assigned with > > > > > > encoder->dev during the bridge attach the chain. Please check and let > > > > > > me know. > > > > > > > > > > > > struct drm_bridge *devm_drm_of_dsi_get_bridge(struct device *dev, > > > > > > struct device_node *np, > > > > > > u32 port, u32 endpoint) > > > > > > { > > > > > > struct drm_bridge *bridge; > > > > > > struct drm_panel *panel; > > > > > > int ret; > > > > > > > > > > > > ret = drm_of_dsi_find_panel_or_bridge(np, port, endpoint, > > > > > > &panel, &bridge); > > > > > > if (ret) > > > > > > return ERR_PTR(ret); > > > > > > > > > > > > if (panel) > > > > > > bridge = devm_drm_panel_bridge_add(dev, panel); > > > > > > > > > > > > if (IS_ERR(bridge)) > > > > > > return bridge; > > > > > > > > > > > > ret = drmm_add_action_or_reset(bridge->dev, > > > > > > drmm_drm_panel_bridge_release, > > > > > > bridge); > > > > > > if (ret) > > > > > > return ERR_PTR(ret); > > > > > > > > > > > > return bridge; > > > > > > } > > > > > > > > > > It's the implementation that isn't. You cannot use a devm hook to > > > > > register a KMS structure, so it's not that you should add a > > > > > drmm_add_action call, it's that you shouldn't call > > > > > devm_drm_panel_bridge_add in the first place. > > > > > > > > I think it is because the remove action helper uses > > > > drm_panel_bridge_remove instead of devm hook. > > > > > > > > > > So either you use drm_panel_bridge_add and a custom drmm action, or you > > > > > add a drmm_panel_bridge_add function and use it. > > > > > > > > It is not possible to use this helper as it is expecting drm_device > > > > > > It's definitely possible, just change the prototype of the function to > > > take a drm_device pointer, just like any other drmm_* function. > > > > But, in my case, I only get the drm_device pointer once I found the > > bridge pointer of panel_bridge but the actual bridge finding for > > panel_bridge is happening in the drmm_panel_bridge_add definition. > > Doesn't it redundant if I find the panel_bridge and pass drm_device > > and panel pointer for calling drmm_panel_bridge_add? > > We've already discussed this, but you can't use > devm_drm_of_dsi_get_bridge() from the MIPI-DSI host attach function. So > fix that first, and then you'll have access to the DRM device in your > driver. I have updated the new series with this change. Please have a look. Thanks, Jagan.
diff --git a/drivers/gpu/drm/bridge/panel.c b/drivers/gpu/drm/bridge/panel.c index e8aae3cdc73d..be281eb26356 100644 --- a/drivers/gpu/drm/bridge/panel.c +++ b/drivers/gpu/drm/bridge/panel.c @@ -499,4 +499,38 @@ struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm, } EXPORT_SYMBOL(drmm_of_get_bridge); +/** + * devm_drm_of_dsi_get_bridge - Return next DSI bridge in the chain + * @dev: device to tie the bridge lifetime to + * @np: device tree node containing encoder output ports + * @port: port in the device tree node + * @endpoint: endpoint in the device tree node + * + * Lookup a given child DSI node or a DT node's port and endpoint number, + * find the connected node and return either the associated struct drm_panel + * or drm_bridge device. Either @panel or @bridge must not be NULL. + * + * Returns a pointer to the bridge if successful, or an error pointer + * otherwise. + */ +struct drm_bridge *devm_drm_of_dsi_get_bridge(struct device *dev, + struct device_node *np, + u32 port, u32 endpoint) +{ + struct drm_bridge *bridge; + struct drm_panel *panel; + int ret; + + ret = drm_of_dsi_find_panel_or_bridge(np, port, endpoint, + &panel, &bridge); + if (ret) + return ERR_PTR(ret); + + if (panel) + bridge = devm_drm_panel_bridge_add(dev, panel); + + return bridge; +} +EXPORT_SYMBOL(devm_drm_of_dsi_get_bridge); + #endif diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index 42f86327b40a..ccb14e361d3f 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -931,6 +931,8 @@ struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, struct device_node u32 port, u32 endpoint); struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm, struct device_node *node, u32 port, u32 endpoint); +struct drm_bridge *devm_drm_of_dsi_get_bridge(struct device *dev, struct device_node *node, + u32 port, u32 endpoint); #else static inline struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, struct device_node *node,