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

base: soc: Make soc_device_match() simpler and easier to read

The function soc_device_match() is difficult to read for various
reasons:
- There are two loop conditions using different styles: "while (...)"
(which is BTW always true) vs. "if ... break",
- The are two return condition using different logic: "if ... return
foo" vs. "if ... else return bar".

Make the code easier to read by:
1. Removing the always-true "!ret" loop condition, and dropping the
now unneeded pre-initialization of "ret",
2. Converting "if ... break" to a proper "while (...)" loop condition,
3. Inverting the logic of the second return condition.

Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/9f9107c06f7d065ae6581e5290ef5d72f7298fd1.1646132835.git.geert+renesas@glider.be
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Geert Uytterhoeven and committed by
Greg Kroah-Hartman
b0f6807d f2aad547

+6 -8
+6 -8
drivers/base/soc.c
··· 241 241 const struct soc_device_attribute *soc_device_match( 242 242 const struct soc_device_attribute *matches) 243 243 { 244 - int ret = 0; 244 + int ret; 245 245 246 246 if (!matches) 247 247 return NULL; 248 248 249 - while (!ret) { 250 - if (!(matches->machine || matches->family || 251 - matches->revision || matches->soc_id)) 252 - break; 249 + while (matches->machine || matches->family || matches->revision || 250 + matches->soc_id) { 253 251 ret = bus_for_each_dev(&soc_bus_type, NULL, (void *)matches, 254 252 soc_device_match_one); 255 253 if (ret < 0 && early_soc_dev_attr) ··· 255 257 matches); 256 258 if (ret < 0) 257 259 return NULL; 258 - if (!ret) 259 - matches++; 260 - else 260 + if (ret) 261 261 return matches; 262 + 263 + matches++; 262 264 } 263 265 return NULL; 264 266 }