aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-core.c
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2012-04-17 14:43:33 -0400
committerWolfram Sang <w.sang@pengutronix.de>2012-05-12 08:28:16 -0400
commit643dd09eb27b40ced671564edbe2640935fe37c2 (patch)
tree2237d5e572351e2d740c34050f7f20c2ec06745b /drivers/i2c/i2c-core.c
parentec39ef83eb9b22cc732329e85fc4ec03e76d9dda (diff)
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: Stephen Warren <swarren@nvidia.com> Acked-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r--drivers/i2c/i2c-core.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index feb7dc359186..a6ad32bc0a96 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -772,6 +772,23 @@ struct device_type i2c_adapter_type = {
772}; 772};
773EXPORT_SYMBOL_GPL(i2c_adapter_type); 773EXPORT_SYMBOL_GPL(i2c_adapter_type);
774 774
775/**
776 * i2c_verify_adapter - return parameter as i2c_adapter or NULL
777 * @dev: device, probably from some driver model iterator
778 *
779 * When traversing the driver model tree, perhaps using driver model
780 * iterators like @device_for_each_child(), you can't assume very much
781 * about the nodes you find. Use this function to avoid oopses caused
782 * by wrongly treating some non-I2C device as an i2c_adapter.
783 */
784struct i2c_adapter *i2c_verify_adapter(struct device *dev)
785{
786 return (dev->type == &i2c_adapter_type)
787 ? to_i2c_adapter(dev)
788 : NULL;
789}
790EXPORT_SYMBOL(i2c_verify_adapter);
791
775#ifdef CONFIG_I2C_COMPAT 792#ifdef CONFIG_I2C_COMPAT
776static struct class_compat *i2c_adapter_compat_class; 793static struct class_compat *i2c_adapter_compat_class;
777#endif 794#endif