drm/bridge: adv7511: Fix cec clock EPROBE_DEFER handling
Subsystems (3)
PATCH 1/1 drm/bridge: adv7511: Fix cec clock EPROBE_DEFER handling
If adv7511's devm_clk_get() for the cec clock returns -EPROBE_DEFER, we end up in an infinite probe loop. This happens:
(1) adv7511's probe is called.
(2) adv7511's probe adds some secondary i2c devices which bind to the dummy driver and thus call driver_deferred_probe_trigger() and increment deferred_trigger_count (see driver_bound()).
(3) adv7511's probe returns -EPROBE_DEFER, and since the deferred_trigger_count has changed during the probe call, driver_deferred_probe_trigger() is called immediately (see really_probe()) and adv7511's probe is scheduled.
(4) Goto step 1.
[ 61.972915] really_probe: bus: 'i2c': really_probe: probing driver adv7511 with device 0-0039 [ 61.992734] really_probe: bus: 'i2c': really_probe: probing driver dummy with device 0-003f [ 61.993343] driver_bound: driver: 'dummy': driver_bound: bound to device '0-003f' [ 61.993626] really_probe: bus: 'i2c': really_probe: bound device 0-003f to driver dummy [ 61.995604] really_probe: bus: 'i2c': really_probe: probing driver dummy with device 0-0038 [ 61.996381] driver_bound: driver: 'dummy': driver_bound: bound to device '0-0038' [ 61.996663] really_probe: bus: 'i2c': really_probe: bound device 0-0038 to driver dummy [ 61.998651] really_probe: bus: 'i2c': really_probe: probing driver dummy with device 0-003c [ 61.999222] driver_bound: driver: 'dummy': driver_bound: bound to device '0-003c' [ 61.999496] really_probe: bus: 'i2c': really_probe: bound device 0-003c to driver dummy [ 62.010050] really_probe: i2c 0-0039: Driver adv7511 requests probe deferral [ 62.011380] really_probe: bus: 'platform': really_probe: probing driver pwm-clock with device clock-cec [ 62.012812] really_probe: platform clock-cec: Driver pwm-clock requests probe deferral [ 62.024679] really_probe: bus: 'i2c': really_probe: probing driver adv7511 with device 0-0039
Fix this by calling devm_clk_get() before registering the secondary devices.
--- drivers/gpu/drm/bridge/adv7511/adv7511_cec.c | 30 +++++++------------- drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 11 +++++-- 2 files changed, 20 insertions(+), 21 deletions(-)
drivers/gpu/drm/bridge/adv7511/adv7511_cec.c +11 -19
@@ -286,28 +286,17 @@ static const struct cec_adap_ops adv7511_cec_adap_ops = { .adap_transmit = adv7511_cec_adap_transmit, }; -static int adv7511_cec_parse_dt (struct device *dev,struct adv7511 *adv7511) -{ - adv7511->cec_clk =devm_clk_get (dev,"cec" ); -if (IS_ERR (adv7511->cec_clk)) { -int ret =PTR_ERR (adv7511->cec_clk); - - adv7511->cec_clk =NULL ; -return ret; - } -clk_prepare_enable (adv7511->cec_clk); - adv7511->cec_clk_freq =clk_get_rate (adv7511->cec_clk); -return 0 ; -} -int adv7511_cec_init (struct device *dev,struct adv7511 *adv7511) {unsigned int offset = adv7511->type ==ADV7533 ?ADV7533_REG_CEC_OFFSET :0 ; -int ret =adv7511_cec_parse_dt (dev, adv7511); +int ret; -if (ret) - goto err_cec_parse_dt; +if (!adv7511->cec_clk) + goto err_cec_no_clock; + +clk_prepare_enable (adv7511->cec_clk); + adv7511->cec_clk_freq =clk_get_rate (adv7511->cec_clk); adv7511->cec_adap =cec_allocate_adapter (&adv7511_cec_adap_ops, adv7511,dev_name (dev),CEC_CAP_DEFAULTS ,ADV7511_MAX_ADDRS );
@@ -342,8 +331,11 @@ int adv7511_cec_init(struct device *dev, struct adv7511 *adv7511) err_cec_alloc:dev_info (dev,"Initializing CEC failed with error %d, disabling CEC\n" , ret); -err_cec_parse_dt: +clk_disable_unprepare (adv7511->cec_clk); +/* Ensure that adv7511_remove() doesn't attempt to disable it again. */ + adv7511->cec_clk =NULL ; +err_cec_no_clock:regmap_write (adv7511->regmap,ADV7511_REG_CEC_CTRL + offset,ADV7511_CEC_CTRL_POWER_DOWN ); -return ret == -EPROBE_DEFER ? ret :0 ; +return 0 ; }
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +9 -2
@@ -1122,6 +1122,15 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)if (ret)return ret; + adv7511->cec_clk =devm_clk_get (dev,"cec" ); +if (IS_ERR (adv7511->cec_clk)) { + ret =PTR_ERR (adv7511->cec_clk); +if (ret == -EPROBE_DEFER ) +return ret; + + adv7511->cec_clk =NULL ; + } + ret =adv7511_init_regulators (adv7511);if (ret) {dev_err (dev,"failed to init regulators\n" );
@@ -1226,8 +1235,6 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id) err_unregister_cec:i2c_unregister_device (adv7511->i2c_cec); -if (adv7511->cec_clk) -clk_disable_unprepare (adv7511->cec_clk); err_i2c_unregister_packet:i2c_unregister_device (adv7511->i2c_packet); err_i2c_unregister_edid:
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Vincent,
Thank you for the patch.
Quoted 9 lines · Vincent Whitchurch
If adv7511's
devm_clk_get()for the cec clock returns -EPROBE_DEFER, we end up in an infinite probe loop. This happens:(1) adv7511's probe is called.
(2) adv7511's probe adds some secondary i2c devices which bind to the dummy driver and thus call
driver_deferred_probe_trigger()and incrementdeferred_trigger_count(seedriver_bound()).
Quoted 6 lines
(3) adv7511's probe returns -EPROBE_DEFER, and since the
deferred_trigger_counthas changed during the probe call,driver_deferred_probe_trigger()is called immediately (seereally_probe()) and adv7511's probe is scheduled.(4) Goto step 1.
Lovely :-S
Quoted 64 lines
[ 61.972915] really_probe: bus: 'i2c': really_probe: probing driver adv7511 with device 0-0039 [ 61.992734] really_probe: bus: 'i2c': really_probe: probing driver dummy with device 0-003f [ 61.993343] driver_bound: driver: 'dummy': driver_bound: bound to device '0-003f' [ 61.993626] really_probe: bus: 'i2c': really_probe: bound device 0-003f to driver dummy [ 61.995604] really_probe: bus: 'i2c': really_probe: probing driver dummy with device 0-0038 [ 61.996381] driver_bound: driver: 'dummy': driver_bound: bound to device '0-0038' [ 61.996663] really_probe: bus: 'i2c': really_probe: bound device 0-0038 to driver dummy [ 61.998651] really_probe: bus: 'i2c': really_probe: probing driver dummy with device 0-003c [ 61.999222] driver_bound: driver: 'dummy': driver_bound: bound to device '0-003c' [ 61.999496] really_probe: bus: 'i2c': really_probe: bound device 0-003c to driver dummy [ 62.010050] really_probe: i2c 0-0039: Driver adv7511 requests probe deferral [ 62.011380] really_probe: bus: 'platform': really_probe: probing driver pwm-clock with device clock-cec [ 62.012812] really_probe: platform clock-cec: Driver pwm-clock requests probe deferral [ 62.024679] really_probe: bus: 'i2c': really_probe: probing driver adv7511 with device 0-0039Fix this by calling
devm_clk_get()before registering the secondary devices.Signed-off-by Vincent Whitchurch <[email protected]>--- drivers/gpu/drm/bridge/adv7511/adv7511_cec.c | 30 +++++++------------- drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 11 +++++-- 2 files changed, 20 insertions(+), 21 deletions(-)drivers/gpu/drm/bridge/adv7511/adv7511_cec.c +6
-17@@ -286,28 +286,17 @@ static const struct cec_adap_ops adv7511_cec_adap_ops = { .adap_transmit = adv7511_cec_adap_transmit, }; -static int adv7511_cec_parse_dt (struct device *dev,struct adv7511 *adv7511) -{ - adv7511->cec_clk =devm_clk_get (dev,"cec" ); -if (IS_ERR (adv7511->cec_clk)) { -int ret =PTR_ERR (adv7511->cec_clk); - - adv7511->cec_clk =NULL ; -return ret; - } -clk_prepare_enable (adv7511->cec_clk); - adv7511->cec_clk_freq =clk_get_rate (adv7511->cec_clk); -return 0 ; -} -int adv7511_cec_init (struct device *dev,struct adv7511 *adv7511) {unsigned int offset = adv7511->type ==ADV7533 ?ADV7533_REG_CEC_OFFSET :0 ; -int ret =adv7511_cec_parse_dt (dev, adv7511); +int ret; -if (ret) - goto err_cec_parse_dt; +if (!adv7511->cec_clk) + goto err_cec_no_clock; + +clk_prepare_enable (adv7511->cec_clk); + adv7511->cec_clk_freq =clk_get_rate (adv7511->cec_clk); adv7511->cec_adap =cec_allocate_adapter (&adv7511_cec_adap_ops, adv7511,dev_name (dev),CEC_CAP_DEFAULTS ,ADV7511_MAX_ADDRS );
drivers/gpu/drm/bridge/adv7511/adv7511_cec.c int adv7511_cec_init(struct device *dev, struct adv7511 *adv7511) · line 335
Quoted 6 lines
drivers/gpu/drm/bridge/adv7511/adv7511_cec.c +2
-1@@ -342,8 +331,11 @@ int adv7511_cec_init(struct device *dev, struct adv7511 *adv7511) err_cec_alloc:dev_info (dev,"Initializing CEC failed with error %d, disabling CEC\n" , ret); -err_cec_parse_dt: +clk_disable_unprepare (adv7511->cec_clk); +/* Ensure that adv7511_remove() doesn't attempt to disable it again. */
Would it make sense to call devm_clk_put() here to already release the clock ? Apart from that,
Quoted 36 lines
drivers/gpu/drm/bridge/adv7511/adv7511_cec.c +3
-1+ adv7511->cec_clk =NULL ; +err_cec_no_clock:regmap_write (adv7511->regmap,ADV7511_REG_CEC_CTRL + offset,ADV7511_CEC_CTRL_POWER_DOWN ); -return ret == -EPROBE_DEFER ? ret :0 ; +return 0 ; }drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +9
-2@@ -1122,6 +1122,15 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)if (ret)return ret; + adv7511->cec_clk =devm_clk_get (dev,"cec" ); +if (IS_ERR (adv7511->cec_clk)) { + ret =PTR_ERR (adv7511->cec_clk); +if (ret == -EPROBE_DEFER ) +return ret; + + adv7511->cec_clk =NULL ; + } + ret =adv7511_init_regulators (adv7511);if (ret) {dev_err (dev,"failed to init regulators\n" );@@ -1226,8 +1235,6 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id) err_unregister_cec:i2c_unregister_device (adv7511->i2c_cec); -if (adv7511->cec_clk) -clk_disable_unprepare (adv7511->cec_clk); err_i2c_unregister_packet:i2c_unregister_device (adv7511->i2c_packet); err_i2c_unregister_edid:
Signature · 7 lines
Regards, Laurent Pinchart _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 16 lines · Laurent Pinchart
Quoted 15 lines · Vincent Whitchurch
int
adv7511_cec_init(struct device *dev, struct adv7511 *adv7511){drivers/gpu/drm/bridge/adv7511/adv7511_cec.c +6
-3unsigned int offset = adv7511->type ==ADV7533 ?ADV7533_REG_CEC_OFFSET :0 ; -int ret =adv7511_cec_parse_dt (dev, adv7511); +int ret; -if (ret) - goto err_cec_parse_dt; +if (!adv7511->cec_clk) + goto err_cec_no_clock; + +clk_prepare_enable (adv7511->cec_clk); + adv7511->cec_clk_freq =clk_get_rate (adv7511->cec_clk);
Quoted 12 lines
drivers/gpu/drm/bridge/adv7511/adv7511_cec.c int adv7511_cec_init(struct device *dev, struct adv7511 *adv7511) · line 335
Quoted 9 lines
drivers/gpu/drm/bridge/adv7511/adv7511_cec.c +2
-1adv7511->cec_adap =cec_allocate_adapter (&adv7511_cec_adap_ops, adv7511,dev_name (dev),CEC_CAP_DEFAULTS ,ADV7511_MAX_ADDRS );@@ -342,8 +331,11 @@ int adv7511_cec_init(struct device *dev, struct adv7511 *adv7511) err_cec_alloc:dev_info (dev,"Initializing CEC failed with error %d, disabling CEC\n" , ret); -err_cec_parse_dt: +clk_disable_unprepare (adv7511->cec_clk); +/* Ensure that adv7511_remove() doesn't attempt to disable it again. */ Would it make sense to call
devm_clk_put()here to already release the clock ?
I've just sent out a v2 with this added. Thank you for the review!
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel