]> git.openfabrics.org - ~shefty/rdma-dev.git/commitdiff
i2c: Let i2c_parent_is_i2c_adapter return the parent adapter
authorJean Delvare <khali@linux-fr.org>
Sun, 24 Oct 2010 16:16:57 +0000 (18:16 +0200)
committerJean Delvare <khali@endymion.delvare>
Sun, 24 Oct 2010 16:16:57 +0000 (18:16 +0200)
This makes the calling site's code clearer IMHO.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Michael Lawnick <ml.lawnick@gmx.de>
drivers/i2c/i2c-core.c
drivers/i2c/i2c-dev.c
include/linux/i2c.h

index bea4c5021d26cb5b4c92e9b58cabeda2b882023c..40e563de05089257d78399c1714207d7ab70eb26 100644 (file)
@@ -425,14 +425,14 @@ static int __i2c_check_addr_busy(struct device *dev, void *addrp)
 /* walk up mux tree */
 static int i2c_check_mux_parents(struct i2c_adapter *adapter, int addr)
 {
+       struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
        int result;
 
        result = device_for_each_child(&adapter->dev, &addr,
                                        __i2c_check_addr_busy);
 
-       if (!result && i2c_parent_is_i2c_adapter(adapter))
-               result = i2c_check_mux_parents(
-                                   to_i2c_adapter(adapter->dev.parent), addr);
+       if (!result && parent)
+               result = i2c_check_mux_parents(parent, addr);
 
        return result;
 }
@@ -453,11 +453,11 @@ static int i2c_check_mux_children(struct device *dev, void *addrp)
 
 static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr)
 {
+       struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
        int result = 0;
 
-       if (i2c_parent_is_i2c_adapter(adapter))
-               result = i2c_check_mux_parents(
-                                   to_i2c_adapter(adapter->dev.parent), addr);
+       if (parent)
+               result = i2c_check_mux_parents(parent, addr);
 
        if (!result)
                result = device_for_each_child(&adapter->dev, &addr,
@@ -472,8 +472,10 @@ static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr)
  */
 void i2c_lock_adapter(struct i2c_adapter *adapter)
 {
-       if (i2c_parent_is_i2c_adapter(adapter))
-               i2c_lock_adapter(to_i2c_adapter(adapter->dev.parent));
+       struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
+
+       if (parent)
+               i2c_lock_adapter(parent);
        else
                rt_mutex_lock(&adapter->bus_lock);
 }
@@ -485,8 +487,10 @@ EXPORT_SYMBOL_GPL(i2c_lock_adapter);
  */
 static int i2c_trylock_adapter(struct i2c_adapter *adapter)
 {
-       if (i2c_parent_is_i2c_adapter(adapter))
-               return i2c_trylock_adapter(to_i2c_adapter(adapter->dev.parent));
+       struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
+
+       if (parent)
+               return i2c_trylock_adapter(parent);
        else
                return rt_mutex_trylock(&adapter->bus_lock);
 }
@@ -497,8 +501,10 @@ static int i2c_trylock_adapter(struct i2c_adapter *adapter)
  */
 void i2c_unlock_adapter(struct i2c_adapter *adapter)
 {
-       if (i2c_parent_is_i2c_adapter(adapter))
-               i2c_unlock_adapter(to_i2c_adapter(adapter->dev.parent));
+       struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
+
+       if (parent)
+               i2c_unlock_adapter(parent);
        else
                rt_mutex_unlock(&adapter->bus_lock);
 }
index 5f3a52d517c370d2d1bb4d8f031ffce4e7f22dbc..cec0f3ba97f8b1a74d7134d3a86a61e4a79474df 100644 (file)
@@ -192,13 +192,12 @@ static int i2cdev_check(struct device *dev, void *addrp)
 /* walk up mux tree */
 static int i2cdev_check_mux_parents(struct i2c_adapter *adapter, int addr)
 {
+       struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
        int result;
 
        result = device_for_each_child(&adapter->dev, &addr, i2cdev_check);
-
-       if (!result && i2c_parent_is_i2c_adapter(adapter))
-               result = i2cdev_check_mux_parents(
-                                   to_i2c_adapter(adapter->dev.parent), addr);
+       if (!result && parent)
+               result = i2cdev_check_mux_parents(parent, addr);
 
        return result;
 }
@@ -222,11 +221,11 @@ static int i2cdev_check_mux_children(struct device *dev, void *addrp)
    driver bound to it, as NOT busy. */
 static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr)
 {
+       struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
        int result = 0;
 
-       if (i2c_parent_is_i2c_adapter(adapter))
-               result = i2cdev_check_mux_parents(
-                                   to_i2c_adapter(adapter->dev.parent), addr);
+       if (parent)
+               result = i2cdev_check_mux_parents(parent, addr);
 
        if (!result)
                result = device_for_each_child(&adapter->dev, &addr,
index 9391a491501a6792b7e6373ef52c1901833dbb8b..1f66fa06a97cae66e39d3ad6f6cef8fc221ea955 100644 (file)
@@ -384,10 +384,15 @@ static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data)
        dev_set_drvdata(&dev->dev, data);
 }
 
-static inline int i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter)
+static inline struct i2c_adapter *
+i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter)
 {
-       return adapter->dev.parent != NULL
-               && adapter->dev.parent->type == &i2c_adapter_type;
+       struct device *parent = adapter->dev.parent;
+
+       if (parent != NULL && parent->type == &i2c_adapter_type)
+               return to_i2c_adapter(parent);
+       else
+               return NULL;
 }
 
 /* Adapter locking functions, exported for shared pin cases */