Commit 643dd09e authored by Stephen Warren's avatar Stephen Warren Committed by Wolfram Sang

i2c: implement i2c_verify_adapter

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: default avatarStephen Warren <swarren@nvidia.com>
Acked-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarWolfram Sang <w.sang@pengutronix.de>
parent ec39ef83
...@@ -772,6 +772,23 @@ struct device_type i2c_adapter_type = { ...@@ -772,6 +772,23 @@ struct device_type i2c_adapter_type = {
}; };
EXPORT_SYMBOL_GPL(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 #ifdef CONFIG_I2C_COMPAT
static struct class_compat *i2c_adapter_compat_class; static struct class_compat *i2c_adapter_compat_class;
#endif #endif
......
...@@ -232,6 +232,7 @@ struct i2c_client { ...@@ -232,6 +232,7 @@ struct i2c_client {
#define to_i2c_client(d) container_of(d, struct i2c_client, dev) #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_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) static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment