* Re: [PATCH v6 4/8] drm: tda998x: use cec_notifier_conn_(un)register
[not found] ` <20190813110300.83025-5-darekm@google.com>
@ 2019-08-13 11:20 ` Russell King - ARM Linux admin
2019-08-14 10:52 ` Dariusz Marcinkiewicz
0 siblings, 1 reply; 6+ messages in thread
From: Russell King - ARM Linux admin @ 2019-08-13 11:20 UTC (permalink / raw)
To: Dariusz Marcinkiewicz
Cc: dri-devel, linux-media, hverkuil-cisco, David Airlie,
Daniel Vetter, open list
On Tue, Aug 13, 2019 at 01:02:36PM +0200, Dariusz Marcinkiewicz wrote:
> Use the new cec_notifier_conn_(un)register() functions to
> (un)register the notifier for the HDMI connector, and fill
> in the cec_connector_info.
>
> Changes since v2:
> - cec_notifier_phys_addr_invalidate where appropriate,
> - don't check for NULL notifier before calling
> cec_notifier_conn_unregister.
> Changes since v1:
> Add memory barrier to make sure that the notifier
> becomes visible to the irq thread once it is
> fully constructed.
>
> Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
> Tested-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> ---
> drivers/gpu/drm/i2c/tda998x_drv.c | 33 +++++++++++++++++++++----------
> 1 file changed, 23 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c
> index 61e042918a7fc..19a63ee1b3f53 100644
> --- a/drivers/gpu/drm/i2c/tda998x_drv.c
> +++ b/drivers/gpu/drm/i2c/tda998x_drv.c
> @@ -804,9 +804,14 @@ static irqreturn_t tda998x_irq_thread(int irq, void *data)
> if (lvl & CEC_RXSHPDLEV_HPD) {
> tda998x_edid_delay_start(priv);
> } else {
> + struct cec_notifier *notify;
> +
> schedule_work(&priv->detect_work);
> - cec_notifier_set_phys_addr(priv->cec_notify,
> - CEC_PHYS_ADDR_INVALID);
> +
> + notify = READ_ONCE(priv->cec_notify);
> + if (notify)
> + cec_notifier_phys_addr_invalidate(
> + notify);
> }
>
> handled = true;
> @@ -1331,6 +1336,8 @@ static int tda998x_connector_init(struct tda998x_priv *priv,
> struct drm_device *drm)
> {
> struct drm_connector *connector = &priv->connector;
> + struct cec_connector_info conn_info;
> + struct cec_notifier *notifier;
> int ret;
>
> connector->interlace_allowed = 1;
> @@ -1347,6 +1354,19 @@ static int tda998x_connector_init(struct tda998x_priv *priv,
> if (ret)
> return ret;
>
> + cec_fill_conn_info_from_drm(&conn_info, connector);
> +
> + notifier = cec_notifier_conn_register(priv->cec_glue.parent,
> + NULL, &conn_info);
> + if (!notifier)
> + return -ENOMEM;
> + /*
> + * Make sure that tda998x_irq_thread does see the notifier
> + * when it fully constructed.
> + */
> + smp_wmb();
> + priv->cec_notify = notifier;
To nitpick, this comment and the following code do not go together.
I think what you actually mean is:
* Make sure that tda998x_irq_thread sees the notifier
* only after it is fully constructed.
> +
> drm_connector_attach_encoder(&priv->connector,
> priv->bridge.encoder);
>
> @@ -1790,8 +1810,7 @@ static void tda998x_destroy(struct device *dev)
>
> i2c_unregister_device(priv->cec);
>
> - if (priv->cec_notify)
> - cec_notifier_put(priv->cec_notify);
> + cec_notifier_conn_unregister(priv->cec_notify);
This also doesn't make sense: tda998x_destroy() is the opposite of
tda998x_create(). However, tda998x_connector_destroy() is the
opposite of tda998x_connector_create().
By moving the CEC creation code into tda998x_connector_create(), you
are creating the possibility for the following sequence to mess up
CEC and leak:
tda998x_create()
tda998x_connector_create()
tda998x_connector_destroy()
tda998x_connector_create()
tda998x_connector_destroy()
tda998x_destroy()
Anything you create in tda998x_connector_create() must be cleaned up
by tda998x_connector_destroy().
> }
>
> static int tda998x_create(struct device *dev)
> @@ -1916,12 +1935,6 @@ static int tda998x_create(struct device *dev)
> cec_write(priv, REG_CEC_RXSHPDINTENA, CEC_RXSHPDLEV_HPD);
> }
>
> - priv->cec_notify = cec_notifier_get(dev);
> - if (!priv->cec_notify) {
> - ret = -ENOMEM;
> - goto fail;
> - }
> -
> priv->cec_glue.parent = dev;
> priv->cec_glue.data = priv;
> priv->cec_glue.init = tda998x_cec_hook_init;
> --
> 2.23.0.rc1.153.gdeed80330f-goog
>
>
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v6 3/8] tda9950: use cec_notifier_cec_adap_(un)register
[not found] ` <20190813110300.83025-4-darekm@google.com>
@ 2019-08-13 11:32 ` Russell King - ARM Linux admin
2019-08-13 11:44 ` Hans Verkuil
0 siblings, 1 reply; 6+ messages in thread
From: Russell King - ARM Linux admin @ 2019-08-13 11:32 UTC (permalink / raw)
To: Dariusz Marcinkiewicz
Cc: dri-devel, linux-media, hverkuil-cisco, David Airlie,
Daniel Vetter, Hans Verkuil, Kate Stewart, Allison Randal,
Thomas Gleixner, Kees Cook, Colin Ian King, open list
On Tue, Aug 13, 2019 at 01:02:35PM +0200, Dariusz Marcinkiewicz wrote:
> Use the new cec_notifier_cec_adap_(un)register() functions to
> (un)register the notifier for the CEC adapter.
>
> Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> Tested-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> ---
> drivers/gpu/drm/i2c/tda9950.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/i2c/tda9950.c b/drivers/gpu/drm/i2c/tda9950.c
> index 8039fc0d83db4..a5a75bdeb7a5f 100644
> --- a/drivers/gpu/drm/i2c/tda9950.c
> +++ b/drivers/gpu/drm/i2c/tda9950.c
> @@ -420,7 +420,8 @@ static int tda9950_probe(struct i2c_client *client,
> priv->hdmi = glue->parent;
>
> priv->adap = cec_allocate_adapter(&tda9950_cec_ops, priv, "tda9950",
> - CEC_CAP_DEFAULTS,
> + CEC_CAP_DEFAULTS |
> + CEC_CAP_CONNECTOR_INFO,
> CEC_MAX_LOG_ADDRS);
> if (IS_ERR(priv->adap))
> return PTR_ERR(priv->adap);
> @@ -457,13 +458,14 @@ static int tda9950_probe(struct i2c_client *client,
> if (ret < 0)
> return ret;
>
> - priv->notify = cec_notifier_get(priv->hdmi);
> + priv->notify = cec_notifier_cec_adap_register(priv->hdmi, NULL,
> + priv->adap);
> if (!priv->notify)
> return -ENOMEM;
>
> ret = cec_register_adapter(priv->adap, priv->hdmi);
> if (ret < 0) {
> - cec_notifier_put(priv->notify);
> + cec_notifier_cec_adap_unregister(priv->notify);
> return ret;
> }
>
> @@ -473,8 +475,6 @@ static int tda9950_probe(struct i2c_client *client,
> */
> devm_remove_action(dev, tda9950_cec_del, priv);
>
> - cec_register_cec_notifier(priv->adap, priv->notify);
> -
> return 0;
> }
>
> @@ -482,8 +482,8 @@ static int tda9950_remove(struct i2c_client *client)
> {
> struct tda9950_priv *priv = i2c_get_clientdata(client);
>
> + cec_notifier_cec_adap_unregister(priv->notify);
> cec_unregister_adapter(priv->adap);
> - cec_notifier_put(priv->notify);
It looks weird to have an unexpectedly different ordering of
unregistration from the registration path - normally, unregistration
is the reverse order of initialisation.
In the initialisation path, it seems that we register the notifier
and _then_ the adapter. Here, we unregister the notifier and then
the adapter rather than what would normally be expected. Why is
this? I suspect there will be drivers created that do this the
"normal" way round, so if this is a requirement, it needs to be made
plainly obvious.
>
> return 0;
> }
> --
> 2.23.0.rc1.153.gdeed80330f-goog
>
>
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v6 7/8] drm: dw-hdmi: use cec_notifier_conn_(un)register
[not found] ` <20190813110300.83025-8-darekm@google.com>
@ 2019-08-13 11:37 ` Hans Verkuil
2019-08-14 10:49 ` Dariusz Marcinkiewicz
0 siblings, 1 reply; 6+ messages in thread
From: Hans Verkuil @ 2019-08-13 11:37 UTC (permalink / raw)
To: Dariusz Marcinkiewicz, dri-devel, linux-media
Cc: Andrzej Hajda, Neil Armstrong, Laurent Pinchart, Jonas Karlman,
Jernej Skrabec, David Airlie, Daniel Vetter, Sam Ravnborg,
Douglas Anderson, open list
On 8/13/19 1:02 PM, Dariusz Marcinkiewicz wrote:
> Use the new cec_notifier_conn_(un)register() functions to
> (un)register the notifier for the HDMI connector, and fill in
> the cec_connector_info.
>
> Changes since v4:
> - typo fix
> Changes since v2:
> - removed unnecessary NULL check before a call to
> cec_notifier_conn_unregister,
> - use cec_notifier_phys_addr_invalidate to invalidate physical
> address.
> Changes since v1:
> Add memory barrier to make sure that the notifier
> becomes visible to the irq thread once it is fully
> constructed.
>
> Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
> Tested-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> ---
> drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 36 ++++++++++++++---------
> 1 file changed, 22 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> index 83b94b66e464e..c00184700bb9d 100644
> --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> @@ -2194,6 +2194,8 @@ static int dw_hdmi_bridge_attach(struct drm_bridge *bridge)
> struct dw_hdmi *hdmi = bridge->driver_private;
> struct drm_encoder *encoder = bridge->encoder;
> struct drm_connector *connector = &hdmi->connector;
> + struct cec_connector_info conn_info;
> + struct cec_notifier *notifier;
>
> connector->interlace_allowed = 1;
> connector->polled = DRM_CONNECTOR_POLL_HPD;
> @@ -2207,6 +2209,18 @@ static int dw_hdmi_bridge_attach(struct drm_bridge *bridge)
>
> drm_connector_attach_encoder(connector, encoder);
>
> + cec_fill_conn_info_from_drm(&conn_info, connector);
> +
> + notifier = cec_notifier_conn_register(hdmi->dev, NULL, &conn_info);
> + if (!notifier)
> + return -ENOMEM;
> + /*
> + * Make sure that dw_hdmi_irq thread does see the notifier
> + * when it fully constructed.
> + */
> + smp_wmb();
> + hdmi->cec_notifier = notifier;
> +
> return 0;
> }
>
> @@ -2373,9 +2387,13 @@ static irqreturn_t dw_hdmi_irq(int irq, void *dev_id)
> phy_stat & HDMI_PHY_HPD,
> phy_stat & HDMI_PHY_RX_SENSE);
>
> - if ((phy_stat & (HDMI_PHY_RX_SENSE | HDMI_PHY_HPD)) == 0)
> - cec_notifier_set_phys_addr(hdmi->cec_notifier,
> - CEC_PHYS_ADDR_INVALID);
> + if ((phy_stat & (HDMI_PHY_RX_SENSE | HDMI_PHY_HPD)) == 0) {
> + struct cec_notifier *notifier;
> +
> + notifier = READ_ONCE(hdmi->cec_notifier);
> + if (notifier)
> + cec_notifier_phys_addr_invalidate(notifier);
> + }
> }
>
> if (intr_stat & HDMI_IH_PHY_STAT0_HPD) {
> @@ -2693,12 +2711,6 @@ __dw_hdmi_probe(struct platform_device *pdev,
> if (ret)
> goto err_iahb;
>
> - hdmi->cec_notifier = cec_notifier_get(dev);
> - if (!hdmi->cec_notifier) {
> - ret = -ENOMEM;
> - goto err_iahb;
> - }
> -
> /*
> * To prevent overflows in HDMI_IH_FC_STAT2, set the clk regenerator
> * N and cts values before enabling phy
> @@ -2796,9 +2808,6 @@ __dw_hdmi_probe(struct platform_device *pdev,
> hdmi->ddc = NULL;
> }
>
> - if (hdmi->cec_notifier)
> - cec_notifier_put(hdmi->cec_notifier);
> -
> clk_disable_unprepare(hdmi->iahb_clk);
> if (hdmi->cec_clk)
> clk_disable_unprepare(hdmi->cec_clk);
> @@ -2820,8 +2829,7 @@ static void __dw_hdmi_remove(struct dw_hdmi *hdmi)
> /* Disable all interrupts */
> hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0);
>
> - if (hdmi->cec_notifier)
> - cec_notifier_put(hdmi->cec_notifier);
> + cec_notifier_conn_unregister(hdmi->cec_notifier);
Russell's review caused me to take another look at this series, and it made
wonder if cec_notifier_conn_unregister() shouldn't be called from bridge_detach?
Regards,
Hans
>
> clk_disable_unprepare(hdmi->iahb_clk);
> clk_disable_unprepare(hdmi->isfr_clk);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v6 3/8] tda9950: use cec_notifier_cec_adap_(un)register
2019-08-13 11:32 ` [PATCH v6 3/8] tda9950: use cec_notifier_cec_adap_(un)register Russell King - ARM Linux admin
@ 2019-08-13 11:44 ` Hans Verkuil
0 siblings, 0 replies; 6+ messages in thread
From: Hans Verkuil @ 2019-08-13 11:44 UTC (permalink / raw)
To: Russell King - ARM Linux admin, Dariusz Marcinkiewicz
Cc: dri-devel, linux-media, David Airlie, Daniel Vetter,
Hans Verkuil, Kate Stewart, Allison Randal, Thomas Gleixner,
Kees Cook, Colin Ian King, open list
On 8/13/19 1:32 PM, Russell King - ARM Linux admin wrote:
> On Tue, Aug 13, 2019 at 01:02:35PM +0200, Dariusz Marcinkiewicz wrote:
>> Use the new cec_notifier_cec_adap_(un)register() functions to
>> (un)register the notifier for the CEC adapter.
>>
>> Signed-off-by: Dariusz Marcinkiewicz <darekm@google.com>
>> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
>> Tested-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
>> ---
>> drivers/gpu/drm/i2c/tda9950.c | 12 ++++++------
>> 1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i2c/tda9950.c b/drivers/gpu/drm/i2c/tda9950.c
>> index 8039fc0d83db4..a5a75bdeb7a5f 100644
>> --- a/drivers/gpu/drm/i2c/tda9950.c
>> +++ b/drivers/gpu/drm/i2c/tda9950.c
>> @@ -420,7 +420,8 @@ static int tda9950_probe(struct i2c_client *client,
>> priv->hdmi = glue->parent;
>>
>> priv->adap = cec_allocate_adapter(&tda9950_cec_ops, priv, "tda9950",
>> - CEC_CAP_DEFAULTS,
>> + CEC_CAP_DEFAULTS |
>> + CEC_CAP_CONNECTOR_INFO,
>> CEC_MAX_LOG_ADDRS);
>> if (IS_ERR(priv->adap))
>> return PTR_ERR(priv->adap);
>> @@ -457,13 +458,14 @@ static int tda9950_probe(struct i2c_client *client,
>> if (ret < 0)
>> return ret;
>>
>> - priv->notify = cec_notifier_get(priv->hdmi);
>> + priv->notify = cec_notifier_cec_adap_register(priv->hdmi, NULL,
>> + priv->adap);
>> if (!priv->notify)
>> return -ENOMEM;
>>
>> ret = cec_register_adapter(priv->adap, priv->hdmi);
>> if (ret < 0) {
>> - cec_notifier_put(priv->notify);
>> + cec_notifier_cec_adap_unregister(priv->notify);
>> return ret;
>> }
>>
>> @@ -473,8 +475,6 @@ static int tda9950_probe(struct i2c_client *client,
>> */
>> devm_remove_action(dev, tda9950_cec_del, priv);
>>
>> - cec_register_cec_notifier(priv->adap, priv->notify);
>> -
>> return 0;
>> }
>>
>> @@ -482,8 +482,8 @@ static int tda9950_remove(struct i2c_client *client)
>> {
>> struct tda9950_priv *priv = i2c_get_clientdata(client);
>>
>> + cec_notifier_cec_adap_unregister(priv->notify);
>> cec_unregister_adapter(priv->adap);
>> - cec_notifier_put(priv->notify);
>
> It looks weird to have an unexpectedly different ordering of
> unregistration from the registration path - normally, unregistration
> is the reverse order of initialisation.
>
> In the initialisation path, it seems that we register the notifier
> and _then_ the adapter. Here, we unregister the notifier and then
> the adapter rather than what would normally be expected. Why is
> this? I suspect there will be drivers created that do this the
> "normal" way round, so if this is a requirement, it needs to be made
> plainly obvious.
It's not a requirement, it just feels better to do it in this order
since cec_unregister_adapter will in general also delete the adapter
(unless an application keeps the cec device open).
So the order is actually: allocate_adapter, then register notifier
and: unregister notifier, then unregister (and typically delete) adapter
Regards,
Hans
>
>>
>> return 0;
>> }
>> --
>> 2.23.0.rc1.153.gdeed80330f-goog
>>
>>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v6 7/8] drm: dw-hdmi: use cec_notifier_conn_(un)register
2019-08-13 11:37 ` [PATCH v6 7/8] drm: dw-hdmi: use cec_notifier_conn_(un)register Hans Verkuil
@ 2019-08-14 10:49 ` Dariusz Marcinkiewicz
0 siblings, 0 replies; 6+ messages in thread
From: Dariusz Marcinkiewicz @ 2019-08-14 10:49 UTC (permalink / raw)
To: Hans Verkuil
Cc: dri-devel, linux-media, Andrzej Hajda, Neil Armstrong,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, David Airlie,
Daniel Vetter, Sam Ravnborg, Douglas Anderson, open list
Hi.
On Tue, Aug 13, 2019 at 1:38 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>
> Russell's review caused me to take another look at this series, and it made
> wonder if cec_notifier_conn_unregister() shouldn't be called from bridge_detach?
>
I've sent out v7 of the series where unregistration is done from bridge detach.
Regards.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v6 4/8] drm: tda998x: use cec_notifier_conn_(un)register
2019-08-13 11:20 ` [PATCH v6 4/8] drm: tda998x: use cec_notifier_conn_(un)register Russell King - ARM Linux admin
@ 2019-08-14 10:52 ` Dariusz Marcinkiewicz
0 siblings, 0 replies; 6+ messages in thread
From: Dariusz Marcinkiewicz @ 2019-08-14 10:52 UTC (permalink / raw)
To: Russell King - ARM Linux admin
Cc: dri-devel, linux-media, Hans Verkuil, David Airlie,
Daniel Vetter, open list
Hello.
On Tue, Aug 13, 2019 at 1:20 PM Russell King - ARM Linux admin
<linux@armlinux.org.uk> wrote:
>
> This also doesn't make sense: tda998x_destroy() is the opposite of
> tda998x_create(). However, tda998x_connector_destroy() is the
> opposite of tda998x_connector_create().
>
> By moving the CEC creation code into tda998x_connector_create(), you
> are creating the possibility for the following sequence to mess up
> CEC and leak:
>
> tda998x_create()
> tda998x_connector_create()
> tda998x_connector_destroy()
> tda998x_connector_create()
> tda998x_connector_destroy()
> tda998x_destroy()
>
> Anything you create in tda998x_connector_create() must be cleaned up
> by tda998x_connector_destroy().
>
Thank you.
I've just sent out another revision of the patch, where registration
and deregistration is symmetric. Please take a look.
Best regards.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-08-14 10:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20190813110300.83025-1-darekm@google.com>
[not found] ` <20190813110300.83025-5-darekm@google.com>
2019-08-13 11:20 ` [PATCH v6 4/8] drm: tda998x: use cec_notifier_conn_(un)register Russell King - ARM Linux admin
2019-08-14 10:52 ` Dariusz Marcinkiewicz
[not found] ` <20190813110300.83025-4-darekm@google.com>
2019-08-13 11:32 ` [PATCH v6 3/8] tda9950: use cec_notifier_cec_adap_(un)register Russell King - ARM Linux admin
2019-08-13 11:44 ` Hans Verkuil
[not found] ` <20190813110300.83025-8-darekm@google.com>
2019-08-13 11:37 ` [PATCH v6 7/8] drm: dw-hdmi: use cec_notifier_conn_(un)register Hans Verkuil
2019-08-14 10:49 ` Dariusz Marcinkiewicz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).