diff mbox series

[1/2] i2c: core: use IS_ENABLED for CONFIG_I2C_COMPAT

Message ID 20190917114918.7157-1-ben.dooks@codethink.co.uk
State New
Headers show
Series [1/2] i2c: core: use IS_ENABLED for CONFIG_I2C_COMPAT | expand

Commit Message

Ben Dooks Sept. 17, 2019, 11:49 a.m. UTC
Reduce the number of #ifdefs used in the i2c-core-base.c by using
IS_ENABLED(CONFIG_I2C_COMPAT) to try and ensure we compile as much
as possible.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
---
 drivers/i2c/i2c-core-base.c | 47 +++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 25 deletions(-)
diff mbox series

Patch

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 9c440fa6a3dd..fb8fd32f2783 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1186,9 +1186,7 @@  struct i2c_adapter *i2c_verify_adapter(struct device *dev)
 }
 EXPORT_SYMBOL(i2c_verify_adapter);
 
-#ifdef CONFIG_I2C_COMPAT
 static struct class_compat *i2c_adapter_compat_class;
-#endif
 
 static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
 {
@@ -1358,13 +1356,14 @@  static int i2c_register_adapter(struct i2c_adapter *adap)
 	pm_suspend_ignore_children(&adap->dev, true);
 	pm_runtime_enable(&adap->dev);
 
-#ifdef CONFIG_I2C_COMPAT
-	res = class_compat_create_link(i2c_adapter_compat_class, &adap->dev,
-				       adap->dev.parent);
-	if (res)
-		dev_warn(&adap->dev,
-			 "Failed to create compatibility class link\n");
-#endif
+	if (IS_ENABLED(CONFIG_I2C_COMPAT)) {
+		res = class_compat_create_link(i2c_adapter_compat_class,
+					       &adap->dev,
+					       adap->dev.parent);
+		if (res)
+			dev_warn(&adap->dev,
+				 "Failed to create compatibility class link\n");
+	}
 
 	i2c_init_recovery(adap);
 
@@ -1573,10 +1572,9 @@  void i2c_del_adapter(struct i2c_adapter *adap)
 	device_for_each_child(&adap->dev, NULL, __unregister_client);
 	device_for_each_child(&adap->dev, NULL, __unregister_dummy);
 
-#ifdef CONFIG_I2C_COMPAT
-	class_compat_remove_link(i2c_adapter_compat_class, &adap->dev,
-				 adap->dev.parent);
-#endif
+	if (IS_ENABLED(CONFIG_I2C_COMPAT))
+		class_compat_remove_link(i2c_adapter_compat_class, &adap->dev,
+					 adap->dev.parent);
 
 	/* device name is gone after device_unregister */
 	dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
@@ -1818,13 +1816,14 @@  static int __init i2c_init(void)
 
 	is_registered = true;
 
-#ifdef CONFIG_I2C_COMPAT
-	i2c_adapter_compat_class = class_compat_register("i2c-adapter");
-	if (!i2c_adapter_compat_class) {
-		retval = -ENOMEM;
-		goto bus_err;
+	if (IS_ENABLED(CONFIG_I2C_COMPAT)) {
+		i2c_adapter_compat_class = class_compat_register("i2c-adapter");
+		if (!i2c_adapter_compat_class) {
+			retval = -ENOMEM;
+			goto bus_err;
+		}
 	}
-#endif
+
 	retval = i2c_add_driver(&dummy_driver);
 	if (retval)
 		goto class_err;
@@ -1837,10 +1836,9 @@  static int __init i2c_init(void)
 	return 0;
 
 class_err:
-#ifdef CONFIG_I2C_COMPAT
-	class_compat_unregister(i2c_adapter_compat_class);
+	if (IS_ENABLED(CONFIG_I2C_COMPAT))
+		class_compat_unregister(i2c_adapter_compat_class);
 bus_err:
-#endif
 	is_registered = false;
 	bus_unregister(&i2c_bus_type);
 	return retval;
@@ -1853,9 +1851,8 @@  static void __exit i2c_exit(void)
 	if (IS_ENABLED(CONFIG_OF_DYNAMIC))
 		WARN_ON(of_reconfig_notifier_unregister(&i2c_of_notifier));
 	i2c_del_driver(&dummy_driver);
-#ifdef CONFIG_I2C_COMPAT
-	class_compat_unregister(i2c_adapter_compat_class);
-#endif
+	if (IS_ENABLED(CONFIG_I2C_COMPAT))
+		class_compat_unregister(i2c_adapter_compat_class);
 	bus_unregister(&i2c_bus_type);
 	tracepoint_synchronize_unregister();
 }