Skip to content

Commit b0f6807

Browse files
geertugregkh
authored andcommitted
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 <[email protected]> Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/9f9107c06f7d065ae6581e5290ef5d72f7298fd1.1646132835.git.geert+renesas@glider.be Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f2aad54 commit b0f6807

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

drivers/base/soc.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,26 +241,24 @@ static int soc_device_match_one(struct device *dev, void *arg)
241241
const struct soc_device_attribute *soc_device_match(
242242
const struct soc_device_attribute *matches)
243243
{
244-
int ret = 0;
244+
int ret;
245245

246246
if (!matches)
247247
return NULL;
248248

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) {
253251
ret = bus_for_each_dev(&soc_bus_type, NULL, (void *)matches,
254252
soc_device_match_one);
255253
if (ret < 0 && early_soc_dev_attr)
256254
ret = soc_device_match_attr(early_soc_dev_attr,
257255
matches);
258256
if (ret < 0)
259257
return NULL;
260-
if (!ret)
261-
matches++;
262-
else
258+
if (ret)
263259
return matches;
260+
261+
matches++;
264262
}
265263
return NULL;
266264
}

0 commit comments

Comments
 (0)