* [PATCH 1/2] i2c: implement i2c_verify_adapter
@ 2012-04-17 18:43 Stephen Warren
[not found] ` <1334688214-8400-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Stephen Warren @ 2012-04-17 18:43 UTC (permalink / raw)
To: Grant Likely, Rob Herring, Ben Dooks, Wolfram Sang
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
linux-i2c-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
This converts a struct device * to a struct i2c_adapter * while verifying
that the device really is an I2C adapter. Just like i2c_verify_client.
Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
drivers/i2c/i2c-core.c | 17 +++++++++++++++++
include/linux/i2c.h | 1 +
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index feb7dc3..a6ad32b 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -772,6 +772,23 @@ struct device_type i2c_adapter_type = {
};
EXPORT_SYMBOL_GPL(i2c_adapter_type);
+/**
+ * i2c_verify_adapter - return parameter as i2c_adapter or NULL
+ * @dev: device, probably from some driver model iterator
+ *
+ * When traversing the driver model tree, perhaps using driver model
+ * iterators like @device_for_each_child(), you can't assume very much
+ * about the nodes you find. Use this function to avoid oopses caused
+ * by wrongly treating some non-I2C device as an i2c_adapter.
+ */
+struct i2c_adapter *i2c_verify_adapter(struct device *dev)
+{
+ return (dev->type == &i2c_adapter_type)
+ ? to_i2c_adapter(dev)
+ : NULL;
+}
+EXPORT_SYMBOL(i2c_verify_adapter);
+
#ifdef CONFIG_I2C_COMPAT
static struct class_compat *i2c_adapter_compat_class;
#endif
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 195d8b3..b66cb60 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -232,6 +232,7 @@ struct i2c_client {
#define to_i2c_client(d) container_of(d, struct i2c_client, dev)
extern struct i2c_client *i2c_verify_client(struct device *dev);
+extern struct i2c_adapter *i2c_verify_adapter(struct device *dev);
static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
{
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] of/i2c: implement of_find_i2c_adapter_by_node
[not found] ` <1334688214-8400-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
@ 2012-04-17 18:43 ` Stephen Warren
[not found] ` <1334688214-8400-2-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-17 18:49 ` [PATCH 1/2] i2c: implement i2c_verify_adapter Jean Delvare
1 sibling, 1 reply; 6+ messages in thread
From: Stephen Warren @ 2012-04-17 18:43 UTC (permalink / raw)
To: Grant Likely, Rob Herring, Ben Dooks, Wolfram Sang
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
linux-i2c-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
This finds the struct i2c_adapter * for a given device tree node. Just
like of_find_i2c_device_by_node.
Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
Note: This series is a dependency for the pinctrl I2C bus mux I will send in a
minute. It'd probably be easiest to merge this through the I2C tree.
It might also be useful to put this patch (and the others I'll send) in
a separate tree so it can be merged into any SoC trees that wish to use
this new feature.
drivers/of/of_i2c.c | 14 ++++++++++++++
include/linux/of_i2c.h | 4 ++++
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c
index 0684887..1e173f3 100644
--- a/drivers/of/of_i2c.c
+++ b/drivers/of/of_i2c.c
@@ -94,4 +94,18 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
}
EXPORT_SYMBOL(of_find_i2c_device_by_node);
+/* must call put_device() when done with returned i2c_adapter device */
+struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
+{
+ struct device *dev;
+
+ dev = bus_find_device(&i2c_bus_type, NULL, node,
+ of_dev_node_match);
+ if (!dev)
+ return NULL;
+
+ return i2c_verify_adapter(dev);
+}
+EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
+
MODULE_LICENSE("GPL");
diff --git a/include/linux/of_i2c.h b/include/linux/of_i2c.h
index 0efe8d4..1cb775f 100644
--- a/include/linux/of_i2c.h
+++ b/include/linux/of_i2c.h
@@ -20,6 +20,10 @@ extern void of_i2c_register_devices(struct i2c_adapter *adap);
/* must call put_device() when done with returned i2c_client device */
extern struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
+/* must call put_device() when done with returned i2c_adapter device */
+extern struct i2c_adapter *of_find_i2c_adapter_by_node(
+ struct device_node *node);
+
#else
static inline void of_i2c_register_devices(struct i2c_adapter *adap)
{
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] i2c: implement i2c_verify_adapter
[not found] ` <1334688214-8400-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-17 18:43 ` [PATCH 2/2] of/i2c: implement of_find_i2c_adapter_by_node Stephen Warren
@ 2012-04-17 18:49 ` Jean Delvare
[not found] ` <20120417204925.29de7775-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
1 sibling, 1 reply; 6+ messages in thread
From: Jean Delvare @ 2012-04-17 18:49 UTC (permalink / raw)
To: Stephen Warren
Cc: Grant Likely, Rob Herring, Ben Dooks, Wolfram Sang,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
linux-i2c-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
Hi Stephen,
On Tue, 17 Apr 2012 12:43:33 -0600, Stephen Warren wrote:
> From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>
> This converts a struct device * to a struct i2c_adapter * while verifying
> that the device really is an I2C adapter. Just like i2c_verify_client.
>
> Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> ---
> drivers/i2c/i2c-core.c | 17 +++++++++++++++++
> include/linux/i2c.h | 1 +
> 2 files changed, 18 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index feb7dc3..a6ad32b 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -772,6 +772,23 @@ struct device_type i2c_adapter_type = {
> };
> EXPORT_SYMBOL_GPL(i2c_adapter_type);
>
> +/**
> + * i2c_verify_adapter - return parameter as i2c_adapter or NULL
> + * @dev: device, probably from some driver model iterator
> + *
> + * When traversing the driver model tree, perhaps using driver model
> + * iterators like @device_for_each_child(), you can't assume very much
> + * about the nodes you find. Use this function to avoid oopses caused
> + * by wrongly treating some non-I2C device as an i2c_adapter.
> + */
> +struct i2c_adapter *i2c_verify_adapter(struct device *dev)
> +{
> + return (dev->type == &i2c_adapter_type)
> + ? to_i2c_adapter(dev)
> + : NULL;
> +}
> +EXPORT_SYMBOL(i2c_verify_adapter);
> +
> #ifdef CONFIG_I2C_COMPAT
> static struct class_compat *i2c_adapter_compat_class;
> #endif
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index 195d8b3..b66cb60 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -232,6 +232,7 @@ struct i2c_client {
> #define to_i2c_client(d) container_of(d, struct i2c_client, dev)
>
> extern struct i2c_client *i2c_verify_client(struct device *dev);
> +extern struct i2c_adapter *i2c_verify_adapter(struct device *dev);
>
> static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
> {
I am fine with this patch:
Acked-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
I can merge it if you want, but if it is easier for you to merge it
through a different tree, this is equally fine with me, just let me
know what you prefer.
--
Jean Delvare
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] i2c: implement i2c_verify_adapter
[not found] ` <20120417204925.29de7775-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
@ 2012-04-24 16:55 ` Stephen Warren
[not found] ` <4F96DAF3.9000700-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Stephen Warren @ 2012-04-24 16:55 UTC (permalink / raw)
To: Wolfram Sang
Cc: Jean Delvare, Grant Likely, Rob Herring, Ben Dooks,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
linux-i2c-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
On 04/17/2012 12:49 PM, Jean Delvare wrote:
> Hi Stephen,
>
> On Tue, 17 Apr 2012 12:43:33 -0600, Stephen Warren wrote:
>> From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>>
>> This converts a struct device * to a struct i2c_adapter * while verifying
>> that the device really is an I2C adapter. Just like i2c_verify_client.
...
> I am fine with this patch:
>
> Acked-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
>
> I can merge it if you want, but if it is easier for you to merge it
> through a different tree, this is equally fine with me, just let me
> know what you prefer.
Wolfram, since the other I2C mux changes are going through your tree,
could you please merge this series too; they are a dependency for my
pinctrl-based I2C mux. Thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] i2c: implement i2c_verify_adapter
[not found] ` <4F96DAF3.9000700-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
@ 2012-04-24 17:09 ` Wolfram Sang
0 siblings, 0 replies; 6+ messages in thread
From: Wolfram Sang @ 2012-04-24 17:09 UTC (permalink / raw)
To: Stephen Warren
Cc: Jean Delvare, Grant Likely, Rob Herring, Ben Dooks,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
linux-i2c-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
[-- Attachment #1: Type: text/plain, Size: 358 bytes --]
> Wolfram, since the other I2C mux changes are going through your tree,
> could you please merge this series too; they are a dependency for my
> pinctrl-based I2C mux. Thanks!
Applied to next.
--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] of/i2c: implement of_find_i2c_adapter_by_node
[not found] ` <1334688214-8400-2-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
@ 2012-04-24 17:09 ` Wolfram Sang
0 siblings, 0 replies; 6+ messages in thread
From: Wolfram Sang @ 2012-04-24 17:09 UTC (permalink / raw)
To: Stephen Warren
Cc: Grant Likely, Rob Herring, Ben Dooks,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
linux-i2c-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
[-- Attachment #1: Type: text/plain, Size: 598 bytes --]
On Tue, Apr 17, 2012 at 12:43:34PM -0600, Stephen Warren wrote:
> From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>
> This finds the struct i2c_adapter * for a given device tree node. Just
> like of_find_i2c_device_by_node.
>
> Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Applied to my i2c-next. As it is outside of drivers/i2c/ an ack by Grant
or Rob would be nice.
--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-04-24 17:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-17 18:43 [PATCH 1/2] i2c: implement i2c_verify_adapter Stephen Warren
[not found] ` <1334688214-8400-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-17 18:43 ` [PATCH 2/2] of/i2c: implement of_find_i2c_adapter_by_node Stephen Warren
[not found] ` <1334688214-8400-2-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-24 17:09 ` Wolfram Sang
2012-04-17 18:49 ` [PATCH 1/2] i2c: implement i2c_verify_adapter Jean Delvare
[not found] ` <20120417204925.29de7775-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-04-24 16:55 ` Stephen Warren
[not found] ` <4F96DAF3.9000700-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-04-24 17:09 ` Wolfram Sang
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).