mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Wolfram Sang <wsa@kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Andi Shyti <andi.shyti@kernel.org>,
	Biju Das <biju.das.jz@bp.renesas.com>,
	Jonathan Cameron <jic23@kernel.org>,
	Michael Hennerich <michael.hennerich@analog.com>,
	Peter Rosin <peda@axentia.se>
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH RFC 1/4] i2c: start migrating to a pointer in i2c_device_id
Date: Mon, 14 Aug 2023 14:52:49 -0700	[thread overview]
Message-ID: <20230814-i2c-id-rework-v1-1-3e5bc71c49ee@gmail.com> (raw)
In-Reply-To: <20230814-i2c-id-rework-v1-0-3e5bc71c49ee@gmail.com>

The of_device_id structure uses a void pointer to associate additional
driver-private data with device id, most commonly used to refer to a
structure containing additional characteristics of a particular chip.
However i2c_device_id uses an unsigned long. While it can easily be
converted to a pointer, several drivers use it to store a scalar (and it
is possible to use a pointer in of_device_id to store a scalar value as
well). The worst case comes when OF part of a driver uses pointers,
while legacy part is using scalars, causing constructs like:

	data = device_get_match_data(...);
	if (!data)
		data = &some_array[i2c_match_id(...)->data];
	...

To avoid this introduce a const void "data" pointer to i2c_device_id as
well, so that we can convert drivers one by one, and drop driver_data
member in the end.

The end goal is to clean up all helpers and make device_get_match_data()
work universally for all ACPI, DT, and legacy variants.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/i2c/i2c-core-base.c     | 2 +-
 include/linux/mod_devicetable.h | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 60746652fd52..75d12d79d8f1 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -126,7 +126,7 @@ const void *i2c_get_match_data(const struct i2c_client *client)
 		if (!match)
 			return NULL;
 
-		data = (const void *)match->driver_data;
+		data = match->data ?: (const void *)match->driver_data;
 	}
 
 	return data;
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index b0678b093cb2..21ac2a96e828 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -477,7 +477,8 @@ struct rpmsg_device_id {
 
 struct i2c_device_id {
 	char name[I2C_NAME_SIZE];
-	kernel_ulong_t driver_data;	/* Data private to the driver */
+	kernel_ulong_t driver_data;	/* This field is obsolete */
+	const void *data;		/* Data private to the driver */
 };
 
 /* pci_epf */

-- 
2.41.0.694.ge786442a9b-goog


  reply	other threads:[~2023-08-14 21:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-14 21:52 [PATCH RFC 0/4] Start unification of of_device_id and i2c_device_id Dmitry Torokhov
2023-08-14 21:52 ` Dmitry Torokhov [this message]
2023-08-15 15:55   ` [PATCH RFC 1/4] i2c: start migrating to a pointer in i2c_device_id Andy Shevchenko
2023-08-14 21:52 ` [PATCH RFC 2/4] i2c: mux: ltc4306: convert to using " Dmitry Torokhov
2023-08-15 15:50   ` Andy Shevchenko
2023-08-14 21:52 ` [PATCH RFC 3/4] i2c: mux: pca954x: " Dmitry Torokhov
2023-08-15 15:51   ` Andy Shevchenko
2023-08-14 21:52 ` [PATCH RFC 4/4] i2c: slave-eeprom: " Dmitry Torokhov
2023-08-15 15:53   ` Andy Shevchenko

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=20230814-i2c-id-rework-v1-1-3e5bc71c49ee@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=andi.shyti@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=jic23@kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    --cc=peda@axentia.se \
    --cc=wsa@kernel.org \
    /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

all inboxes | Powered by JetHome®