OSDN Git Service

i2c: add helper to check if a client has a driver attached
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Wed, 6 Nov 2019 21:21:01 +0000 (22:21 +0100)
committerWolfram Sang <wsa@the-dreams.de>
Wed, 11 Dec 2019 07:39:07 +0000 (08:39 +0100)
As a preparation for an API conversion, factor out something frequently
used in the media subsystem. As an improvement, it bails out on both,
NULL and ERRPTR to handle the old and new API.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
include/linux/i2c.h

index 9195432..582ef05 100644 (file)
@@ -851,6 +851,11 @@ extern void i2c_del_driver(struct i2c_driver *driver);
 #define i2c_add_driver(driver) \
        i2c_register_driver(THIS_MODULE, driver)
 
+static inline bool i2c_client_has_driver(struct i2c_client *client)
+{
+       return !IS_ERR_OR_NULL(client) && client->dev.driver;
+}
+
 /* call the i2c_client->command() of all attached clients with
  * the given arguments */
 extern void i2c_clients_command(struct i2c_adapter *adap,