max9286: Refactor V4L2 support to prevent EPROBE_DEFER failures
Subsystems (2)
Kieran Bingham
maintainercover max9286: Refactor V4L2 support to prevent EPROBE_DEFER failures
Currently the V4L2 notifiers are registered during DT parsing.
Move this handling and all other V4L2 code to two distinct implementations and contained higher in the source code. This simplifies the hardware initialisation functions, and makes error paths and cleanup much easier to parse.
I hope to squash these two patches into the max9286 and then post a v7, along with Jacopo's RDACM20 split work, with an aim to hopefully getting upstream integration.
max9286 v7 changlog currently looks like:
v7:
[Kieran]
- Ensure powerdown lines are optional
- Add a 4ms power-up delay
- Add max9286_check_config_link() to core
- Add GPIO chip controller for GPIO0OUT and GPIO1OUT
- Fix GPIO registration
[Jacopo]
- Remove redundanct MAXIM_I2C_SPEED macros
- Move notifiers operations
- Add delay after reverse channel reconfiguration
- Move link setup to completion
- Fix up max9286_check_config_link() implementation
- Remove redundant dual configuration of reverse channel
Kieran Bingham (2):
max9286: Split out async registration
max9286: Collect all V4L2 registrations
drivers/media/i2c/max9286.c | 205 ++++++++++++++++++++++-------------- 1 file changed, 127 insertions(+), 78 deletions(-)
Signature · 1 line
2.20.1
Kieran Bingham
maintainerPATCH 1/2 max9286: Split out async registration
Move all the V4L2 Subdev Async registration so that it can only happen once we know we will not need to -EPROBE_DEFER...
--- drivers/media/i2c/max9286.c | 88 +++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 33 deletions(-)
drivers/media/i2c/max9286.c +55 -33
@@ -503,6 +503,49 @@ static const struct v4l2_async_notifier_operations max9286_notify_ops = { .unbind = max9286_notify_unbind, }; +static int max9286_v4l2_async_register (struct max9286_priv *priv) +{ +struct device *dev = &priv->client->dev; +struct max9286_source *source =NULL ; +int ret; + +v4l2_async_notifier_init (&priv->notifier); + +for_each_source (priv, source) { +unsigned int i =to_index (priv, source); + +dev_err (dev,"Registering v4l2-async for source %d\n" , i); + + source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; + source->asd.match.fwnode = source->fwnode; + + ret =v4l2_async_notifier_add_subdev (&priv->notifier, + &source->asd); +if (ret) { +dev_err (dev,"Failed to add subdev for source %d" , i); +v4l2_async_notifier_cleanup (&priv->notifier); +return ret; + } + } + + priv->notifier.ops = &max9286_notify_ops; + + ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); +if (ret) { +dev_err (dev,"Failed to register subdev_notifier" ); +v4l2_async_notifier_cleanup (&priv->notifier); +return ret; + } + +return 0 ; +} + +static void max9286_v4l2_async_unregister (struct max9286_priv *priv) +{ +v4l2_async_notifier_unregister (&priv->notifier); +v4l2_async_notifier_cleanup (&priv->notifier); +} +static int max9286_s_stream (struct v4l2_subdev *sd,int enable) {struct max9286_priv *priv =sd_to_max9286 (sd);
@@ -870,6 +913,13 @@ static int max9286_init(struct device *dev) goto err_regulator; } +/* Register v4l2 async notifiers */ + ret =max9286_v4l2_async_register (priv); +if (ret) { +dev_err (dev,"Unable to register V4L2 async notifiers\n" ); + goto err_regulator; + } +v4l2_i2c_subdev_init (&priv->sd, client, &max9286_subdev_ops); priv->sd.internal_ops = &max9286_subdev_internal_ops; priv->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;
@@ -884,7 +934,7 @@ static int max9286_init(struct device *dev) priv->sd.ctrl_handler = &priv->ctrls; ret = priv->ctrls.error;if (ret) - goto err_regulator; + goto err_async; priv->sd.entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ;
@@ -927,6 +977,8 @@ static int max9286_init(struct device *dev)max9286_i2c_mux_close (priv); err_put_node:fwnode_handle_put (ep); +err_async: +max9286_v4l2_async_unregister (priv); err_regulator:regulator_disable (priv->regulator); priv->poc_enabled = false;
@@ -938,14 +990,6 @@ static void max9286_cleanup_dt(struct max9286_priv *priv) {struct max9286_source *source; -/* -* Not strictly part of the DT, but the notifier is registered during -* max9286_parse_dt(), and the notifier holds references to the fwnodes -* thus the cleanup is here to mirror the registration. -*/ -v4l2_async_notifier_unregister (&priv->notifier); -v4l2_async_notifier_cleanup (&priv->notifier); -for_each_source (priv, source) {fwnode_handle_put (source->fwnode); source->fwnode =NULL ;
@@ -958,7 +1002,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)struct device_node *i2c_mux;struct device_node *node =NULL ;unsigned int i2c_mux_mask =0 ; -int ret;of_node_get (dev->of_node); i2c_mux =of_find_node_by_name (dev->of_node,"i2c-mux" );
@@ -986,8 +1029,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)of_node_put (node);of_node_put (i2c_mux); -v4l2_async_notifier_init (&priv->notifier); -/* Parse the endpoints */ for_each_endpoint_of_node (dev->of_node, node) {struct max9286_source *source;
@@ -1056,34 +1097,14 @@ static int max9286_parse_dt(struct max9286_priv *priv)continue ; } - source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; - source->asd.match.fwnode = source->fwnode; - - ret =v4l2_async_notifier_add_subdev (&priv->notifier, - &source->asd); -if (ret) { -v4l2_async_notifier_cleanup (&priv->notifier); -of_node_put (node); -return ret; - } - priv->source_mask |=BIT (ep.port); priv->nsources++; }of_node_put (node); -/* Do not register the subdev notifier if there are no devices. */ -if (!priv->nsources) -return 0 ; - priv->route_mask = priv->source_mask; - priv->notifier.ops = &max9286_notify_ops; - - ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); -if (ret) -v4l2_async_notifier_cleanup (&priv->notifier); -return ret; +return 0 ; }static int max9286_probe (struct i2c_client *client)
@@ -1182,6 +1203,7 @@ static int max9286_remove(struct i2c_client *client)fwnode_handle_put (priv->sd.fwnode);v4l2_async_unregister_subdev (&priv->sd); +max9286_v4l2_async_unregister (priv);if (priv->poc_enabled)regulator_disable (priv->regulator);
Signature · 1 line
2.20.1
Kieran Bingham
maintainerRe: [PATCH 1/2] max9286: Split out async registration
Hi Me,
Quoted 18 lines · Kieran Bingham
Move all the V4L2 Subdev Async registration so that it can only happen once we know we will not need to -EPROBE_DEFER...
Signed-off-by Kieran Bingham <[email protected]>--- drivers/media/i2c/max9286.c | 88 +++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 33 deletions(-)drivers/media/i2c/max9286.c +2
-0@@ -503,6 +503,49 @@ static const struct v4l2_async_notifier_operations max9286_notify_ops = { .unbind = max9286_notify_unbind, }; +static int max9286_v4l2_async_register (struct max9286_priv *priv) +{
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 517
Quoted 10 lines
drivers/media/i2c/max9286.c +10
-0+struct device *dev = &priv->client->dev; +struct max9286_source *source =NULL ; +int ret; + +v4l2_async_notifier_init (&priv->notifier); + +for_each_source (priv, source) { +unsigned int i =to_index (priv, source); + +dev_err (dev,"Registering v4l2-async for source %d\n" , i);
Debug line, can be removed.
Quoted 143 lines
drivers/media/i2c/max9286.c +43
-33+ + source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; + source->asd.match.fwnode = source->fwnode; + + ret =v4l2_async_notifier_add_subdev (&priv->notifier, + &source->asd); +if (ret) { +dev_err (dev,"Failed to add subdev for source %d" , i); +v4l2_async_notifier_cleanup (&priv->notifier); +return ret; + } + } + + priv->notifier.ops = &max9286_notify_ops; + + ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); +if (ret) { +dev_err (dev,"Failed to register subdev_notifier" ); +v4l2_async_notifier_cleanup (&priv->notifier); +return ret; + } + +return 0 ; +} + +static void max9286_v4l2_async_unregister (struct max9286_priv *priv) +{ +v4l2_async_notifier_unregister (&priv->notifier); +v4l2_async_notifier_cleanup (&priv->notifier); +} +static int max9286_s_stream (struct v4l2_subdev *sd,int enable) {struct max9286_priv *priv =sd_to_max9286 (sd);@@ -870,6 +913,13 @@ static int max9286_init(struct device *dev) goto err_regulator; } +/* Register v4l2 async notifiers */ + ret =max9286_v4l2_async_register (priv); +if (ret) { +dev_err (dev,"Unable to register V4L2 async notifiers\n" ); + goto err_regulator; + } +v4l2_i2c_subdev_init (&priv->sd, client, &max9286_subdev_ops); priv->sd.internal_ops = &max9286_subdev_internal_ops; priv->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;@@ -884,7 +934,7 @@ static int max9286_init(struct device *dev) priv->sd.ctrl_handler = &priv->ctrls; ret = priv->ctrls.error;if (ret) - goto err_regulator; + goto err_async; priv->sd.entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ;@@ -927,6 +977,8 @@ static int max9286_init(struct device *dev)max9286_i2c_mux_close (priv); err_put_node:fwnode_handle_put (ep); +err_async: +max9286_v4l2_async_unregister (priv); err_regulator:regulator_disable (priv->regulator); priv->poc_enabled = false;@@ -938,14 +990,6 @@ static void max9286_cleanup_dt(struct max9286_priv *priv) {struct max9286_source *source; -/* -* Not strictly part of the DT, but the notifier is registered during -* max9286_parse_dt(), and the notifier holds references to the fwnodes -* thus the cleanup is here to mirror the registration. -*/ -v4l2_async_notifier_unregister (&priv->notifier); -v4l2_async_notifier_cleanup (&priv->notifier); -for_each_source (priv, source) {fwnode_handle_put (source->fwnode); source->fwnode =NULL ;@@ -958,7 +1002,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)struct device_node *i2c_mux;struct device_node *node =NULL ;unsigned int i2c_mux_mask =0 ; -int ret;of_node_get (dev->of_node); i2c_mux =of_find_node_by_name (dev->of_node,"i2c-mux" );@@ -986,8 +1029,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)of_node_put (node);of_node_put (i2c_mux); -v4l2_async_notifier_init (&priv->notifier); -/* Parse the endpoints */ for_each_endpoint_of_node (dev->of_node, node) {struct max9286_source *source;@@ -1056,34 +1097,14 @@ static int max9286_parse_dt(struct max9286_priv *priv)continue ; } - source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; - source->asd.match.fwnode = source->fwnode; - - ret =v4l2_async_notifier_add_subdev (&priv->notifier, - &source->asd); -if (ret) { -v4l2_async_notifier_cleanup (&priv->notifier); -of_node_put (node); -return ret; - } - priv->source_mask |=BIT (ep.port); priv->nsources++; }of_node_put (node); -/* Do not register the subdev notifier if there are no devices. */ -if (!priv->nsources) -return 0 ; - priv->route_mask = priv->source_mask; - priv->notifier.ops = &max9286_notify_ops; - - ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); -if (ret) -v4l2_async_notifier_cleanup (&priv->notifier); -return ret; +return 0 ; }static int max9286_probe (struct i2c_client *client)@@ -1182,6 +1203,7 @@ static int max9286_remove(struct i2c_client *client)fwnode_handle_put (priv->sd.fwnode);v4l2_async_unregister_subdev (&priv->sd); +max9286_v4l2_async_unregister (priv);if (priv->poc_enabled)regulator_disable (priv->regulator);
Re: [PATCH 1/2] max9286: Split out async registration
In reply to Kieran BinghamHi Kieran,
very nice thanks for handling this
Just a few minors
Quoted 13 lines · Kieran Bingham
Move all the V4L2 Subdev Async registration so that it can only happen once we know we will not need to -EPROBE_DEFER...
Signed-off-by Kieran Bingham <[email protected]>--- drivers/media/i2c/max9286.c | 88 +++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 33 deletions(-)drivers/media/i2c/max9286.c +0
-0
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 506
Quoted 4 lines
drivers/media/i2c/max9286.c +1
-0@@ -503,6 +503,49 @@ static const struct v4l2_async_notifier_operations max9286_notify_ops = { .unbind = max9286_notify_unbind, }; +static int max9286_v4l2_async_register (struct max9286_priv *priv)
Could you capture in the function name this actually deals with notifiers ? Like max9286_notifier_register() or similar...
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 511
Quoted 5 lines
drivers/media/i2c/max9286.c +5
-0+{ +struct device *dev = &priv->client->dev; +struct max9286_source *source =NULL ; +int ret; +
Do we want to init and register the notifier if there are no sources connected ? I would keep
if (!priv->nsources) return 0;
here or in the caller.
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 517
Quoted 6 lines
drivers/media/i2c/max9286.c +6
-0+v4l2_async_notifier_init (&priv->notifier); + +for_each_source (priv, source) { +unsigned int i =to_index (priv, source); + +dev_err (dev,"Registering v4l2-async for source %d\n" , i);
dev_err ?
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 526
Quoted 9 lines
drivers/media/i2c/max9286.c +9
-0+ + source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; + source->asd.match.fwnode = source->fwnode; + + ret =v4l2_async_notifier_add_subdev (&priv->notifier, + &source->asd); +if (ret) { +dev_err (dev,"Failed to add subdev for source %d" , i); +v4l2_async_notifier_cleanup (&priv->notifier);
v4l2_async_notifier_cleanup() does fwnode_handle_put() on the async subdevs registered to the notifier but not yet completed. All the other sources have to be put as well I think.
How to do so might be not nice, as you would need to keep track of which sources have been registered to the notifier already and put the other ones in the error path.
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 536
Quoted 10 lines
drivers/media/i2c/max9286.c +10
-0+return ret; + } + } + + priv->notifier.ops = &max9286_notify_ops; + + ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); +if (ret) { +dev_err (dev,"Failed to register subdev_notifier" ); +v4l2_async_notifier_cleanup (&priv->notifier);
Here it's fine to call notifier_cleanup()
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 546
Quoted 10 lines
drivers/media/i2c/max9286.c +10
-0+return ret; + } + +return 0 ; +} + +static void max9286_v4l2_async_unregister (struct max9286_priv *priv) +{ +v4l2_async_notifier_unregister (&priv->notifier); +v4l2_async_notifier_cleanup (&priv->notifier);
I would first cleanup() then unregister() even if they deal with two different sets of asds (done and registred-but-not-yet-done ones).
Quoted 41 lines
drivers/media/i2c/max9286.c +12
-1+} +static int max9286_s_stream (struct v4l2_subdev *sd,int enable) {struct max9286_priv *priv =sd_to_max9286 (sd);@@ -870,6 +913,13 @@ static int max9286_init(struct device *dev) goto err_regulator; } +/* Register v4l2 async notifiers */ + ret =max9286_v4l2_async_register (priv); +if (ret) { +dev_err (dev,"Unable to register V4L2 async notifiers\n" ); + goto err_regulator; + } +v4l2_i2c_subdev_init (&priv->sd, client, &max9286_subdev_ops); priv->sd.internal_ops = &max9286_subdev_internal_ops; priv->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;@@ -884,7 +934,7 @@ static int max9286_init(struct device *dev) priv->sd.ctrl_handler = &priv->ctrls; ret = priv->ctrls.error;if (ret) - goto err_regulator; + goto err_async; priv->sd.entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ;@@ -927,6 +977,8 @@ static int max9286_init(struct device *dev)max9286_i2c_mux_close (priv); err_put_node:fwnode_handle_put (ep); +err_async: +max9286_v4l2_async_unregister (priv); err_regulator:regulator_disable (priv->regulator); priv->poc_enabled = false;@@ -938,14 +990,6 @@ static void max9286_cleanup_dt(struct max9286_priv *priv) {struct max9286_source *source;
drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 994
Quoted 10 lines
drivers/media/i2c/max9286.c +0
-8-/* -* Not strictly part of the DT, but the notifier is registered during -* max9286_parse_dt(), and the notifier holds references to the fwnodes -* thus the cleanup is here to mirror the registration. -*/ -v4l2_async_notifier_unregister (&priv->notifier); -v4l2_async_notifier_cleanup (&priv->notifier); -for_each_source (priv, source) {fwnode_handle_put (source->fwnode);
Wasn't this a double fwnode_handle_put() ? We called notifier_cleanup() and then put all sources again manually.
I don't see one more get() when the asd gets registered to the notifier with v4l2_async_notifier_add_subdev() so I'm afraid this would result in a duplicated put(). Am I wrong ?
It was there already, but I think it happens in this patch as
well: if max9286_init() fails calls max9286_v4l2_unregister() which then calls max9286_v4l2_async_unregister() which put all the not-yet-completed subdevs by calling v4l2_async_notifier_cleanup(). Then in the probe() function error path we then call max9286_cleanup_dt() which puts again all the registered sources regardless of their completed status.
I would call max9286_cleanup_dt() only if max9286_init() has not been called yet. If we get to register subdevs to the notifier, I would then provide a function that calls v4l2_async_notifier_cleanup() and then manually puts all sources not yet registered. I'm afraid this would need to keep a status flag in the source, unless you have a more elegant solution.
Thanks
j
Quoted 65 lines
drivers/media/i2c/max9286.c +2
-25source->fwnode =NULL ;@@ -958,7 +1002,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)struct device_node *i2c_mux;struct device_node *node =NULL ;unsigned int i2c_mux_mask =0 ; -int ret;of_node_get (dev->of_node); i2c_mux =of_find_node_by_name (dev->of_node,"i2c-mux" );@@ -986,8 +1029,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)of_node_put (node);of_node_put (i2c_mux); -v4l2_async_notifier_init (&priv->notifier); -/* Parse the endpoints */ for_each_endpoint_of_node (dev->of_node, node) {struct max9286_source *source;@@ -1056,34 +1097,14 @@ static int max9286_parse_dt(struct max9286_priv *priv)continue ; } - source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; - source->asd.match.fwnode = source->fwnode; - - ret =v4l2_async_notifier_add_subdev (&priv->notifier, - &source->asd); -if (ret) { -v4l2_async_notifier_cleanup (&priv->notifier); -of_node_put (node); -return ret; - } - priv->source_mask |=BIT (ep.port); priv->nsources++; }of_node_put (node); -/* Do not register the subdev notifier if there are no devices. */ -if (!priv->nsources) -return 0 ; - priv->route_mask = priv->source_mask; - priv->notifier.ops = &max9286_notify_ops; - - ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); -if (ret) -v4l2_async_notifier_cleanup (&priv->notifier); -return ret; +return 0 ; }static int max9286_probe (struct i2c_client *client)@@ -1182,6 +1203,7 @@ static int max9286_remove(struct i2c_client *client)fwnode_handle_put (priv->sd.fwnode);v4l2_async_unregister_subdev (&priv->sd); +max9286_v4l2_async_unregister (priv);if (priv->poc_enabled)regulator_disable (priv->regulator); --2.20.1
Kieran Bingham
maintainerRe: [PATCH 1/2] max9286: Split out async registration
Hi Jacopo,
Quoted 2 lines · Jacopo Mondi
Hi Kieran,
very nice thanks for handling this
:-)
Quoted 1 line
Just a few minors
:-s hehe
Quoted 18 lines · Kieran Bingham
Quoted 16 lines
Move all the V4L2 Subdev Async registration so that it can only happen once we know we will not need to -EPROBE_DEFER...
Signed-off-by Kieran Bingham <[email protected]>--- drivers/media/i2c/max9286.c | 88 +++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 33 deletions(-)drivers/media/i2c/max9286.c +0
-0@@ -503,6 +503,49 @@ static const struct v4l2_async_notifier_operations max9286_notify_ops = { .unbind = max9286_notify_unbind, };
Quoted 4 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 506
Quoted 1 line
drivers/media/i2c/max9286.c +1
-0+static int max9286_v4l2_async_register (struct max9286_priv *priv)Could you capture in the function name this actually deals with notifiers ? Like
max9286_notifier_register()or similar...
I'd like to keep the 'v4l2' in there somewhere...
max9286_v4l2_notifier_register() ?
But then maybe even that could be confused with the notifiers/async handling for the max9286 itself.
My aim was that max9286_v4l2_async_{un,}register() dealt with subdevices connected to the max9286 only ...
For ~20 lines of code, it could be inlined up a level into max9286_v4l2_register() but I do perhaps like trying to keep the symmetry clean somehow.
<scratch that - below tells me not to inline>
Quoted 9 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 511
Quoted 5 lines
drivers/media/i2c/max9286.c +5
-0+{ +struct device *dev = &priv->client->dev; +struct max9286_source *source =NULL ; +int ret; +Do we want to init and register the notifier if there are no sources connected ? I would keep
Quoted 4 lines
if (!priv->nsources) return 0;here or in the caller.
Ah yes, I had thought about that but clearly not acted upon it much.
If we know there is nothing to notify us, I guess we won't expect any need to register the notifications!
Although this would certainly mean keeping the sources registration in their own functions.
Quoted 10 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 517
Quoted 7 lines
drivers/media/i2c/max9286.c +6
-0+v4l2_async_notifier_init (&priv->notifier); + +for_each_source (priv, source) { +unsigned int i =to_index (priv, source); + +dev_err (dev,"Registering v4l2-async for source %d\n" , i);
dev_err?
Already removed, left over debug print.
Quoted 14 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 526
Quoted 9 lines
drivers/media/i2c/max9286.c +9
-0+ + source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; + source->asd.match.fwnode = source->fwnode; + + ret =v4l2_async_notifier_add_subdev (&priv->notifier, + &source->asd); +if (ret) { +dev_err (dev,"Failed to add subdev for source %d" , i); +v4l2_async_notifier_cleanup (&priv->notifier);
v4l2_async_notifier_cleanup()doesfwnode_handle_put()on the async subdevs registered to the notifier but not yet completed. All the other sources have to be put as well I think.
Quoted 3 lines
How to do so might be not nice, as you would need to keep track of which sources have been registered to the notifier already and put the other ones in the error path.
Or can we move all fwnode refcounting back to cleanup_dt perhaps?
I'll have a look.
Quoted 14 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 536
Quoted 11 lines
drivers/media/i2c/max9286.c +10
-0+return ret; + } + } + + priv->notifier.ops = &max9286_notify_ops; + + ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); +if (ret) { +dev_err (dev,"Failed to register subdev_notifier" ); +v4l2_async_notifier_cleanup (&priv->notifier);Here it's fine to call
notifier_cleanup()
Quoted 13 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 546
Quoted 10 lines
drivers/media/i2c/max9286.c +10
-0+return ret; + } + +return 0 ; +} + +static void max9286_v4l2_async_unregister (struct max9286_priv *priv) +{ +v4l2_async_notifier_unregister (&priv->notifier); +v4l2_async_notifier_cleanup (&priv->notifier);I would first
cleanup()thenunregister()even if they deal with two different sets of asds (done and registred-but-not-yet-done ones).
Looking at max9286_v4l2_async_register(), the v4l2_async_subdev_notifier_register() call is last.
Therefore that would make it the first thing to cleanup in the reverse procedure?
Quoted 56 lines
Quoted 42 lines
drivers/media/i2c/max9286.c +12
-1+} +static int max9286_s_stream (struct v4l2_subdev *sd,int enable) {struct max9286_priv *priv =sd_to_max9286 (sd);@@ -870,6 +913,13 @@ static int max9286_init(struct device *dev) goto err_regulator; } +/* Register v4l2 async notifiers */ + ret =max9286_v4l2_async_register (priv); +if (ret) { +dev_err (dev,"Unable to register V4L2 async notifiers\n" ); + goto err_regulator; + } +v4l2_i2c_subdev_init (&priv->sd, client, &max9286_subdev_ops); priv->sd.internal_ops = &max9286_subdev_internal_ops; priv->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;@@ -884,7 +934,7 @@ static int max9286_init(struct device *dev) priv->sd.ctrl_handler = &priv->ctrls; ret = priv->ctrls.error;if (ret) - goto err_regulator; + goto err_async; priv->sd.entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ;@@ -927,6 +977,8 @@ static int max9286_init(struct device *dev)max9286_i2c_mux_close (priv); err_put_node:fwnode_handle_put (ep); +err_async: +max9286_v4l2_async_unregister (priv); err_regulator:regulator_disable (priv->regulator); priv->poc_enabled = false;@@ -938,14 +990,6 @@ static void max9286_cleanup_dt(struct max9286_priv *priv) {struct max9286_source *source;drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 994
Quoted 10 lines
drivers/media/i2c/max9286.c +0
-8-/* -* Not strictly part of the DT, but the notifier is registered during -* max9286_parse_dt(), and the notifier holds references to the fwnodes -* thus the cleanup is here to mirror the registration. -*/ -v4l2_async_notifier_unregister (&priv->notifier); -v4l2_async_notifier_cleanup (&priv->notifier); -for_each_source (priv, source) {fwnode_handle_put (source->fwnode);Wasn't this a double
fwnode_handle_put()? We callednotifier_cleanup()and then put all sources again manually.
Quoted 3 lines
I don't see one more
get()when the asd gets registered to the notifier withv4l2_async_notifier_add_subdev()so I'm afraid this would result in a duplicatedput(). Am I wrong ?
Agh, all the implicit transfers of ownerships for refcnting with fwnodes is horrible.
I hadn't actually noticed that _notifier_cleanup() was doing fwnode_handle_puts() ...
But indeed, all of that was pre-existing before this patch series. Not something I was looking to modify as part of this patch.
Lets fix that issue on top.
(which is going to get squashed in all the same, but I'm not going to change /this/ patch for it)
Quoted 8 lines
It was there already, but I think it happens in this patch as
well: ifmax9286_init()fails callsmax9286_v4l2_unregister()which then callsmax9286_v4l2_async_unregister()which put all the not-yet-completed subdevs by callingv4l2_async_notifier_cleanup(). Then in theprobe()function error path we then callmax9286_cleanup_dt()which puts again all the registered sources regardless of their completed status.
Quoted 6 lines
I would call
max9286_cleanup_dt()only ifmax9286_init()has not been called yet. If we get to register subdevs to the notifier, I would then provide a function that callsv4l2_async_notifier_cleanup()and then manually puts all sources not yet registered. I'm afraid this would need to keep a status flag in the source, unless you have a more elegant solution.
It seems like we also have the issue where we need to cleanup partially registered sources, (i.e. if some have registered, and some haven't) ... so how about a per-source flag to note that the device /got/ registered, and thus 'ownership' moved to V4L2 v4l2_async_notifier_cleanup() to _put().
Then we can maintain a single cleanup function still, and it will be handled on a per-node basis.
--
KB
Quoted 69 lines
Thanks
jQuoted 65 lines
drivers/media/i2c/max9286.c +2
-25source->fwnode =NULL ;@@ -958,7 +1002,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)struct device_node *i2c_mux;struct device_node *node =NULL ;unsigned int i2c_mux_mask =0 ; -int ret;of_node_get (dev->of_node); i2c_mux =of_find_node_by_name (dev->of_node,"i2c-mux" );@@ -986,8 +1029,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)of_node_put (node);of_node_put (i2c_mux); -v4l2_async_notifier_init (&priv->notifier); -/* Parse the endpoints */ for_each_endpoint_of_node (dev->of_node, node) {struct max9286_source *source;@@ -1056,34 +1097,14 @@ static int max9286_parse_dt(struct max9286_priv *priv)continue ; } - source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; - source->asd.match.fwnode = source->fwnode; - - ret =v4l2_async_notifier_add_subdev (&priv->notifier, - &source->asd); -if (ret) { -v4l2_async_notifier_cleanup (&priv->notifier); -of_node_put (node); -return ret; - } - priv->source_mask |=BIT (ep.port); priv->nsources++; }of_node_put (node); -/* Do not register the subdev notifier if there are no devices. */ -if (!priv->nsources) -return 0 ; - priv->route_mask = priv->source_mask; - priv->notifier.ops = &max9286_notify_ops; - - ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); -if (ret) -v4l2_async_notifier_cleanup (&priv->notifier); -return ret; +return 0 ; }static int max9286_probe (struct i2c_client *client)@@ -1182,6 +1203,7 @@ static int max9286_remove(struct i2c_client *client)fwnode_handle_put (priv->sd.fwnode);v4l2_async_unregister_subdev (&priv->sd); +max9286_v4l2_async_unregister (priv);if (priv->poc_enabled)regulator_disable (priv->regulator); --2.20.1
Kieran Bingham
maintainerRe: [PATCH 1/2] max9286: Split out async registration
Hi Jacopo,
Quoted 213 lines · Kieran Bingham
Hi Jacopo,
Quoted 2 lines · Jacopo Mondi
Hi Kieran,
very nice thanks for handling this:-)
Quoted 1 line
Just a few minors
:-s hehe
Quoted 18 lines · Kieran Bingham
Quoted 16 lines
Move all the V4L2 Subdev Async registration so that it can only happen once we know we will not need to -EPROBE_DEFER...
Signed-off-by Kieran Bingham <[email protected]>--- drivers/media/i2c/max9286.c | 88 +++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 33 deletions(-)drivers/media/i2c/max9286.c +0
-0@@ -503,6 +503,49 @@ static const struct v4l2_async_notifier_operations max9286_notify_ops = { .unbind = max9286_notify_unbind, };Quoted 4 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 506
Quoted 1 line
drivers/media/i2c/max9286.c +1
-0+static int max9286_v4l2_async_register (struct max9286_priv *priv)Could you capture in the function name this actually deals with notifiers ? Like
max9286_notifier_register()or similar...I'd like to keep the 'v4l2' in there somewhere...
max9286_v4l2_notifier_register() ?But then maybe even that could be confused with the notifiers/async handling for the max9286 itself.
My aim was that max9286_v4l2_async_{un,}register() dealt with subdevices connected to the max9286 only ...
For ~20 lines of code, it could be inlined up a level into
max9286_v4l2_register()but I do perhaps like trying to keep the symmetry clean somehow.<scratch that - below tells me not to inline>
Quoted 9 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 511
Quoted 5 lines
drivers/media/i2c/max9286.c +5
-0+{ +struct device *dev = &priv->client->dev; +struct max9286_source *source =NULL ; +int ret; +Do we want to init and register the notifier if there are no sources connected ? I would keep
Quoted 4 lines
if (!priv->nsources) return 0;here or in the caller.
Ah yes, I had thought about that but clearly not acted upon it much.
If we know there is nothing to notify us, I guess we won't expect any need to register the notifications!
Although this would certainly mean keeping the sources registration in their own functions.
Quoted 10 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 517
Quoted 7 lines
drivers/media/i2c/max9286.c +6
-0+v4l2_async_notifier_init (&priv->notifier); + +for_each_source (priv, source) { +unsigned int i =to_index (priv, source); + +dev_err (dev,"Registering v4l2-async for source %d\n" , i);
dev_err?Already removed, left over debug print.
Quoted 14 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 526
Quoted 9 lines
drivers/media/i2c/max9286.c +9
-0+ + source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; + source->asd.match.fwnode = source->fwnode; + + ret =v4l2_async_notifier_add_subdev (&priv->notifier, + &source->asd); +if (ret) { +dev_err (dev,"Failed to add subdev for source %d" , i); +v4l2_async_notifier_cleanup (&priv->notifier);
v4l2_async_notifier_cleanup()doesfwnode_handle_put()on the async subdevs registered to the notifier but not yet completed. All the other sources have to be put as well I think.Quoted 3 lines
How to do so might be not nice, as you would need to keep track of which sources have been registered to the notifier already and put the other ones in the error path.
Or can we move all fwnode refcounting back to
cleanup_dtperhaps?I'll have a look.
Quoted 14 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 536
Quoted 11 lines
drivers/media/i2c/max9286.c +10
-0+return ret; + } + } + + priv->notifier.ops = &max9286_notify_ops; + + ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); +if (ret) { +dev_err (dev,"Failed to register subdev_notifier" ); +v4l2_async_notifier_cleanup (&priv->notifier);Here it's fine to call
notifier_cleanup()Quoted 13 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 546
Quoted 10 lines
drivers/media/i2c/max9286.c +10
-0+return ret; + } + +return 0 ; +} + +static void max9286_v4l2_async_unregister (struct max9286_priv *priv) +{ +v4l2_async_notifier_unregister (&priv->notifier); +v4l2_async_notifier_cleanup (&priv->notifier);I would first
cleanup()thenunregister()even if they deal with two different sets of asds (done and registred-but-not-yet-done ones).Looking at
max9286_v4l2_async_register(), thev4l2_async_subdev_notifier_register()call is last.Therefore that would make it the first thing to cleanup in the reverse procedure?
Quoted 56 lines
Quoted 42 lines
drivers/media/i2c/max9286.c +12
-1+} +static int max9286_s_stream (struct v4l2_subdev *sd,int enable) {struct max9286_priv *priv =sd_to_max9286 (sd);@@ -870,6 +913,13 @@ static int max9286_init(struct device *dev) goto err_regulator; } +/* Register v4l2 async notifiers */ + ret =max9286_v4l2_async_register (priv); +if (ret) { +dev_err (dev,"Unable to register V4L2 async notifiers\n" ); + goto err_regulator; + } +v4l2_i2c_subdev_init (&priv->sd, client, &max9286_subdev_ops); priv->sd.internal_ops = &max9286_subdev_internal_ops; priv->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;@@ -884,7 +934,7 @@ static int max9286_init(struct device *dev) priv->sd.ctrl_handler = &priv->ctrls; ret = priv->ctrls.error;if (ret) - goto err_regulator; + goto err_async; priv->sd.entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ;@@ -927,6 +977,8 @@ static int max9286_init(struct device *dev)max9286_i2c_mux_close (priv); err_put_node:fwnode_handle_put (ep); +err_async: +max9286_v4l2_async_unregister (priv); err_regulator:regulator_disable (priv->regulator); priv->poc_enabled = false;@@ -938,14 +990,6 @@ static void max9286_cleanup_dt(struct max9286_priv *priv) {struct max9286_source *source;drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 994
Quoted 10 lines
drivers/media/i2c/max9286.c +0
-8-/* -* Not strictly part of the DT, but the notifier is registered during -* max9286_parse_dt(), and the notifier holds references to the fwnodes -* thus the cleanup is here to mirror the registration. -*/ -v4l2_async_notifier_unregister (&priv->notifier); -v4l2_async_notifier_cleanup (&priv->notifier); -for_each_source (priv, source) {fwnode_handle_put (source->fwnode);Wasn't this a double
fwnode_handle_put()? We callednotifier_cleanup()and then put all sources again manually.Quoted 3 lines
I don't see one more
get()when the asd gets registered to the notifier withv4l2_async_notifier_add_subdev()so I'm afraid this would result in a duplicatedput(). Am I wrong ?Agh, all the implicit transfers of ownerships for refcnting with fwnodes is horrible.
I hadn't actually noticed that
_notifier_cleanup()was doingfwnode_handle_puts()...
Quoted 7 lines
But indeed, all of that was pre-existing before this patch series. Not something I was looking to modify as part of this patch.
Lets fix that issue on top.
(which is going to get squashed in all the same, but I'm not going to change /this/ patch for it)
Perhaps the simplest option in this case actually is to do a fwnode_handle_get() on a successful async_notifier_add_subdev().
That will keep the refcnting balanced.
Quoted 15 lines
Quoted 8 lines
It was there already, but I think it happens in this patch as
well: ifmax9286_init()fails callsmax9286_v4l2_unregister()which then callsmax9286_v4l2_async_unregister()which put all the not-yet-completed subdevs by callingv4l2_async_notifier_cleanup(). Then in theprobe()function error path we then callmax9286_cleanup_dt()which puts again all the registered sources regardless of their completed status.Quoted 6 lines
I would call
max9286_cleanup_dt()only ifmax9286_init()has not been called yet. If we get to register subdevs to the notifier, I would then provide a function that callsv4l2_async_notifier_cleanup()and then manually puts all sources not yet registered. I'm afraid this would need to keep a status flag in the source, unless you have a more elegant solution.
Quoted 7 lines
It seems like we also have the issue where we need to cleanup partially registered sources, (i.e. if some have registered, and some haven't) ... so how about a per-source flag to note that the device /got/ registered, and thus 'ownership' moved to V4L2
v4l2_async_notifier_cleanup()to_put().Then we can maintain a single cleanup function still, and it will be handled on a per-node basis.
And I think the extra 'fwnode_handle_get()' would resolve this too?
Quoted 76 lines
--
KBQuoted 69 lines
Thanks
jQuoted 65 lines
drivers/media/i2c/max9286.c +2
-25source->fwnode =NULL ;@@ -958,7 +1002,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)struct device_node *i2c_mux;struct device_node *node =NULL ;unsigned int i2c_mux_mask =0 ; -int ret;of_node_get (dev->of_node); i2c_mux =of_find_node_by_name (dev->of_node,"i2c-mux" );@@ -986,8 +1029,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)of_node_put (node);of_node_put (i2c_mux); -v4l2_async_notifier_init (&priv->notifier); -/* Parse the endpoints */ for_each_endpoint_of_node (dev->of_node, node) {struct max9286_source *source;@@ -1056,34 +1097,14 @@ static int max9286_parse_dt(struct max9286_priv *priv)continue ; } - source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; - source->asd.match.fwnode = source->fwnode; - - ret =v4l2_async_notifier_add_subdev (&priv->notifier, - &source->asd); -if (ret) { -v4l2_async_notifier_cleanup (&priv->notifier); -of_node_put (node); -return ret; - } - priv->source_mask |=BIT (ep.port); priv->nsources++; }of_node_put (node); -/* Do not register the subdev notifier if there are no devices. */ -if (!priv->nsources) -return 0 ; - priv->route_mask = priv->source_mask; - priv->notifier.ops = &max9286_notify_ops; - - ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); -if (ret) -v4l2_async_notifier_cleanup (&priv->notifier); -return ret; +return 0 ; }static int max9286_probe (struct i2c_client *client)@@ -1182,6 +1203,7 @@ static int max9286_remove(struct i2c_client *client)fwnode_handle_put (priv->sd.fwnode);v4l2_async_unregister_subdev (&priv->sd); +max9286_v4l2_async_unregister (priv);if (priv->poc_enabled)regulator_disable (priv->regulator); --2.20.1
Re: [PATCH 1/2] max9286: Split out async registration
In reply to Kieran BinghamHi Kieran,
Quoted 12 lines · Kieran Bingham
Hi Jacopo,
Quoted 2 lines · Jacopo Mondi
Hi Kieran,
very nice thanks for handling this:-)
Quoted 1 line
Just a few minors
:-s hehe
Turned out to be lengthier than expected :)
Quoted 25 lines
Quoted 18 lines · Kieran Bingham
Quoted 16 lines
Move all the V4L2 Subdev Async registration so that it can only happen once we know we will not need to -EPROBE_DEFER...
Signed-off-by Kieran Bingham <[email protected]>--- drivers/media/i2c/max9286.c | 88 +++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 33 deletions(-)drivers/media/i2c/max9286.c +0
-0@@ -503,6 +503,49 @@ static const struct v4l2_async_notifier_operations max9286_notify_ops = { .unbind = max9286_notify_unbind, };Quoted 4 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 506
Quoted 1 line
drivers/media/i2c/max9286.c +1
-0+static int max9286_v4l2_async_register (struct max9286_priv *priv)Could you capture in the function name this actually deals with notifiers ? Like
max9286_notifier_register()or similar...I'd like to keep the 'v4l2' in there somewhere...
Quoted 7 lines
max9286_v4l2_notifier_register() ?But then maybe even that could be confused with the notifiers/async handling for the max9286 itself.
My aim was that max9286_v4l2_async_{un,}register() dealt with subdevices connected to the max9286 only ...
To me async_register() calls for dealing with registering our own subdev to the async framework, not collecting remote asds and adding it our subnotifier. As you wish, it's really just a suggestion.
Quoted 96 lines
For ~20 lines of code, it could be inlined up a level into
max9286_v4l2_register()but I do perhaps like trying to keep the symmetry clean somehow.<scratch that - below tells me not to inline>
Quoted 9 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 511
Quoted 5 lines
drivers/media/i2c/max9286.c +5
-0+{ +struct device *dev = &priv->client->dev; +struct max9286_source *source =NULL ; +int ret; +Do we want to init and register the notifier if there are no sources connected ? I would keep
Quoted 4 lines
if (!priv->nsources) return 0;here or in the caller.
Ah yes, I had thought about that but clearly not acted upon it much.
If we know there is nothing to notify us, I guess we won't expect any need to register the notifications!
Although this would certainly mean keeping the sources registration in their own functions.
Quoted 10 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 517
Quoted 7 lines
drivers/media/i2c/max9286.c +6
-0+v4l2_async_notifier_init (&priv->notifier); + +for_each_source (priv, source) { +unsigned int i =to_index (priv, source); + +dev_err (dev,"Registering v4l2-async for source %d\n" , i);
dev_err?Already removed, left over debug print.
Quoted 14 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 526
Quoted 9 lines
drivers/media/i2c/max9286.c +9
-0+ + source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; + source->asd.match.fwnode = source->fwnode; + + ret =v4l2_async_notifier_add_subdev (&priv->notifier, + &source->asd); +if (ret) { +dev_err (dev,"Failed to add subdev for source %d" , i); +v4l2_async_notifier_cleanup (&priv->notifier);
v4l2_async_notifier_cleanup()doesfwnode_handle_put()on the async subdevs registered to the notifier but not yet completed. All the other sources have to be put as well I think.Quoted 3 lines
How to do so might be not nice, as you would need to keep track of which sources have been registered to the notifier already and put the other ones in the error path.
Or can we move all fwnode refcounting back to
cleanup_dtperhaps?I'll have a look.
Quoted 14 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 536
Quoted 11 lines
drivers/media/i2c/max9286.c +10
-0+return ret; + } + } + + priv->notifier.ops = &max9286_notify_ops; + + ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); +if (ret) { +dev_err (dev,"Failed to register subdev_notifier" ); +v4l2_async_notifier_cleanup (&priv->notifier);Here it's fine to call
notifier_cleanup()Quoted 13 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 546
Quoted 10 lines
drivers/media/i2c/max9286.c +10
-0+return ret; + } + +return 0 ; +} + +static void max9286_v4l2_async_unregister (struct max9286_priv *priv) +{ +v4l2_async_notifier_unregister (&priv->notifier); +v4l2_async_notifier_cleanup (&priv->notifier);I would first
cleanup()thenunregister()even if they deal with two different sets of asds (done and registred-but-not-yet-done ones).
Quoted 6 lines
Looking at
max9286_v4l2_async_register(), thev4l2_async_subdev_notifier_register()call is last.Therefore that would make it the first thing to cleanup in the reverse procedure?
Ok then, reverse order for symmetry is fine.
Quoted 57 lines
Quoted 57 lines
Quoted 43 lines
drivers/media/i2c/max9286.c +12
-1+} +static int max9286_s_stream (struct v4l2_subdev *sd,int enable) {struct max9286_priv *priv =sd_to_max9286 (sd);@@ -870,6 +913,13 @@ static int max9286_init(struct device *dev) goto err_regulator; } +/* Register v4l2 async notifiers */ + ret =max9286_v4l2_async_register (priv); +if (ret) { +dev_err (dev,"Unable to register V4L2 async notifiers\n" ); + goto err_regulator; + } +v4l2_i2c_subdev_init (&priv->sd, client, &max9286_subdev_ops); priv->sd.internal_ops = &max9286_subdev_internal_ops; priv->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;@@ -884,7 +934,7 @@ static int max9286_init(struct device *dev) priv->sd.ctrl_handler = &priv->ctrls; ret = priv->ctrls.error;if (ret) - goto err_regulator; + goto err_async; priv->sd.entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ;@@ -927,6 +977,8 @@ static int max9286_init(struct device *dev)max9286_i2c_mux_close (priv); err_put_node:fwnode_handle_put (ep); +err_async: +max9286_v4l2_async_unregister (priv); err_regulator:regulator_disable (priv->regulator); priv->poc_enabled = false;@@ -938,14 +990,6 @@ static void max9286_cleanup_dt(struct max9286_priv *priv) {struct max9286_source *source;drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 994
Quoted 10 lines
drivers/media/i2c/max9286.c +0
-8-/* -* Not strictly part of the DT, but the notifier is registered during -* max9286_parse_dt(), and the notifier holds references to the fwnodes -* thus the cleanup is here to mirror the registration. -*/ -v4l2_async_notifier_unregister (&priv->notifier); -v4l2_async_notifier_cleanup (&priv->notifier); -for_each_source (priv, source) {fwnode_handle_put (source->fwnode);Wasn't this a double
fwnode_handle_put()? We callednotifier_cleanup()and then put all sources again manually.
Quoted 7 lines
Quoted 3 lines
I don't see one more
get()when the asd gets registered to the notifier withv4l2_async_notifier_add_subdev()so I'm afraid this would result in a duplicatedput(). Am I wrong ?Agh, all the implicit transfers of ownerships for refcnting with fwnodes is horrible.
Yup :(
Quoted 8 lines
I hadn't actually noticed that
_notifier_cleanup()was doingfwnode_handle_puts()...But indeed, all of that was pre-existing before this patch series. Not something I was looking to modify as part of this patch.
Lets fix that issue on top.
Fine with me
Quoted 19 lines
(which is going to get squashed in all the same, but I'm not going to change /this/ patch for it)
Quoted 8 lines
It was there already, but I think it happens in this patch as
well: ifmax9286_init()fails callsmax9286_v4l2_unregister()which then callsmax9286_v4l2_async_unregister()which put all the not-yet-completed subdevs by callingv4l2_async_notifier_cleanup(). Then in theprobe()function error path we then callmax9286_cleanup_dt()which puts again all the registered sources regardless of their completed status.Quoted 6 lines
I would call
max9286_cleanup_dt()only ifmax9286_init()has not been called yet. If we get to register subdevs to the notifier, I would then provide a function that callsv4l2_async_notifier_cleanup()and then manually puts all sources not yet registered. I'm afraid this would need to keep a status flag in the source, unless you have a more elegant solution.
Quoted 7 lines
It seems like we also have the issue where we need to cleanup partially registered sources, (i.e. if some have registered, and some haven't) ... so how about a per-source flag to note that the device /got/ registered, and thus 'ownership' moved to V4L2
v4l2_async_notifier_cleanup()to_put().Then we can maintain a single cleanup function still, and it will be handled on a per-node basis.
That was my suggestion but indeed requires some state keeping in place, so I hoped we could come up with something more elegant :)
But indeed, keeping a flag in the source to tell ownership has been passed to the async framework would probably be enough, and would allow us to possibly have a single cleanup function, yes.
Quoted 76 lines
--
KBQuoted 69 lines
Thanks
jQuoted 65 lines
drivers/media/i2c/max9286.c +2
-25source->fwnode =NULL ;@@ -958,7 +1002,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)struct device_node *i2c_mux;struct device_node *node =NULL ;unsigned int i2c_mux_mask =0 ; -int ret;of_node_get (dev->of_node); i2c_mux =of_find_node_by_name (dev->of_node,"i2c-mux" );@@ -986,8 +1029,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)of_node_put (node);of_node_put (i2c_mux); -v4l2_async_notifier_init (&priv->notifier); -/* Parse the endpoints */ for_each_endpoint_of_node (dev->of_node, node) {struct max9286_source *source;@@ -1056,34 +1097,14 @@ static int max9286_parse_dt(struct max9286_priv *priv)continue ; } - source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; - source->asd.match.fwnode = source->fwnode; - - ret =v4l2_async_notifier_add_subdev (&priv->notifier, - &source->asd); -if (ret) { -v4l2_async_notifier_cleanup (&priv->notifier); -of_node_put (node); -return ret; - } - priv->source_mask |=BIT (ep.port); priv->nsources++; }of_node_put (node); -/* Do not register the subdev notifier if there are no devices. */ -if (!priv->nsources) -return 0 ; - priv->route_mask = priv->source_mask; - priv->notifier.ops = &max9286_notify_ops; - - ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); -if (ret) -v4l2_async_notifier_cleanup (&priv->notifier); -return ret; +return 0 ; }static int max9286_probe (struct i2c_client *client)@@ -1182,6 +1203,7 @@ static int max9286_remove(struct i2c_client *client)fwnode_handle_put (priv->sd.fwnode);v4l2_async_unregister_subdev (&priv->sd); +max9286_v4l2_async_unregister (priv);if (priv->poc_enabled)regulator_disable (priv->regulator); --2.20.1
Kieran Bingham
maintainerRe: [PATCH 1/2] max9286: Split out async registration
Quoted 48 lines · Jacopo Mondi
Hi Kieran,
Quoted 12 lines · Kieran Bingham
Hi Jacopo,
Quoted 2 lines · Jacopo Mondi
Hi Kieran,
very nice thanks for handling this:-)
Quoted 1 line
Just a few minors
:-s hehe
Turned out to be lengthier than expected :)
Quoted 30 lines
Quoted 18 lines · Kieran Bingham
Quoted 16 lines
Move all the V4L2 Subdev Async registration so that it can only happen once we know we will not need to -EPROBE_DEFER...
Signed-off-by Kieran Bingham <[email protected]>--- drivers/media/i2c/max9286.c | 88 +++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 33 deletions(-)drivers/media/i2c/max9286.c +0
-0@@ -503,6 +503,49 @@ static const struct v4l2_async_notifier_operations max9286_notify_ops = { .unbind = max9286_notify_unbind, };Quoted 4 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 506
Quoted 1 line
drivers/media/i2c/max9286.c +1
-0+static int max9286_v4l2_async_register (struct max9286_priv *priv)Could you capture in the function name this actually deals with notifiers ? Like
max9286_notifier_register()or similar...I'd like to keep the 'v4l2' in there somewhere...
max9286_v4l2_notifier_register() ?But then maybe even that could be confused with the notifiers/async handling for the max9286 itself.
Quoted 6 lines
Quoted 2 lines
My aim was that max9286_v4l2_async_{un,}register() dealt with subdevices connected to the max9286 only ...
To me
async_register()calls for dealing with registering our own subdev to the async framework, not collecting remote asds and adding it our subnotifier. As you wish, it's really just a suggestion.
So would you like to see the async registration between the max9286 and the connected CSI2 receiver handled in this pair of functions too?
That would mean moveing the subdevice registrations later too - to after all of the max9286 device creations but I think that's fine.
As long as the case between "if (priv->nsources)" is handled correctly between the max9286 subdevices and the parent device it should be fine.
Quoted 209 lines
Quoted 95 lines
For ~20 lines of code, it could be inlined up a level into
max9286_v4l2_register()but I do perhaps like trying to keep the symmetry clean somehow.<scratch that - below tells me not to inline>
Quoted 9 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 511
Quoted 5 lines
drivers/media/i2c/max9286.c +5
-0+{ +struct device *dev = &priv->client->dev; +struct max9286_source *source =NULL ; +int ret; +Do we want to init and register the notifier if there are no sources connected ? I would keep
Quoted 4 lines
if (!priv->nsources) return 0;here or in the caller.
Ah yes, I had thought about that but clearly not acted upon it much.
If we know there is nothing to notify us, I guess we won't expect any need to register the notifications!
Although this would certainly mean keeping the sources registration in their own functions.
Quoted 10 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 517
Quoted 7 lines
drivers/media/i2c/max9286.c +6
-0+v4l2_async_notifier_init (&priv->notifier); + +for_each_source (priv, source) { +unsigned int i =to_index (priv, source); + +dev_err (dev,"Registering v4l2-async for source %d\n" , i);
dev_err?Already removed, left over debug print.
Quoted 14 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 526
Quoted 9 lines
drivers/media/i2c/max9286.c +9
-0+ + source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; + source->asd.match.fwnode = source->fwnode; + + ret =v4l2_async_notifier_add_subdev (&priv->notifier, + &source->asd); +if (ret) { +dev_err (dev,"Failed to add subdev for source %d" , i); +v4l2_async_notifier_cleanup (&priv->notifier);
v4l2_async_notifier_cleanup()doesfwnode_handle_put()on the async subdevs registered to the notifier but not yet completed. All the other sources have to be put as well I think.Quoted 3 lines
How to do so might be not nice, as you would need to keep track of which sources have been registered to the notifier already and put the other ones in the error path.
Or can we move all fwnode refcounting back to
cleanup_dtperhaps?I'll have a look.
Quoted 14 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 536
Quoted 11 lines
drivers/media/i2c/max9286.c +10
-0+return ret; + } + } + + priv->notifier.ops = &max9286_notify_ops; + + ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); +if (ret) { +dev_err (dev,"Failed to register subdev_notifier" ); +v4l2_async_notifier_cleanup (&priv->notifier);Here it's fine to call
notifier_cleanup()Quoted 13 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 546
Quoted 10 lines
drivers/media/i2c/max9286.c +10
-0+return ret; + } + +return 0 ; +} + +static void max9286_v4l2_async_unregister (struct max9286_priv *priv) +{ +v4l2_async_notifier_unregister (&priv->notifier); +v4l2_async_notifier_cleanup (&priv->notifier);I would first
cleanup()thenunregister()even if they deal with two different sets of asds (done and registred-but-not-yet-done ones).Quoted 6 lines
Looking at
max9286_v4l2_async_register(), thev4l2_async_subdev_notifier_register()call is last.Therefore that would make it the first thing to cleanup in the reverse procedure?
Ok then, reverse order for symmetry is fine.
Quoted 57 lines
Quoted 57 lines
Quoted 43 lines
drivers/media/i2c/max9286.c +12
-1+} +static int max9286_s_stream (struct v4l2_subdev *sd,int enable) {struct max9286_priv *priv =sd_to_max9286 (sd);@@ -870,6 +913,13 @@ static int max9286_init(struct device *dev) goto err_regulator; } +/* Register v4l2 async notifiers */ + ret =max9286_v4l2_async_register (priv); +if (ret) { +dev_err (dev,"Unable to register V4L2 async notifiers\n" ); + goto err_regulator; + } +v4l2_i2c_subdev_init (&priv->sd, client, &max9286_subdev_ops); priv->sd.internal_ops = &max9286_subdev_internal_ops; priv->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;@@ -884,7 +934,7 @@ static int max9286_init(struct device *dev) priv->sd.ctrl_handler = &priv->ctrls; ret = priv->ctrls.error;if (ret) - goto err_regulator; + goto err_async; priv->sd.entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ;@@ -927,6 +977,8 @@ static int max9286_init(struct device *dev)max9286_i2c_mux_close (priv); err_put_node:fwnode_handle_put (ep); +err_async: +max9286_v4l2_async_unregister (priv); err_regulator:regulator_disable (priv->regulator); priv->poc_enabled = false;@@ -938,14 +990,6 @@ static void max9286_cleanup_dt(struct max9286_priv *priv) {struct max9286_source *source;drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 994
Quoted 10 lines
drivers/media/i2c/max9286.c +0
-8-/* -* Not strictly part of the DT, but the notifier is registered during -* max9286_parse_dt(), and the notifier holds references to the fwnodes -* thus the cleanup is here to mirror the registration. -*/ -v4l2_async_notifier_unregister (&priv->notifier); -v4l2_async_notifier_cleanup (&priv->notifier); -for_each_source (priv, source) {fwnode_handle_put (source->fwnode);Wasn't this a double
fwnode_handle_put()? We callednotifier_cleanup()and then put all sources again manually.Quoted 7 lines
Quoted 3 lines
I don't see one more
get()when the asd gets registered to the notifier withv4l2_async_notifier_add_subdev()so I'm afraid this would result in a duplicatedput(). Am I wrong ?Agh, all the implicit transfers of ownerships for refcnting with fwnodes is horrible.
Yup :(
Quoted 8 lines
I hadn't actually noticed that
_notifier_cleanup()was doingfwnode_handle_puts()...But indeed, all of that was pre-existing before this patch series. Not something I was looking to modify as part of this patch.
Lets fix that issue on top.
Fine with me
Quoted 19 lines
(which is going to get squashed in all the same, but I'm not going to change /this/ patch for it)
Quoted 8 lines
It was there already, but I think it happens in this patch as
well: ifmax9286_init()fails callsmax9286_v4l2_unregister()which then callsmax9286_v4l2_async_unregister()which put all the not-yet-completed subdevs by callingv4l2_async_notifier_cleanup(). Then in theprobe()function error path we then callmax9286_cleanup_dt()which puts again all the registered sources regardless of their completed status.Quoted 6 lines
I would call
max9286_cleanup_dt()only ifmax9286_init()has not been called yet. If we get to register subdevs to the notifier, I would then provide a function that callsv4l2_async_notifier_cleanup()and then manually puts all sources not yet registered. I'm afraid this would need to keep a status flag in the source, unless you have a more elegant solution.Quoted 7 lines
It seems like we also have the issue where we need to cleanup partially registered sources, (i.e. if some have registered, and some haven't) ... so how about a per-source flag to note that the device /got/ registered, and thus 'ownership' moved to V4L2
v4l2_async_notifier_cleanup()to_put().Then we can maintain a single cleanup function still, and it will be handled on a per-node basis.
Quoted 6 lines
That was my suggestion but indeed requires some state keeping in place, so I hoped we could come up with something more elegant :)
But indeed, keeping a flag in the source to tell ownership has been passed to the async framework would probably be enough, and would allow us to possibly have a single cleanup function, yes.
Hopefully my proposed patch to simply increase the refcnt on successfully added subdevs will do the trick.
Quoted 77 lines
Quoted 77 lines
--
KBQuoted 69 lines
Thanks
jQuoted 65 lines
drivers/media/i2c/max9286.c +2
-25source->fwnode =NULL ;@@ -958,7 +1002,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)struct device_node *i2c_mux;struct device_node *node =NULL ;unsigned int i2c_mux_mask =0 ; -int ret;of_node_get (dev->of_node); i2c_mux =of_find_node_by_name (dev->of_node,"i2c-mux" );@@ -986,8 +1029,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)of_node_put (node);of_node_put (i2c_mux); -v4l2_async_notifier_init (&priv->notifier); -/* Parse the endpoints */ for_each_endpoint_of_node (dev->of_node, node) {struct max9286_source *source;@@ -1056,34 +1097,14 @@ static int max9286_parse_dt(struct max9286_priv *priv)continue ; } - source->asd.match_type =V4L2_ASYNC_MATCH_FWNODE ; - source->asd.match.fwnode = source->fwnode; - - ret =v4l2_async_notifier_add_subdev (&priv->notifier, - &source->asd); -if (ret) { -v4l2_async_notifier_cleanup (&priv->notifier); -of_node_put (node); -return ret; - } - priv->source_mask |=BIT (ep.port); priv->nsources++; }of_node_put (node); -/* Do not register the subdev notifier if there are no devices. */ -if (!priv->nsources) -return 0 ; - priv->route_mask = priv->source_mask; - priv->notifier.ops = &max9286_notify_ops; - - ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); -if (ret) -v4l2_async_notifier_cleanup (&priv->notifier); -return ret; +return 0 ; }static int max9286_probe (struct i2c_client *client)@@ -1182,6 +1203,7 @@ static int max9286_remove(struct i2c_client *client)fwnode_handle_put (priv->sd.fwnode);v4l2_async_unregister_subdev (&priv->sd); +max9286_v4l2_async_unregister (priv);if (priv->poc_enabled)regulator_disable (priv->regulator); --2.20.1
Re: [PATCH 1/2] max9286: Split out async registration
Hi Kieran,
Quoted 52 lines · Kieran Bingham
Quoted 51 lines · Jacopo Mondi
Hi Kieran,
Quoted 12 lines · Kieran Bingham
Hi Jacopo,
Quoted 2 lines · Jacopo Mondi
Hi Kieran,
very nice thanks for handling this:-)
Quoted 1 line
Just a few minors
:-s hehe
Turned out to be lengthier than expected :)
Quoted 32 lines
Quoted 18 lines · Kieran Bingham
Quoted 16 lines
Move all the V4L2 Subdev Async registration so that it can only happen once we know we will not need to -EPROBE_DEFER...
Signed-off-by Kieran Bingham <[email protected]>--- drivers/media/i2c/max9286.c | 88 +++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 33 deletions(-)drivers/media/i2c/max9286.c +0
-0@@ -503,6 +503,49 @@ static const struct v4l2_async_notifier_operations max9286_notify_ops = { .unbind = max9286_notify_unbind, };Quoted 4 lines
drivers/media/i2c/max9286.c static const struct v4l2_async_notifier_operations max9286_notify_ops = { · line 506
Quoted 1 line
drivers/media/i2c/max9286.c +1
-0+static int max9286_v4l2_async_register (struct max9286_priv *priv)Could you capture in the function name this actually deals with notifiers ? Like
max9286_notifier_register()or similar...I'd like to keep the 'v4l2' in there somewhere...
max9286_v4l2_notifier_register() ?But then maybe even that could be confused with the notifiers/async handling for the max9286 itself.
My aim was that max9286_v4l2_async_{un,}register() dealt with subdevices connected to the max9286 only ...
Quoted 8 lines
Quoted 3 lines
To me
async_register()calls for dealing with registering our own subdev to the async framework, not collecting remote asds and adding it our subnotifier. As you wish, it's really just a suggestion.So would you like to see the async registration between the max9286 and the connected CSI2 receiver handled in this pair of functions too?
No no, I was just bikeshedding on function names, no worries :)
Kieran Bingham
maintainerPATCH 2/2 max9286: Collect all V4L2 registrations
In reply to Kieran BinghamMove all interactions with V4L2 to a dedicated pair of functions for register and unregister to improve readability of the code.
--- drivers/media/i2c/max9286.c | 139 +++++++++++++++++++++--------------- 1 file changed, 83 insertions(+), 56 deletions(-)
drivers/media/i2c/max9286.c +83 -56
@@ -735,6 +735,80 @@ static const struct v4l2_subdev_internal_ops max9286_subdev_internal_ops = { .open = max9286_open, }; +static int max9286_v4l2_register (struct max9286_priv *priv) +{ +struct device *dev = &priv->client->dev; +struct fwnode_handle *ep; +int ret; +int i; + +/* Register v4l2 async notifiers for connected Camera subdevices */ + ret =max9286_v4l2_async_register (priv); +if (ret) { +dev_err (dev,"Unable to register V4L2 async notifiers\n" ); +return ret; + } + +/* Configure V4L2 for the MAX9286 itself */ + +v4l2_i2c_subdev_init (&priv->sd, priv->client, &max9286_subdev_ops); + priv->sd.internal_ops = &max9286_subdev_internal_ops; + priv->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + +v4l2_ctrl_handler_init (&priv->ctrls,1 ); +/* +* FIXME: Compute the real pixel rate. The 50 MP/s value comes from the +* hardcoded frequency in the BSP CSI-2 receiver driver. +*/ +v4l2_ctrl_new_std (&priv->ctrls,NULL ,V4L2_CID_PIXEL_RATE , +50000000 ,50000000 ,1 ,50000000 ); + priv->sd.ctrl_handler = &priv->ctrls; + ret = priv->ctrls.error; +if (ret) + goto err_async; + + priv->sd.entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ; + + priv->pads[MAX9286_SRC_PAD ].flags =MEDIA_PAD_FL_SOURCE ; +for (i =0 ; i <MAX9286_SRC_PAD ; i++) + priv->pads[i].flags =MEDIA_PAD_FL_SINK ; + ret =media_entity_pads_init (&priv->sd.entity,MAX9286_N_PADS , + priv->pads); +if (ret) + goto err_async; + + ep =fwnode_graph_get_endpoint_by_id (dev_fwnode (dev),MAX9286_SRC_PAD , +0 ,0 ); +if (!ep) { +dev_err (dev,"Unable to retrieve endpoint on \"port@4\"\n" ); + ret = -ENOENT ; + goto err_async; + } + priv->sd.fwnode = ep; + + ret =v4l2_async_register_subdev (&priv->sd); +if (ret <0 ) { +dev_err (dev,"Unable to register subdevice\n" ); + goto err_put_node; + } + +return 0 ; + +err_put_node: +fwnode_handle_put (ep); +err_async: +max9286_v4l2_async_unregister (priv); + +return ret; +} + +static void max9286_v4l2_unregister (struct max9286_priv *priv) +{ +fwnode_handle_put (priv->sd.fwnode); +v4l2_async_unregister_subdev (&priv->sd); +max9286_v4l2_async_unregister (priv); +} +/* ----------------------------------------------------------------------------- * Probe/Remove */
@@ -887,8 +961,6 @@ static int max9286_init(struct device *dev) {struct max9286_priv *priv;struct i2c_client *client; -struct fwnode_handle *ep; -unsigned int i;int ret;/* Skip non-max9286 devices. */
@@ -913,58 +985,20 @@ static int max9286_init(struct device *dev) goto err_regulator; } -/* Register v4l2 async notifiers */ - ret =max9286_v4l2_async_register (priv); -if (ret) { -dev_err (dev,"Unable to register V4L2 async notifiers\n" ); - goto err_regulator; - } - -v4l2_i2c_subdev_init (&priv->sd, client, &max9286_subdev_ops); - priv->sd.internal_ops = &max9286_subdev_internal_ops; - priv->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; - -v4l2_ctrl_handler_init (&priv->ctrls,1 );/* -* FIXME: Compute the real pixel rate. The 50 MP/s value comes from the -* hardcoded frequency in the BSP CSI-2 receiver driver. +* Register all V4L2 interactions for the MAX9286 and notifiers for +* any subdevices connected. */ -v4l2_ctrl_new_std (&priv->ctrls,NULL ,V4L2_CID_PIXEL_RATE , -50000000 ,50000000 ,1 ,50000000 ); - priv->sd.ctrl_handler = &priv->ctrls; - ret = priv->ctrls.error; -if (ret) - goto err_async; - - priv->sd.entity.function =MEDIA_ENT_F_VID_IF_BRIDGE ; - - priv->pads[MAX9286_SRC_PAD ].flags =MEDIA_PAD_FL_SOURCE ; -for (i =0 ; i <MAX9286_SRC_PAD ; i++) - priv->pads[i].flags =MEDIA_PAD_FL_SINK ; - ret =media_entity_pads_init (&priv->sd.entity,MAX9286_N_PADS , - priv->pads); -if (ret) - goto err_regulator; - - ep =fwnode_graph_get_endpoint_by_id (dev_fwnode (dev),MAX9286_SRC_PAD , -0 ,0 ); -if (!ep) { -dev_err (dev,"Unable to retrieve endpoint on \"port@4\"\n" ); - ret = -ENOENT ; + ret =max9286_v4l2_register (priv); +if (ret) { +dev_err (dev,"Failed to register with V4L2\n" ); goto err_regulator; } - priv->sd.fwnode = ep; - - ret =v4l2_async_register_subdev (&priv->sd); -if (ret <0 ) { -dev_err (dev,"Unable to register subdevice\n" ); - goto err_put_node; - } ret =max9286_i2c_mux_init (priv);if (ret) {dev_err (dev,"Unable to initialize I2C multiplexer\n" ); - goto err_subdev_unregister; + goto err_v4l2_register; }/* Leave the mux channels disabled until they are selected. */
@@ -972,13 +1006,8 @@ static int max9286_init(struct device *dev)return 0 ; -err_subdev_unregister: -v4l2_async_unregister_subdev (&priv->sd); -max9286_i2c_mux_close (priv); -err_put_node: -fwnode_handle_put (ep); -err_async: -max9286_v4l2_async_unregister (priv); +err_v4l2_register: +max9286_v4l2_unregister (priv); err_regulator:regulator_disable (priv->regulator); priv->poc_enabled = false;
@@ -1201,9 +1230,7 @@ static int max9286_remove(struct i2c_client *client)i2c_mux_del_adapters (priv->mux); -fwnode_handle_put (priv->sd.fwnode); -v4l2_async_unregister_subdev (&priv->sd); -max9286_v4l2_async_unregister (priv); +max9286_v4l2_unregister (priv);if (priv->poc_enabled)regulator_disable (priv->regulator);
Signature · 1 line
2.20.1
Kieran Bingham
maintainerPATCH 1/1 max9286: balance v4l2_async refcnting
In reply to Kieran BinghamWhen we add fwnodes to V4L2 notifiers through v4l2_async_notifier_add_subdev they are stored internally in V4L2 core, and have a reference count released upon any call to v4l2_async_notifier_cleanup().
Ensure that any source successfully added to a notifier gets its fwnode reference count increased accordingly.
--- drivers/media/i2c/max9286.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/media/i2c/max9286.c +5 -0
@@ -665,6 +665,11 @@ static int max9286_v4l2_async_register(struct max9286_priv *priv)v4l2_async_notifier_cleanup (&priv->notifier);return ret; } + +/* Balance the refernce counting handled through +* v4l2_async_notifier_cleanup() +*/ +fwnode_handle_get (source->fwnode); } priv->notifier.ops = &max9286_notify_ops;
Signature · 1 line
2.20.1
Kieran Bingham
maintainerRe: [PATCH] max9286: balance v4l2_async refcnting
Quoted 18 lines · Kieran Bingham
When we add fwnodes to V4L2 notifiers through
v4l2_async_notifier_add_subdevthey are stored internally in V4L2 core, and have a reference count released upon any call tov4l2_async_notifier_cleanup().Ensure that any source successfully added to a notifier gets its fwnode reference count increased accordingly.
Signed-off-by Kieran Bingham <[email protected]>--- drivers/media/i2c/max9286.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/media/i2c/max9286.c +0
-0
drivers/media/i2c/max9286.c static int max9286_v4l2_async_register(struct max9286_priv *priv) · line 669
Quoted 5 lines
drivers/media/i2c/max9286.c +2
-0@@ -665,6 +665,11 @@ static int max9286_v4l2_async_register(struct max9286_priv *priv)v4l2_async_notifier_cleanup (&priv->notifier);return ret; } + +/* Balance the refernce counting handled through
I've correctly moved this to a new line and fixed up the reference spelling :)
Quoted 7 lines
drivers/media/i2c/max9286.c +3
-0+* v4l2_async_notifier_cleanup() +*/ +fwnode_handle_get (source->fwnode); } priv->notifier.ops = &max9286_notify_ops;
Jacopo Mondi
Acked-byRe: [PATCH] max9286: balance v4l2_async refcnting
Hi Kieran!
Quoted 14 lines · Kieran Bingham
Quoted 13 lines · Kieran Bingham
When we add fwnodes to V4L2 notifiers through
v4l2_async_notifier_add_subdevthey are stored internally in V4L2 core, and have a reference count released upon any call tov4l2_async_notifier_cleanup().Ensure that any source successfully added to a notifier gets its fwnode reference count increased accordingly.
Signed-off-by Kieran Bingham <[email protected]>--- drivers/media/i2c/max9286.c | 5 +++++ 1 file changed, 5 insertions(+)
Quoted 13 lines
drivers/media/i2c/max9286.c static int max9286_v4l2_async_register(struct max9286_priv *priv) · line 669
Quoted 10 lines
drivers/media/i2c/max9286.c +2
-0@@ -665,6 +665,11 @@ static int max9286_v4l2_async_register(struct max9286_priv *priv)v4l2_async_notifier_cleanup (&priv->notifier);return ret; } + +/* Balance the refernce counting handled through I've correctly moved this to a new line and fixed up the reference spelling :)
Good, thanks!
I think you could squash all of these in the next max9286 iteration!
Thanks
j
Quoted 9 lines
Quoted 8 lines
drivers/media/i2c/max9286.c +3
-0+* v4l2_async_notifier_cleanup() +*/ +fwnode_handle_get (source->fwnode); } priv->notifier.ops = &max9286_notify_ops;
Kieran Bingham
maintainerRe: [PATCH] max9286: balance v4l2_async refcnting
Quoted 31 lines · Jacopo Mondi
Hi Kieran!
Quoted 14 lines · Kieran Bingham
Quoted 13 lines · Kieran Bingham
When we add fwnodes to V4L2 notifiers through
v4l2_async_notifier_add_subdevthey are stored internally in V4L2 core, and have a reference count released upon any call tov4l2_async_notifier_cleanup().Ensure that any source successfully added to a notifier gets its fwnode reference count increased accordingly.
Signed-off-by Kieran Bingham <[email protected]>--- drivers/media/i2c/max9286.c | 5 +++++ 1 file changed, 5 insertions(+)Quoted 13 lines
drivers/media/i2c/max9286.c static int max9286_v4l2_async_register(struct max9286_priv *priv) · line 669
Quoted 10 lines
drivers/media/i2c/max9286.c +2
-0@@ -665,6 +665,11 @@ static int max9286_v4l2_async_register(struct max9286_priv *priv)v4l2_async_notifier_cleanup (&priv->notifier);return ret; } + +/* Balance the refernce counting handled through I've correctly moved this to a new line and fixed up the reference spelling :)
Quoted 5 lines
Good, thanks!
I think you could squash all of these in the next max9286 iteration!
Acked-by Jacopo Mondi <[email protected]>
Thankyou, I'll squash and rebase to linux-media/master branch!
\o/
--
Kieran
Quoted 12 lines
Thanks
jQuoted 9 lines
Quoted 8 lines
drivers/media/i2c/max9286.c +3
-0+* v4l2_async_notifier_cleanup() +*/ +fwnode_handle_get (source->fwnode); } priv->notifier.ops = &max9286_notify_ops;