i2c: designware: Drop unneeded condition in i2c_dw_validate_speed()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 19 May 2020 12:50:40 +0000 (15:50 +0300)
committerWolfram Sang <wsa@kernel.org>
Fri, 22 May 2020 14:50:30 +0000 (16:50 +0200)
We may bailout directly from the loop instead of breaking it and
testing a loop counter. This also gives advantages such as decreased
indentation level along with dropped unneeded condition.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
drivers/i2c/busses/i2c-designware-common.c

index 9f06567..2fd5372 100644 (file)
@@ -127,16 +127,14 @@ int i2c_dw_validate_speed(struct dw_i2c_dev *dev)
         */
        for (i = 0; i < ARRAY_SIZE(i2c_dw_supported_speeds); i++) {
                if (t->bus_freq_hz == i2c_dw_supported_speeds[i])
-                       break;
-       }
-       if (i == ARRAY_SIZE(i2c_dw_supported_speeds)) {
-               dev_err(dev->dev,
-                       "%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n",
-                       t->bus_freq_hz);
-               return -EINVAL;
+                       return 0;
        }
 
-       return 0;
+       dev_err(dev->dev,
+               "%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n",
+               t->bus_freq_hz);
+
+       return -EINVAL;
 }
 EXPORT_SYMBOL_GPL(i2c_dw_validate_speed);