Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1418179
| From | Chris Wilson <chris@chris-wilson.co.uk> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 2/3] i2c: Mark adapter as initialised |
| Date | 2016-06-09 11:00 +0200 |
| Message-ID | <rI3YJ-42v-21@gated-at.bofh.it> (permalink) |
| References | <rI3YJ-42v-11@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
In order to allow drivers to call i2c_init_adapter as a separate step,
and to allow other drivers to continue skipping the call, mark the
adapter as initialised upon i2c_init_adapter() and ignore multiple
calls.
The choice of how to introduce an "already-initialised" check into the
existing i2c_add_adapter() callers is tricky as we cannot make too many
assumptions about the state of memory, i.e. whether the struct was
cleared before being passed to i2c_add_adapter. This poses an issue if
we wanted to add a boolean flag to mark when the adapter is initialised
(as that flag may be set due to previous contents of memory). Instead,
we opt to use the userspace_client_lists as that should be empty from
initialisation through to registration - but will be reported as !empty
if it has either random junk or zeroes (with a very small chance that we
fail to register an adapter that just happens to have a prior empty list
at that location in memory).
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-i2c@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
---
drivers/i2c/i2c-core.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 743c38a63da1..91ff70d31ec8 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1513,6 +1513,10 @@ static int __process_new_adapter(struct device_driver *d, void *data)
static int i2c_init_adapter(struct i2c_adapter *adap)
{
+ /* Only initialise the adapter once. */
+ if (list_empty(&adap->userspace_clients))
+ return 0;
+
/* Sanity checks */
if (unlikely(adap->name[0] == '\0')) {
pr_err("i2c-core: Attempt to register an adapter with "
@@ -1632,6 +1636,9 @@ out_list:
mutex_lock(&core_lock);
idr_remove(&i2c_adapter_idr, adap->nr);
mutex_unlock(&core_lock);
+
+ /* Force initialisation if this struct gets reused */
+ memset(&adap->userspace_clients, 0, sizeof(adap->userspace_clients));
return res;
}
--
2.8.1
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH 1/3] i2c: Split adapter initialisation from registers Chris Wilson <chris@chris-wilson.co.uk> - 2016-06-09 11:00 +0200 [PATCH 2/3] i2c: Mark adapter as initialised Chris Wilson <chris@chris-wilson.co.uk> - 2016-06-09 11:00 +0200
csiph-web