* [PATCH] i2c: i2c-core: do not use bus internal data @ 2016-03-07 11:49 Sudip Mukherjee 2016-03-07 16:57 ` Greg KH ` (2 more replies) 0 siblings, 3 replies; 10+ messages in thread From: Sudip Mukherjee @ 2016-03-07 11:49 UTC (permalink / raw) To: Wolfram Sang; +Cc: linux-kernel, linux-i2c, Sudip Mukherjee, gregkh The variable p is a data structure which is used by the driver core internally and it is not expected that busses will be directly accessing these driver core internal only data. Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk> --- Reference of Greg's comment about it at: https://lkml.org/lkml/2016/3/5/171 drivers/i2c/i2c-core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 2949ab3..2f31fb5 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -73,6 +73,7 @@ static struct device_type i2c_client_type; static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE; +static bool is_registered; void i2c_transfer_trace_reg(void) { @@ -1529,7 +1530,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) int res = 0; /* Can't register until after driver model init */ - if (unlikely(WARN_ON(!i2c_bus_type.p))) { + if (unlikely(WARN_ON(!is_registered))) { res = -EAGAIN; goto out_list; } @@ -1926,7 +1927,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) int res; /* Can't register until after driver model init */ - if (unlikely(WARN_ON(!i2c_bus_type.p))) + if (unlikely(WARN_ON(!is_registered))) return -EAGAIN; /* add the driver to the list of i2c drivers in the driver core */ @@ -2118,6 +2119,7 @@ static int __init i2c_init(void) if (IS_ENABLED(CONFIG_OF_DYNAMIC)) WARN_ON(of_reconfig_notifier_register(&i2c_of_notifier)); + is_registered = true; return 0; class_err: -- 1.9.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] i2c: i2c-core: do not use bus internal data 2016-03-07 11:49 [PATCH] i2c: i2c-core: do not use bus internal data Sudip Mukherjee @ 2016-03-07 16:57 ` Greg KH 2016-03-07 17:17 ` Sudip Mukherjee 2016-03-12 15:14 ` Wolfram Sang 2016-03-14 9:18 ` Thierry Reding 2 siblings, 1 reply; 10+ messages in thread From: Greg KH @ 2016-03-07 16:57 UTC (permalink / raw) To: Sudip Mukherjee; +Cc: Wolfram Sang, linux-kernel, linux-i2c On Mon, Mar 07, 2016 at 05:19:17PM +0530, Sudip Mukherjee wrote: > The variable p is a data structure which is used by the driver core > internally and it is not expected that busses will be directly accessing > these driver core internal only data. > > Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk> > --- > > Reference of Greg's comment about it at: > https://lkml.org/lkml/2016/3/5/171 > > drivers/i2c/i2c-core.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c > index 2949ab3..2f31fb5 100644 > --- a/drivers/i2c/i2c-core.c > +++ b/drivers/i2c/i2c-core.c > @@ -73,6 +73,7 @@ static struct device_type i2c_client_type; > static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); > > static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE; > +static bool is_registered; > > void i2c_transfer_trace_reg(void) > { > @@ -1529,7 +1530,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) > int res = 0; > > /* Can't register until after driver model init */ > - if (unlikely(WARN_ON(!i2c_bus_type.p))) { > + if (unlikely(WARN_ON(!is_registered))) { > res = -EAGAIN; > goto out_list; > } Minor nit, likely/unlikely should only be used on very "hot paths" where the difference if it is not included can be measured. the "register a device" path is not "hot" at all. That being said, the patch is fine with me: Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] i2c: i2c-core: do not use bus internal data 2016-03-07 16:57 ` Greg KH @ 2016-03-07 17:17 ` Sudip Mukherjee 0 siblings, 0 replies; 10+ messages in thread From: Sudip Mukherjee @ 2016-03-07 17:17 UTC (permalink / raw) To: Greg KH; +Cc: Wolfram Sang, linux-kernel, linux-i2c On Monday 07 March 2016 10:27 PM, Greg KH wrote: > On Mon, Mar 07, 2016 at 05:19:17PM +0530, Sudip Mukherjee wrote: >> The variable p is a data structure which is used by the driver core >> internally and it is not expected that busses will be directly accessing >> these driver core internal only data. >> >> Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk> >> --- >> >> Reference of Greg's comment about it at: >> https://lkml.org/lkml/2016/3/5/171 >> >> drivers/i2c/i2c-core.c | 6 ++++-- >> 1 file changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c >> index 2949ab3..2f31fb5 100644 >> --- a/drivers/i2c/i2c-core.c >> +++ b/drivers/i2c/i2c-core.c >> @@ -73,6 +73,7 @@ static struct device_type i2c_client_type; >> static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); >> >> static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE; >> +static bool is_registered; >> >> void i2c_transfer_trace_reg(void) >> { >> @@ -1529,7 +1530,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) >> int res = 0; >> >> /* Can't register until after driver model init */ >> - if (unlikely(WARN_ON(!i2c_bus_type.p))) { >> + if (unlikely(WARN_ON(!is_registered))) { >> res = -EAGAIN; >> goto out_list; >> } > > Minor nit, likely/unlikely should only be used on very "hot paths" where > the difference if it is not included can be measured. the "register a > device" path is not "hot" at all. I can submit a patch afterwards to remove the "unlikely" if that is ok with Wolfram. regards sudip ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] i2c: i2c-core: do not use bus internal data 2016-03-07 11:49 [PATCH] i2c: i2c-core: do not use bus internal data Sudip Mukherjee 2016-03-07 16:57 ` Greg KH @ 2016-03-12 15:14 ` Wolfram Sang 2016-03-14 9:18 ` Thierry Reding 2 siblings, 0 replies; 10+ messages in thread From: Wolfram Sang @ 2016-03-12 15:14 UTC (permalink / raw) To: Sudip Mukherjee; +Cc: linux-kernel, linux-i2c, gregkh [-- Attachment #1: Type: text/plain, Size: 387 bytes --] On Mon, Mar 07, 2016 at 05:19:17PM +0530, Sudip Mukherjee wrote: > The variable p is a data structure which is used by the driver core > internally and it is not expected that busses will be directly accessing > these driver core internal only data. > > Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk> Removed the unlikely() and applied to for-next, thanks! [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] i2c: i2c-core: do not use bus internal data 2016-03-07 11:49 [PATCH] i2c: i2c-core: do not use bus internal data Sudip Mukherjee 2016-03-07 16:57 ` Greg KH 2016-03-12 15:14 ` Wolfram Sang @ 2016-03-14 9:18 ` Thierry Reding 2016-03-14 9:27 ` Thierry Reding 2016-03-14 9:28 ` Wolfram Sang 2 siblings, 2 replies; 10+ messages in thread From: Thierry Reding @ 2016-03-14 9:18 UTC (permalink / raw) To: Sudip Mukherjee; +Cc: Wolfram Sang, linux-kernel, linux-i2c, gregkh [-- Attachment #1: Type: text/plain, Size: 2228 bytes --] On Mon, Mar 07, 2016 at 05:19:17PM +0530, Sudip Mukherjee wrote: > The variable p is a data structure which is used by the driver core > internally and it is not expected that busses will be directly accessing > these driver core internal only data. > > Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk> > --- > > Reference of Greg's comment about it at: > https://lkml.org/lkml/2016/3/5/171 > > drivers/i2c/i2c-core.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c > index 2949ab3..2f31fb5 100644 > --- a/drivers/i2c/i2c-core.c > +++ b/drivers/i2c/i2c-core.c > @@ -73,6 +73,7 @@ static struct device_type i2c_client_type; > static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); > > static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE; > +static bool is_registered; > > void i2c_transfer_trace_reg(void) > { > @@ -1529,7 +1530,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) > int res = 0; > > /* Can't register until after driver model init */ > - if (unlikely(WARN_ON(!i2c_bus_type.p))) { > + if (unlikely(WARN_ON(!is_registered))) { > res = -EAGAIN; > goto out_list; > } > @@ -1926,7 +1927,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) > int res; > > /* Can't register until after driver model init */ > - if (unlikely(WARN_ON(!i2c_bus_type.p))) > + if (unlikely(WARN_ON(!is_registered))) > return -EAGAIN; > > /* add the driver to the list of i2c drivers in the driver core */ > @@ -2118,6 +2119,7 @@ static int __init i2c_init(void) > if (IS_ENABLED(CONFIG_OF_DYNAMIC)) > WARN_ON(of_reconfig_notifier_register(&i2c_of_notifier)); > > + is_registered = true; > return 0; > > class_err: This doesn't work. I see a number of these WARN_ON()s trigger and I think the reason is that i2c_init() always fails now. The cause seems to be that i2c_init() calls i2c_add_driver(&dummy_driver), which will now always fail, because is_register is set to true *after* that call. There is no way I see I2C working at all after this patch. Thierry [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] i2c: i2c-core: do not use bus internal data 2016-03-14 9:18 ` Thierry Reding @ 2016-03-14 9:27 ` Thierry Reding 2016-03-14 12:15 ` Sudeep Holla 2016-03-14 9:28 ` Wolfram Sang 1 sibling, 1 reply; 10+ messages in thread From: Thierry Reding @ 2016-03-14 9:27 UTC (permalink / raw) To: Sudip Mukherjee; +Cc: Wolfram Sang, linux-kernel, linux-i2c, gregkh [-- Attachment #1: Type: text/plain, Size: 3061 bytes --] On Mon, Mar 14, 2016 at 10:18:19AM +0100, Thierry Reding wrote: > On Mon, Mar 07, 2016 at 05:19:17PM +0530, Sudip Mukherjee wrote: > > The variable p is a data structure which is used by the driver core > > internally and it is not expected that busses will be directly accessing > > these driver core internal only data. > > > > Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk> > > --- > > > > Reference of Greg's comment about it at: > > https://lkml.org/lkml/2016/3/5/171 > > > > drivers/i2c/i2c-core.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c > > index 2949ab3..2f31fb5 100644 > > --- a/drivers/i2c/i2c-core.c > > +++ b/drivers/i2c/i2c-core.c > > @@ -73,6 +73,7 @@ static struct device_type i2c_client_type; > > static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); > > > > static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE; > > +static bool is_registered; > > > > void i2c_transfer_trace_reg(void) > > { > > @@ -1529,7 +1530,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) > > int res = 0; > > > > /* Can't register until after driver model init */ > > - if (unlikely(WARN_ON(!i2c_bus_type.p))) { > > + if (unlikely(WARN_ON(!is_registered))) { > > res = -EAGAIN; > > goto out_list; > > } > > @@ -1926,7 +1927,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) > > int res; > > > > /* Can't register until after driver model init */ > > - if (unlikely(WARN_ON(!i2c_bus_type.p))) > > + if (unlikely(WARN_ON(!is_registered))) > > return -EAGAIN; > > > > /* add the driver to the list of i2c drivers in the driver core */ > > @@ -2118,6 +2119,7 @@ static int __init i2c_init(void) > > if (IS_ENABLED(CONFIG_OF_DYNAMIC)) > > WARN_ON(of_reconfig_notifier_register(&i2c_of_notifier)); > > > > + is_registered = true; > > return 0; > > > > class_err: > > This doesn't work. I see a number of these WARN_ON()s trigger and I > think the reason is that i2c_init() always fails now. The cause seems to > be that i2c_init() calls i2c_add_driver(&dummy_driver), which will now > always fail, because is_register is set to true *after* that call. There > is no way I see I2C working at all after this patch. FWIW, the below on top of your patch seems to fix things for me. Thierry --- >8 --- diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index f4726cdbb06a..f8723a474e28 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -2112,6 +2112,8 @@ static int __init i2c_init(void) goto bus_err; } #endif + is_registered = true; + retval = i2c_add_driver(&dummy_driver); if (retval) goto class_err; @@ -2119,7 +2121,6 @@ static int __init i2c_init(void) if (IS_ENABLED(CONFIG_OF_DYNAMIC)) WARN_ON(of_reconfig_notifier_register(&i2c_of_notifier)); - is_registered = true; return 0; class_err: [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] i2c: i2c-core: do not use bus internal data 2016-03-14 9:27 ` Thierry Reding @ 2016-03-14 12:15 ` Sudeep Holla 0 siblings, 0 replies; 10+ messages in thread From: Sudeep Holla @ 2016-03-14 12:15 UTC (permalink / raw) To: Thierry Reding, Sudip Mukherjee, Wolfram Sang Cc: open list, linux-i2c, Greg Kroah-Hartman On Mon, Mar 14, 2016 at 9:27 AM, Thierry Reding <thierry.reding@gmail.com> wrote: > On Mon, Mar 14, 2016 at 10:18:19AM +0100, Thierry Reding wrote: >> On Mon, Mar 07, 2016 at 05:19:17PM +0530, Sudip Mukherjee wrote: >> > The variable p is a data structure which is used by the driver core >> > internally and it is not expected that busses will be directly accessing >> > these driver core internal only data. >> > >> > Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk> >> > --- >> > >> > Reference of Greg's comment about it at: >> > https://lkml.org/lkml/2016/3/5/171 >> > >> > drivers/i2c/i2c-core.c | 6 ++++-- >> > 1 file changed, 4 insertions(+), 2 deletions(-) >> > >> > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c >> > index 2949ab3..2f31fb5 100644 >> > --- a/drivers/i2c/i2c-core.c >> > +++ b/drivers/i2c/i2c-core.c >> > @@ -73,6 +73,7 @@ static struct device_type i2c_client_type; >> > static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); >> > >> > static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE; >> > +static bool is_registered; >> > >> > void i2c_transfer_trace_reg(void) >> > { >> > @@ -1529,7 +1530,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) >> > int res = 0; >> > >> > /* Can't register until after driver model init */ >> > - if (unlikely(WARN_ON(!i2c_bus_type.p))) { >> > + if (unlikely(WARN_ON(!is_registered))) { >> > res = -EAGAIN; >> > goto out_list; >> > } >> > @@ -1926,7 +1927,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) >> > int res; >> > >> > /* Can't register until after driver model init */ >> > - if (unlikely(WARN_ON(!i2c_bus_type.p))) >> > + if (unlikely(WARN_ON(!is_registered))) >> > return -EAGAIN; >> > >> > /* add the driver to the list of i2c drivers in the driver core */ >> > @@ -2118,6 +2119,7 @@ static int __init i2c_init(void) >> > if (IS_ENABLED(CONFIG_OF_DYNAMIC)) >> > WARN_ON(of_reconfig_notifier_register(&i2c_of_notifier)); >> > >> > + is_registered = true; >> > return 0; >> > >> > class_err: >> >> This doesn't work. I see a number of these WARN_ON()s trigger and I >> think the reason is that i2c_init() always fails now. The cause seems to >> be that i2c_init() calls i2c_add_driver(&dummy_driver), which will now >> always fail, because is_register is set to true *after* that call. There >> is no way I see I2C working at all after this patch. Exactly, and this is resulting in recursive failures on dev platform ending up in boot failure > > FWIW, the below on top of your patch seems to fix things for me. > I too came up with same patch, good that I searched before posting it out. FWIW, it fixes the recursive fault at boot on my arm64 platform. Regards, Sudeep ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] i2c: i2c-core: do not use bus internal data 2016-03-14 9:18 ` Thierry Reding 2016-03-14 9:27 ` Thierry Reding @ 2016-03-14 9:28 ` Wolfram Sang 2016-03-14 9:39 ` Thierry Reding 2016-03-14 14:25 ` Sudip Mukherjee 1 sibling, 2 replies; 10+ messages in thread From: Wolfram Sang @ 2016-03-14 9:28 UTC (permalink / raw) To: Thierry Reding; +Cc: Sudip Mukherjee, linux-kernel, linux-i2c, gregkh [-- Attachment #1: Type: text/plain, Size: 483 bytes --] > This doesn't work. I see a number of these WARN_ON()s trigger and I > think the reason is that i2c_init() always fails now. The cause seems to > be that i2c_init() calls i2c_add_driver(&dummy_driver), which will now > always fail, because is_register is set to true *after* that call. There > is no way I see I2C working at all after this patch. Same conclusion here. Too much trust applied to the original patch, mea culpa and sorry! Will send the fixup (tested!) in a minute. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] i2c: i2c-core: do not use bus internal data 2016-03-14 9:28 ` Wolfram Sang @ 2016-03-14 9:39 ` Thierry Reding 2016-03-14 14:25 ` Sudip Mukherjee 1 sibling, 0 replies; 10+ messages in thread From: Thierry Reding @ 2016-03-14 9:39 UTC (permalink / raw) To: Wolfram Sang; +Cc: Sudip Mukherjee, linux-kernel, linux-i2c, gregkh [-- Attachment #1: Type: text/plain, Size: 687 bytes --] On Mon, Mar 14, 2016 at 10:28:10AM +0100, Wolfram Sang wrote: > > > This doesn't work. I see a number of these WARN_ON()s trigger and I > > think the reason is that i2c_init() always fails now. The cause seems to > > be that i2c_init() calls i2c_add_driver(&dummy_driver), which will now > > always fail, because is_register is set to true *after* that call. There > > is no way I see I2C working at all after this patch. > > Same conclusion here. Too much trust applied to the original patch, mea > culpa and sorry! Will send the fixup (tested!) in a minute. No worries. There's nothing like good old runtime testing for making sure things really do work. =) Thierry [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] i2c: i2c-core: do not use bus internal data 2016-03-14 9:28 ` Wolfram Sang 2016-03-14 9:39 ` Thierry Reding @ 2016-03-14 14:25 ` Sudip Mukherjee 1 sibling, 0 replies; 10+ messages in thread From: Sudip Mukherjee @ 2016-03-14 14:25 UTC (permalink / raw) To: Wolfram Sang; +Cc: Thierry Reding, linux-kernel, linux-i2c, gregkh On Mon, Mar 14, 2016 at 10:28:10AM +0100, Wolfram Sang wrote: > > > This doesn't work. I see a number of these WARN_ON()s trigger and I > > think the reason is that i2c_init() always fails now. The cause seems to > > be that i2c_init() calls i2c_add_driver(&dummy_driver), which will now > > always fail, because is_register is set to true *after* that call. There > > is no way I see I2C working at all after this patch. > > Same conclusion here. Too much trust applied to the original patch, mea > culpa and sorry! Will send the fixup (tested!) in a minute. Sorry for the mess. Fengguang Wu did send me a warning, but since I was travelling i could not do much with it. Sorry again. regards sudip ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2016-03-14 14:25 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-03-07 11:49 [PATCH] i2c: i2c-core: do not use bus internal data Sudip Mukherjee 2016-03-07 16:57 ` Greg KH 2016-03-07 17:17 ` Sudip Mukherjee 2016-03-12 15:14 ` Wolfram Sang 2016-03-14 9:18 ` Thierry Reding 2016-03-14 9:27 ` Thierry Reding 2016-03-14 12:15 ` Sudeep Holla 2016-03-14 9:28 ` Wolfram Sang 2016-03-14 9:39 ` Thierry Reding 2016-03-14 14:25 ` Sudip Mukherjee
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).