lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1465462435-5240-2-git-send-email-chris@chris-wilson.co.uk>
Date:	Thu,  9 Jun 2016 09:53:54 +0100
From:	Chris Wilson <chris@...is-wilson.co.uk>
To:	linux-i2c@...r.kernel.org
Cc:	Chris Wilson <chris@...is-wilson.co.uk>,
	Ville Syrjälä 
	<ville.syrjala@...ux.intel.com>, Wolfram Sang <wsa@...-dreams.de>,
	linux-kernel@...r.kernel.org, dri-devel@...ts.freedesktop.org
Subject: [PATCH 2/3] i2c: Mark adapter as initialised

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@...is-wilson.co.uk>
Cc: Ville Syrjälä <ville.syrjala@...ux.intel.com>
Cc: Wolfram Sang <wsa@...-dreams.de>
Cc: linux-i2c@...r.kernel.org
Cc: linux-kernel@...r.kernel.org
Cc: dri-devel@...ts.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ