* [PATCH] base: soc: Make soc_device_match() simpler and easier to read
@ 2022-03-01 11:10 Geert Uytterhoeven
2022-03-01 13:16 ` Arnd Bergmann
0 siblings, 1 reply; 2+ messages in thread
From: Geert Uytterhoeven @ 2022-03-01 11:10 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J . Wysocki, Arnd Bergmann, Lee Jones
Cc: linux-kernel, linux-renesas-soc, Geert Uytterhoeven
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.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
drivers/base/soc.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 0af5363a582c36dd..22130b5f789d9d7e 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;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] base: soc: Make soc_device_match() simpler and easier to read
2022-03-01 11:10 [PATCH] base: soc: Make soc_device_match() simpler and easier to read Geert Uytterhoeven
@ 2022-03-01 13:16 ` Arnd Bergmann
0 siblings, 0 replies; 2+ messages in thread
From: Arnd Bergmann @ 2022-03-01 13:16 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Greg Kroah-Hartman, Rafael J . Wysocki, Arnd Bergmann, Lee Jones,
Linux Kernel Mailing List, Linux-Renesas
On Tue, Mar 1, 2022 at 12:10 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
>
> 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.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-03-01 13:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01 11:10 [PATCH] base: soc: Make soc_device_match() simpler and easier to read Geert Uytterhoeven
2022-03-01 13:16 ` Arnd Bergmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).