Skip to contentSkip to conversation

mm/damon/core: simplify control flow in damon_register_ops()

PATCH Applied Taotao Chen 2 participants 2 messages Mar 20, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/damon/core: simplify control flow in damon_register_ops()

The function logic is not complex, so using goto is unnecessary. Replace it with a straightforward if-else to simplify control flow and improve readability.

---
 mm/damon/core.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
mm/damon/core.c +4 -5
index 384935ef4e65..a3bdc09d38fe 100644
@@ -76,14 +76,13 @@ int damon_register_ops(struct damon_operations *ops)
 
 	if (ops->id >= NR_DAMON_OPS)
 		return -EINVAL;
+
 	mutex_lock(&damon_ops_lock);
 	/* Fail for already registered ops */
-	if (__damon_is_registered_ops(ops->id)) {
+	if (__damon_is_registered_ops(ops->id))
 		err = -EINVAL;
-		goto out;
-	}
-	damon_registered_ops[ops->id] = *ops;
-out:
+	else
+		damon_registered_ops[ops->id] = *ops;
 	mutex_unlock(&damon_ops_lock);
 	return err;
 }
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

+ damon@ and linux-mm@ mailing lists.

Hello Taotao,

Quoted 3 lines · On Thu, 20 Mar 2025 18:44:00 +0800 Taotao Chen <[email protected]>…

The function logic is not complex, so using goto is unnecessary. Replace it with a straightforward if-else to simplify control flow and improve readability.

Good catch and nice cleanup, thank you!

Quoted 2 lines

Thanks,
SJ

[...]