Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752908AbdLUPAg (ORCPT ); Thu, 21 Dec 2017 10:00:36 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:49531 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751426AbdLUPAc (ORCPT ); Thu, 21 Dec 2017 10:00:32 -0500 From: Philippe CORNU To: Nickey Yang , "robh+dt@kernel.org" , "heiko@sntech.de" , "mark.rutland@arm.com" , "airlied@linux.ie" CC: "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "linux-rockchip@lists.infradead.org" , "laurent.pinchart@ideasonboard.com" , "seanpaul@chromium.org" , "briannorris@chromium.org" , "mka@chromium.org" , "hoegsberg@gmail.com" , "architt@codeaurora.org" , Yannick FERTRE , "hl@rock-chips.com" , "zyw@rock-chips.com" , "xbl@rock-chips.com" Subject: Re: [PATCH v7 1/3] drm/bridge/synopsys: dsi: stop clobbering drvdata Thread-Topic: [PATCH v7 1/3] drm/bridge/synopsys: dsi: stop clobbering drvdata Thread-Index: AQHTcuYc/ZYp8zM+PECt/cO/JxY79qNN4h4A Date: Thu, 21 Dec 2017 14:59:50 +0000 Message-ID: <0c7d4909-b926-1370-2847-c801172248c9@st.com> References: <1513041045-12808-1-git-send-email-nickey.yang@rock-chips.com> <1513041045-12808-2-git-send-email-nickey.yang@rock-chips.com> In-Reply-To: <1513041045-12808-2-git-send-email-nickey.yang@rock-chips.com> Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.75.127.51] Content-Type: text/plain; charset="utf-8" Content-ID: <3F8EF6405205F1428C45680506D48A2C@st.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-21_07:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id vBLF0eDp022183 Content-Length: 7617 Lines: 223 Hi Nickey, On 12/12/2017 02:10 AM, Nickey Yang wrote: > From: Brian Norris > > Bridge drivers/helpers shouldn't be clobbering the drvdata, since a > parent driver might need to own this. Instead, let's return our > 'dw_mipi_dsi' object and have callers pass that back to us for removal. > > Signed-off-by: Brian Norris > Signed-off-by: Nickey Yang > Link:https://patchwork.kernel.org/patch/10078493/ > > --- > Changes > > v4: > - Add From tag,update subject line > - keep patch "drm/stm: dsi: Adjust dw_mipi_dsi_probe and remove" > in this piece together. > > v5: > - remove Review & Ack tag > - fix remove() directly referencing the static > dw_mipi_dsi_stm_plat_data struct. > > v7: > - add missing platform_set_drvdata in stm part. > > drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 36 ++++++++++----------------- > drivers/gpu/drm/stm/dw_mipi_dsi-stm.c | 12 ++++++--- > include/drm/bridge/dw_mipi_dsi.h | 17 ++++++++----- > 3 files changed, 32 insertions(+), 33 deletions(-) > > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c b/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c > index d9cca4f..c39c7dc 100644 > --- a/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c > +++ b/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c > @@ -922,8 +922,6 @@ static int dw_mipi_dsi_bridge_attach(struct drm_bridge *bridge) > dsi->bridge.of_node = pdev->dev.of_node; > #endif > > - dev_set_drvdata(dev, dsi); > - > return dsi; > } > > @@ -935,23 +933,16 @@ static void __dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi) > /* > * Probe/remove API, used from platforms based on the DRM bridge API. > */ > -int dw_mipi_dsi_probe(struct platform_device *pdev, > - const struct dw_mipi_dsi_plat_data *plat_data) > +struct dw_mipi_dsi * > +dw_mipi_dsi_probe(struct platform_device *pdev, > + const struct dw_mipi_dsi_plat_data *plat_data) > { > - struct dw_mipi_dsi *dsi; > - > - dsi = __dw_mipi_dsi_probe(pdev, plat_data); > - if (IS_ERR(dsi)) > - return PTR_ERR(dsi); > - > - return 0; > + return __dw_mipi_dsi_probe(pdev, plat_data); > } > EXPORT_SYMBOL_GPL(dw_mipi_dsi_probe); > > -void dw_mipi_dsi_remove(struct platform_device *pdev) > +void dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi) > { > - struct dw_mipi_dsi *dsi = platform_get_drvdata(pdev); > - > mipi_dsi_host_unregister(&dsi->dsi_host); > > __dw_mipi_dsi_remove(dsi); > @@ -961,31 +952,30 @@ void dw_mipi_dsi_remove(struct platform_device *pdev) > /* > * Bind/unbind API, used from platforms based on the component framework. > */ > -int dw_mipi_dsi_bind(struct platform_device *pdev, struct drm_encoder *encoder, > - const struct dw_mipi_dsi_plat_data *plat_data) > +struct dw_mipi_dsi * > +dw_mipi_dsi_bind(struct platform_device *pdev, struct drm_encoder *encoder, > + const struct dw_mipi_dsi_plat_data *plat_data) > { > struct dw_mipi_dsi *dsi; > int ret; > > dsi = __dw_mipi_dsi_probe(pdev, plat_data); > if (IS_ERR(dsi)) > - return PTR_ERR(dsi); > + return dsi; > > ret = drm_bridge_attach(encoder, &dsi->bridge, NULL); > if (ret) { > - dw_mipi_dsi_remove(pdev); > + dw_mipi_dsi_remove(dsi); > DRM_ERROR("Failed to initialize bridge with drm\n"); > - return ret; > + return ERR_PTR(ret); > } > > - return 0; > + return dsi; > } > EXPORT_SYMBOL_GPL(dw_mipi_dsi_bind); > > -void dw_mipi_dsi_unbind(struct device *dev) > +void dw_mipi_dsi_unbind(struct dw_mipi_dsi *dsi) > { > - struct dw_mipi_dsi *dsi = dev_get_drvdata(dev); > - > __dw_mipi_dsi_remove(dsi); > } > EXPORT_SYMBOL_GPL(dw_mipi_dsi_unbind); > diff --git a/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c b/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c > index e5b6310..c1ed691 100644 > --- a/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c > +++ b/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c > @@ -66,6 +66,7 @@ enum dsi_color { > struct dw_mipi_dsi_stm { > void __iomem *base; > struct clk *pllref_clk; > + struct dw_mipi_dsi *dmd; > }; > > static inline void dsi_write(struct dw_mipi_dsi_stm *dsi, u32 reg, u32 val) > @@ -290,6 +291,8 @@ static int dw_mipi_dsi_stm_probe(struct platform_device *pdev) > if (!dsi) > return -ENOMEM; > > + platform_set_drvdata(pdev, dsi); > + Why don't you simply use the original patch from Brian. With your last update, platform_set_drvdata() is called early during the stm_probe() and this is not the "classic" way: most of the time we prefer calling platform_set_drvdata() at the end of the probe (or as close as possible of the end of the probe). I took few minutes to look into drm directory and it seems to be the classic way for most of the drivers... > res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > if (!res) { > DRM_ERROR("Unable to get resource\n"); > @@ -318,10 +321,11 @@ static int dw_mipi_dsi_stm_probe(struct platform_device *pdev) > dw_mipi_dsi_stm_plat_data.base = dsi->base; > dw_mipi_dsi_stm_plat_data.priv_data = dsi; > > - ret = dw_mipi_dsi_probe(pdev, &dw_mipi_dsi_stm_plat_data); > - if (ret) { > + dsi->dmd = dw_mipi_dsi_probe(pdev, &dw_mipi_dsi_stm_plat_data); > + if (IS_ERR(dsi->dmd)) { > DRM_ERROR("Failed to initialize mipi dsi host\n"); > clk_disable_unprepare(dsi->pllref_clk); > + return PTR_ERR(dsi->dmd); > } > > return ret; Moreover, I do prefer the "return 0;" from the Brian original version because "ret" here is far from its usage (from clk_prepare_enable()) with this new patch. So, once again, I really prefer the Brian original version, on which you already got my Tested-By & Acked-by. Is there any reason why you did not use the original patch? Many thanks, Philippe :-) Note: I will be ooo next 2 weeks. > @@ -329,10 +333,10 @@ static int dw_mipi_dsi_stm_probe(struct platform_device *pdev) > > static int dw_mipi_dsi_stm_remove(struct platform_device *pdev) > { > - struct dw_mipi_dsi_stm *dsi = dw_mipi_dsi_stm_plat_data.priv_data; > + struct dw_mipi_dsi_stm *dsi = platform_get_drvdata(pdev); > > clk_disable_unprepare(dsi->pllref_clk); > - dw_mipi_dsi_remove(pdev); > + dw_mipi_dsi_remove(dsi->dmd); > > return 0; > } > diff --git a/include/drm/bridge/dw_mipi_dsi.h b/include/drm/bridge/dw_mipi_dsi.h > index 9b30fec..d9c6d54 100644 > --- a/include/drm/bridge/dw_mipi_dsi.h > +++ b/include/drm/bridge/dw_mipi_dsi.h > @@ -10,6 +10,8 @@ > #ifndef __DW_MIPI_DSI__ > #define __DW_MIPI_DSI__ > > +struct dw_mipi_dsi; > + > struct dw_mipi_dsi_phy_ops { > int (*init)(void *priv_data); > int (*get_lane_mbps)(void *priv_data, struct drm_display_mode *mode, > @@ -29,11 +31,14 @@ struct dw_mipi_dsi_plat_data { > void *priv_data; > }; > > -int dw_mipi_dsi_probe(struct platform_device *pdev, > - const struct dw_mipi_dsi_plat_data *plat_data); > -void dw_mipi_dsi_remove(struct platform_device *pdev); > -int dw_mipi_dsi_bind(struct platform_device *pdev, struct drm_encoder *encoder, > - const struct dw_mipi_dsi_plat_data *plat_data); > -void dw_mipi_dsi_unbind(struct device *dev); > +struct dw_mipi_dsi *dw_mipi_dsi_probe(struct platform_device *pdev, > + const struct dw_mipi_dsi_plat_data > + *plat_data); > +void dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi); > +struct dw_mipi_dsi *dw_mipi_dsi_bind(struct platform_device *pdev, > + struct drm_encoder *encoder, > + const struct dw_mipi_dsi_plat_data > + *plat_data); > +void dw_mipi_dsi_unbind(struct dw_mipi_dsi *dsi); > > #endif /* __DW_MIPI_DSI__ */ >