Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c: riic: Simplify unsupported bus speed handling

Simplify checking for unsupported bus speeds and reporting errors by
factoring out the calculation of the maximum bus speed, and by using the
dev_err_probe() helper.

While at it, use "%u" for u32, and improve the error message.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Tested-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>

authored by

Geert Uytterhoeven and committed by
Andi Shyti
71dacb25 bc07fb41

+6 -9
+6 -9
drivers/i2c/busses/i2c-riic.c
··· 316 316 struct i2c_timings *t = &riic->i2c_t; 317 317 struct device *dev = riic->adapter.dev.parent; 318 318 bool fast_mode_plus = riic->info->fast_mode_plus; 319 + u32 max_freq = fast_mode_plus ? I2C_MAX_FAST_MODE_PLUS_FREQ 320 + : I2C_MAX_FAST_MODE_FREQ; 319 321 320 - if ((!fast_mode_plus && t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ) || 321 - (fast_mode_plus && t->bus_freq_hz > I2C_MAX_FAST_MODE_PLUS_FREQ)) { 322 - dev_err(&riic->adapter.dev, 323 - "unsupported bus speed (%dHz). %d max\n", 324 - t->bus_freq_hz, 325 - fast_mode_plus ? I2C_MAX_FAST_MODE_PLUS_FREQ : 326 - I2C_MAX_FAST_MODE_FREQ); 327 - return -EINVAL; 328 - } 322 + if (t->bus_freq_hz > max_freq) 323 + return dev_err_probe(&riic->adapter.dev, -EINVAL, 324 + "unsupported bus speed %uHz (%u max)\n", 325 + t->bus_freq_hz, max_freq); 329 326 330 327 rate = clk_get_rate(riic->clk); 331 328