linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: linux-i2c@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org, Wolfram Sang <wsa@the-dreams.de>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] i2c: Mark adapter as initialised
Date: Thu,  9 Jun 2016 09:53:54 +0100	[thread overview]
Message-ID: <1465462435-5240-2-git-send-email-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <1465462435-5240-1-git-send-email-chris@chris-wilson.co.uk>

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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2016-06-09  8:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-09  8:53 [PATCH 1/3] i2c: Split adapter initialisation from registers Chris Wilson
2016-06-09  8:53 ` Chris Wilson [this message]
2016-06-09  8:53 ` [PATCH 3/3] i2c: Export i2c_init_adapter() for use by drivers in early initialisation Chris Wilson
2016-08-23 21:33   ` Wolfram Sang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1465462435-5240-2-git-send-email-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).