Skip to contentSkip to conversation

xen/notifier: simplify using notifier_[to|from]_errno()

PATCH In review Juergen Gross 4 participants 4 messages Oct 28, 2022 – Nov 15, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/notifier: simplify using notifier_[to|from]_errno()

Today all users of notifier_from_errno() and notifier_to_errno() are Handling the success case the same way, by using

!rc ? NOTIFY_DONE : notifier_from_errno(rc)

or

  (notifier_rc == NOTIFY_DONE) ? 0 : notifier_to_errno(notifier_rc);

Simplify the use cases by moving the handling of the success case into the functions.

---
 xen/arch/arm/cpuerrata.c            | 2 +-
 xen/arch/arm/gic-v3-lpi.c           | 2 +-
 xen/arch/arm/irq.c                  | 2 +-
 xen/arch/arm/percpu.c               | 2 +-
 xen/arch/arm/smpboot.c              | 2 +-
 xen/arch/x86/acpi/cpu_idle.c        | 2 +-
 xen/arch/x86/cpu/mcheck/mce.c       | 2 +-
 xen/arch/x86/cpu/mcheck/mce_intel.c | 2 +-
 xen/arch/x86/cpu/mwait-idle.c       | 2 +-
 xen/arch/x86/genapic/x2apic.c       | 2 +-
 xen/arch/x86/hvm/hvm.c              | 2 +-
 xen/arch/x86/percpu.c               | 2 +-
 xen/arch/x86/psr.c                  | 2 +-
 xen/arch/x86/smpboot.c              | 2 +-
 xen/common/cpu.c                    | 2 +-
 xen/common/sched/core.c             | 2 +-
 xen/common/sched/cpupool.c          | 2 +-
 xen/include/xen/notifier.h          | 4 ++--
 18 files changed, 19 insertions(+), 19 deletions(-)
xen/arch/arm/cpuerrata.c +1 -1
index ae649d16ef..5952111b72 100644
@@ -724,7 +724,7 @@ static int cpu_errata_callback(struct notifier_block *nfb,
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_errata_nfb = {
xen/arch/arm/gic-v3-lpi.c +1 -1
index 61d90eb386..f0b7ef17da 100644
@@ -402,7 +402,7 @@ static int cpu_callback(struct notifier_block *nfb, unsigned long action,
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_nfb = {
xen/arch/arm/irq.c +1 -1
index fd0c15fffd..00fadbc354 100644
@@ -148,7 +148,7 @@ static int cpu_callback(struct notifier_block *nfb, unsigned long action,
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_nfb = {
xen/arch/arm/percpu.c +1 -1
index 25442c48fe..67eb821ff6 100644
@@ -68,7 +68,7 @@ static int cpu_percpu_callback(
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_percpu_nfb = {
xen/arch/arm/smpboot.c +1 -1
index f7bda3a18b..bfa988c162 100644
@@ -562,7 +562,7 @@ static int cpu_smpboot_callback(struct notifier_block *nfb,
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_smpboot_nfb = {
xen/arch/x86/acpi/cpu_idle.c +1 -1
index 557bc6ef86..427c8c89c5 100644
@@ -1663,7 +1663,7 @@ static int cf_check cpu_callback(
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_nfb = {
xen/arch/x86/cpu/mcheck/mce.c +1 -1
index f68e31b643..3e93bdd8da 100644
@@ -757,7 +757,7 @@ static int cf_check cpu_callback(
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_nfb = {
xen/arch/x86/cpu/mcheck/mce_intel.c +1 -1
index 28a605a5cb..301533722d 100644
@@ -951,7 +951,7 @@ static int cf_check cpu_callback(
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_nfb = {
xen/arch/x86/cpu/mwait-idle.c +1 -1
index ffdc6fb2fc..9e981e7e26 100644
@@ -1537,7 +1537,7 @@ static int cf_check mwait_idle_cpu_init(
 		dev = processor_powers[cpu];
 		if (!rc && cpuidle_current_governor->enable)
 			rc = cpuidle_current_governor->enable(dev);
-		return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+		return notifier_from_errno(rc);
 
 	case CPU_ONLINE:
 		if (!dev)
xen/arch/x86/genapic/x2apic.c +1 -1
index 7dfc793514..f73390cdb0 100644
@@ -221,7 +221,7 @@ static int cf_check update_clusterinfo(
         break;
     }
 
-    return !err ? NOTIFY_DONE : notifier_from_errno(err);
+    return notifier_from_errno(err);
 }
 
 static struct notifier_block x2apic_cpu_nfb = {
xen/arch/x86/hvm/hvm.c +1 -1
index 44b432ec5a..75ce37394d 100644
@@ -142,7 +142,7 @@ static int cf_check cpu_callback(
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_nfb = {
xen/arch/x86/percpu.c +1 -1
index 46460689b7..288050cdba 100644
@@ -86,7 +86,7 @@ static int cf_check cpu_percpu_callback(
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_percpu_nfb = {
xen/arch/x86/psr.c +1 -1
index ccb761998f..a1e0af27c5 100644
@@ -1663,7 +1663,7 @@ static int cf_check cpu_callback(
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_nfb = {
xen/arch/x86/smpboot.c +1 -1
index b46fd9ab18..a238aa1f14 100644
@@ -1144,7 +1144,7 @@ static int cf_check cpu_smpboot_callback(
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_smpboot_nfb = {
xen/common/cpu.c +1 -1
index 778b6820b7..8709db4d29 100644
@@ -82,7 +82,7 @@ static int cpu_notifier_call_chain(unsigned int cpu, unsigned long action,
 {
     void *hcpu = (void *)(long)cpu;
     int notifier_rc = notifier_call_chain(&cpu_chain, action, hcpu, nb);
-    int ret = (notifier_rc == NOTIFY_DONE) ? 0 : notifier_to_errno(notifier_rc);
+    int ret =  notifier_to_errno(notifier_rc);
 
     BUG_ON(ret && nofail);
 
xen/common/sched/core.c +1 -1
index 23fa6845a8..44d60ac561 100644
@@ -2874,7 +2874,7 @@ static int cf_check cpu_schedule_callback(
 
     rcu_read_unlock(&sched_res_rculock);
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_schedule_nfb = {
xen/common/sched/cpupool.c +1 -1
index b2c6f520c3..ccb86ef283 100644
@@ -1072,7 +1072,7 @@ static int cf_check cpu_callback(
         break;
     }
 
-    return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
+    return notifier_from_errno(rc);
 }
 
 static struct notifier_block cpu_nfb = {
xen/include/xen/notifier.h +2 -2
index 0921213298..3d6017d4f7 100644
@@ -58,13 +58,13 @@ int notifier_call_chain(
 /* Encapsulate (negative) errno value. */
 static inline int notifier_from_errno(int err)
 {
-    return NOTIFY_STOP_MASK | -err;
+    return err ? (NOTIFY_STOP_MASK | -err) : NOTIFY_DONE;
 }
 
 /* Restore (negative) errno value from notify return value. */
 static inline int notifier_to_errno(int ret)
 {
-    return -(ret & ~NOTIFY_STOP_MASK);
+    return (ret == NOTIFY_DONE) ? 0 : -(ret & ~NOTIFY_STOP_MASK);
 }
 
 #endif /* __XEN_NOTIFIER_H__ */
Signature · 1 line
2.35.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Juergen Gross

Today all users of notifier_from_errno() and notifier_to_errno() are Handling the success case the same way, by using

  !rc ? NOTIFY_DONE : notifier_from_errno(rc)

or

  (notifier_rc == NOTIFY_DONE) ? 0 : notifier_to_errno(notifier_rc);

Simplify the use cases by moving the handling of the success case into
the functions.

Quoted 6 lines

---
...
 xen/common/sched/core.c             | 2 +-
 xen/common/sched/cpupool.c          | 2 +-

Regards

Signature · 6 lines
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)
Acked-by on v1 1/1
#2 lore raw
In reply to Juergen Gross
Quoted 5 lines · Juergen Gross

Today all users of notifier_from_errno() and notifier_to_errno() are Handling the success case the same way, by using

!rc ? NOTIFY_DONE : notifier_from_errno(rc)

Quoted 8 lines

or

  (notifier_rc == NOTIFY_DONE) ? 0 : notifier_to_errno(notifier_rc);

Simplify the use cases by moving the handling of the success case into the functions.

Acked-by on v1 1/1
#3 lore raw
In reply to Juergen Gross

Hi Juergen,

Quoted 5 lines · Juergen Gross

Today all users of notifier_from_errno() and notifier_to_errno() are Handling the success case the same way, by using

!rc ? NOTIFY_DONE : notifier_from_errno(rc)

Quoted 8 lines

or

   (notifier_rc == NOTIFY_DONE) ? 0 : notifier_to_errno(notifier_rc);

Simplify the use cases by moving the handling of the success case into the functions.

Cheers,

Signature · 1 line
Julien Grall