summaryrefslogtreecommitdiff
path: root/drivers/base/soc.c
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2022-03-01 12:10:35 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-03-18 14:28:07 +0100
commitb0f6807d35667faae6de5e23ceffa4546c209bc8 (patch)
treea356ad3a56ed78a6711b50fb673dd1ecce891210 /drivers/base/soc.c
parentf2aad54703dbe630f9d8b235eb58e8c8cc78f37d (diff)
downloadlwn-b0f6807d35667faae6de5e23ceffa4546c209bc8.tar.gz
lwn-b0f6807d35667faae6de5e23ceffa4546c209bc8.zip
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>
Diffstat (limited to 'drivers/base/soc.c')
-rw-r--r--drivers/base/soc.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 0af5363a582c..22130b5f789d 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -241,15 +241,13 @@ static int soc_device_match_one(struct device *dev, void *arg)
const struct soc_device_attribute *soc_device_match(
const struct soc_device_attribute *matches)
{
- int ret = 0;
+ int ret;
if (!matches)
return NULL;
- while (!ret) {
- if (!(matches->machine || matches->family ||
- matches->revision || matches->soc_id))
- break;
+ while (matches->machine || matches->family || matches->revision ||
+ matches->soc_id) {
ret = bus_for_each_dev(&soc_bus_type, NULL, (void *)matches,
soc_device_match_one);
if (ret < 0 && early_soc_dev_attr)
@@ -257,10 +255,10 @@ const struct soc_device_attribute *soc_device_match(
matches);
if (ret < 0)
return NULL;
- if (!ret)
- matches++;
- else
+ if (ret)
return matches;
+
+ matches++;
}
return NULL;
}