From patchwork Fri Feb 23 09:35:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13568785 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B7326C5478C for ; Fri, 23 Feb 2024 09:36:01 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.684706.1064742 (Exim 4.92) (envelope-from ) id 1rdRyB-0006CA-2f; Fri, 23 Feb 2024 09:35:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 684706.1064742; Fri, 23 Feb 2024 09:35:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rdRyA-0006C3-VV; Fri, 23 Feb 2024 09:35:50 +0000 Received: by outflank-mailman (input) for mailman id 684706; Fri, 23 Feb 2024 09:35:49 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rdRy9-0006BX-1V for xen-devel@lists.xenproject.org; Fri, 23 Feb 2024 09:35:49 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ecdb525a-d22e-11ee-8a57-1f161083a0e0; Fri, 23 Feb 2024 10:35:48 +0100 (CET) Received: from nico.bugseng.com (unknown [46.228.253.196]) by support.bugseng.com (Postfix) with ESMTPSA id B667E4EE0741; Fri, 23 Feb 2024 10:35:46 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ecdb525a-d22e-11ee-8a57-1f161083a0e0 From: Nicola Vetrini To: nicola.vetrini@bugseng.com, xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, consulting@bugseng.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Wei Liu Subject: [XEN PATCH 1/2] xen/console: drop return value from consoled_guest_rx/tx Date: Fri, 23 Feb 2024 10:35:36 +0100 Message-Id: <4998ec735bd7e5a50a229507e2b92ae56ec1ba4b.1708680104.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 These functions never saw a usage of their return value since they were introduced, so it can be dropped since their usages violate MISRA C Rule 17.7: "The value returned by a function having non-void return type shall be used". No functional change. Signed-off-by: Nicola Vetrini Reviewed-by: Stefano Stabellini --- xen/drivers/char/consoled.c | 17 +++++------------ xen/include/xen/consoled.h | 4 ++-- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/xen/drivers/char/consoled.c b/xen/drivers/char/consoled.c index 222e01844271..b415b632cecc 100644 --- a/xen/drivers/char/consoled.c +++ b/xen/drivers/char/consoled.c @@ -43,13 +43,13 @@ struct xencons_interface *consoled_get_ring_addr(void) static char buf[BUF_SZ + 1]; /* Receives characters from a domain's PV console */ -size_t consoled_guest_rx(void) +void consoled_guest_rx(void) { - size_t recv = 0, idx = 0; + size_t idx = 0; XENCONS_RING_IDX cons, prod; if ( !cons_ring ) - return 0; + return; spin_lock(&rx_lock); @@ -73,7 +73,6 @@ size_t consoled_guest_rx(void) char c = cons_ring->out[MASK_XENCONS_IDX(cons++, cons_ring->out)]; buf[idx++] = c; - recv++; if ( idx >= BUF_SZ ) { @@ -92,18 +91,15 @@ size_t consoled_guest_rx(void) out: spin_unlock(&rx_lock); - - return recv; } /* Sends a character into a domain's PV console */ -size_t consoled_guest_tx(char c) +void consoled_guest_tx(char c) { - size_t sent = 0; XENCONS_RING_IDX cons, prod; if ( !cons_ring ) - return 0; + return; cons = ACCESS_ONCE(cons_ring->in_cons); prod = cons_ring->in_prod; @@ -121,7 +117,6 @@ size_t consoled_guest_tx(char c) goto notify; cons_ring->in[MASK_XENCONS_IDX(prod++, cons_ring->in)] = c; - sent++; /* Write to the ring before updating the pointer */ smp_wmb(); @@ -130,8 +125,6 @@ size_t consoled_guest_tx(char c) notify: /* Always notify the guest: prevents receive path from getting stuck. */ pv_shim_inject_evtchn(pv_console_evtchn()); - - return sent; } /* diff --git a/xen/include/xen/consoled.h b/xen/include/xen/consoled.h index 2b30516b3a0a..bd7ab6329ee8 100644 --- a/xen/include/xen/consoled.h +++ b/xen/include/xen/consoled.h @@ -5,8 +5,8 @@ void consoled_set_ring_addr(struct xencons_interface *ring); struct xencons_interface *consoled_get_ring_addr(void); -size_t consoled_guest_rx(void); -size_t consoled_guest_tx(char c); +void consoled_guest_rx(void); +void consoled_guest_tx(char c); #endif /* __XEN_CONSOLED_H__ */ /* From patchwork Fri Feb 23 09:35:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13568787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98541C54E49 for ; Fri, 23 Feb 2024 09:36:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.684707.1064752 (Exim 4.92) (envelope-from ) id 1rdRyD-0006RU-8h; Fri, 23 Feb 2024 09:35:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 684707.1064752; Fri, 23 Feb 2024 09:35:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rdRyD-0006RL-5w; Fri, 23 Feb 2024 09:35:53 +0000 Received: by outflank-mailman (input) for mailman id 684707; Fri, 23 Feb 2024 09:35:52 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rdRyC-0006BX-2n for xen-devel@lists.xenproject.org; Fri, 23 Feb 2024 09:35:52 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id eeee753b-d22e-11ee-8a57-1f161083a0e0; Fri, 23 Feb 2024 10:35:51 +0100 (CET) Received: from nico.bugseng.com (unknown [46.228.253.196]) by support.bugseng.com (Postfix) with ESMTPSA id 4FDB34EE0C8A; Fri, 23 Feb 2024 10:35:50 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: eeee753b-d22e-11ee-8a57-1f161083a0e0 From: Nicola Vetrini To: nicola.vetrini@bugseng.com, xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, consulting@bugseng.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Wei Liu Subject: [XEN PATCH 2/2] xen/cpu: address MISRA C Rule 17.7 Date: Fri, 23 Feb 2024 10:35:37 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Refactor cpu_notifier_call_chain into two functions: - the variant that is allowed to fail loses the nofail flag - the variant that shouldn't fail is encapsulated in a call to the failing variant, with an additional check. This prevents uses of the function that are not supposed to fail from ignoring the return value, thus violating Rule 17.7: "The value returned by a function having non-void return type shall be used". No functional change. Signed-off-by: Nicola Vetrini Reviewed-by: Stefano Stabellini --- xen/common/cpu.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/xen/common/cpu.c b/xen/common/cpu.c index 8709db4d2957..0b7cf54c4264 100644 --- a/xen/common/cpu.c +++ b/xen/common/cpu.c @@ -78,20 +78,27 @@ void __init register_cpu_notifier(struct notifier_block *nb) } static int cpu_notifier_call_chain(unsigned int cpu, unsigned long action, - struct notifier_block **nb, bool nofail) + struct notifier_block **nb) { void *hcpu = (void *)(long)cpu; int notifier_rc = notifier_call_chain(&cpu_chain, action, hcpu, nb); int ret = notifier_to_errno(notifier_rc); - BUG_ON(ret && nofail); - return ret; } +static void cpu_notifier_call_chain_nofail(unsigned int cpu, + unsigned long action, + struct notifier_block **nb) +{ + int ret = cpu_notifier_call_chain(cpu, action, nb); + + BUG_ON(ret); +} + static void cf_check _take_cpu_down(void *unused) { - cpu_notifier_call_chain(smp_processor_id(), CPU_DYING, NULL, true); + cpu_notifier_call_chain_nofail(smp_processor_id(), CPU_DYING, NULL); __cpu_disable(); } @@ -116,7 +123,7 @@ int cpu_down(unsigned int cpu) if ( !cpu_online(cpu) ) goto out; - err = cpu_notifier_call_chain(cpu, CPU_DOWN_PREPARE, &nb, false); + err = cpu_notifier_call_chain(cpu, CPU_DOWN_PREPARE, &nb); if ( err ) goto fail; @@ -129,14 +136,14 @@ int cpu_down(unsigned int cpu) err = cpu_online(cpu); BUG_ON(err); - cpu_notifier_call_chain(cpu, CPU_DEAD, NULL, true); + cpu_notifier_call_chain_nofail(cpu, CPU_DEAD, NULL); send_global_virq(VIRQ_PCPU_STATE); cpu_hotplug_done(); return 0; fail: - cpu_notifier_call_chain(cpu, CPU_DOWN_FAILED, &nb, true); + cpu_notifier_call_chain_nofail(cpu, CPU_DOWN_FAILED, &nb); out: cpu_hotplug_done(); return err; @@ -157,7 +164,7 @@ int cpu_up(unsigned int cpu) if ( cpu_online(cpu) ) goto out; - err = cpu_notifier_call_chain(cpu, CPU_UP_PREPARE, &nb, false); + err = cpu_notifier_call_chain(cpu, CPU_UP_PREPARE, &nb); if ( err ) goto fail; @@ -165,7 +172,7 @@ int cpu_up(unsigned int cpu) if ( err < 0 ) goto fail; - cpu_notifier_call_chain(cpu, CPU_ONLINE, NULL, true); + cpu_notifier_call_chain_nofail(cpu, CPU_ONLINE, NULL); send_global_virq(VIRQ_PCPU_STATE); @@ -173,7 +180,7 @@ int cpu_up(unsigned int cpu) return 0; fail: - cpu_notifier_call_chain(cpu, CPU_UP_CANCELED, &nb, true); + cpu_notifier_call_chain_nofail(cpu, CPU_UP_CANCELED, &nb); out: cpu_hotplug_done(); return err; @@ -181,7 +188,7 @@ int cpu_up(unsigned int cpu) void notify_cpu_starting(unsigned int cpu) { - cpu_notifier_call_chain(cpu, CPU_STARTING, NULL, true); + cpu_notifier_call_chain_nofail(cpu, CPU_STARTING, NULL); } static cpumask_t frozen_cpus; @@ -237,7 +244,7 @@ void enable_nonboot_cpus(void) } for_each_cpu ( cpu, &frozen_cpus ) - cpu_notifier_call_chain(cpu, CPU_RESUME_FAILED, NULL, true); + cpu_notifier_call_chain_nofail(cpu, CPU_RESUME_FAILED, NULL); cpumask_clear(&frozen_cpus); }