QEMU-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	qemu-devel@nongnu.org, "Thomas Huth" <thuth@redhat.com>,
	qemu-s390x@nongnu.org, qemu-ppc@nongnu.org,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Corey Minyard" <minyard@acm.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>
Subject: Re: [PATCH 4/4] hw/nmi: Remove @cpu_index argument from nmi_trigger()
Date: Wed, 19 Aug 2026 15:02:45 +0200	[thread overview]
Message-ID: <87tsoq5klm.fsf@pond.sub.org> (raw)
In-Reply-To: <d0ad382b-9fe1-4ba2-a7f5-0bbb05daabe5@oss.qualcomm.com> ("Philippe Mathieu-Daudé"'s message of "Tue, 11 Aug 2026 12:17:19 +0200")

Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> writes:

> On 20/3/24 14:34, Peter Maydell wrote:
>> On Tue, 20 Feb 2024 at 15:09, Philippe Mathieu-Daud=C3=A9 <philmd@linaro.=
> org> wrote:
>>>
>>> nmi_monitor_handle() is not related to the monitor,
>>> rename it as nmi_trigger(). Return boolean value
>>> indicating success / failure. The 'cpu_index' argument
>>> is not used, remove it.
>>>
>>> Signed-off-by: Philippe Mathieu-Daud=C3=A9 <philmd@linaro.org>

[...]

>>> diff --git a/include/hw/nmi.h b/include/hw/nmi.h
>>> index c70db941c9..32b27067f2 100644
>>> --- a/include/hw/nmi.h
>>> +++ b/include/hw/nmi.h
>>> @@ -49,6 +49,17 @@ struct NMIClass {
>>>       bool (*nmi_handler)(NMIState *n, Error **errp);
>>>   };
>>>
>>> -void nmi_monitor_handle(int cpu_index, Error **errp);
>>> +/**
>>> + * nmi_trigger: Trigger a NMI.
>>> + *
>>> + * @errp: pointer to error object
>>> + *
>>> + * Iterate over all objects implementing the TYPE_NMI interface
>>> + * and deliver NMI to them.

[...]

>>> + *
>>> + * On success, return %true.
>>> + * On failure, store an error through @errp and return %false.
>>> + */
>>> +bool nmi_trigger(Error **errp);
>>
>> Why return a bool here? None of the callsites looks at the
>> return value.
>
> Indeed, but again this is the style *recommended* by the Error API
> since commit e3fe3988d7 ("error: Document Error API usage rules").

Correct:

 * - Whenever practical, also return a value that indicates success /
 *   failure.  This can make the error checking more concise, and can
 *   avoid useless error object creation and destruction.  Note that
 *   we still have many functions returning void.  We recommend
 *   • bool-valued functions return true on success / false on failure,
 *   • pointer-valued functions return non-null / null pointer, and
 *   • integer-valued functions return non-negative / negative.
>
> Callers providing a non-NULL errp should check the return value,
> but the QMP handlers generated by gen_command_decl() like
> qmp_inject_nmi() here don't return anything.

qmp_inject_nmi() passes the error to its caller.  That's fine.

ipmi_do_hw_op() and watchdog_perform_action() ignore the error.  Also
fine.

> Markus, what would be your preference?

I prefer sticking to the rule whenever practical.

Example for a defensible exception: a callback that's implemented many
more times than it's called.  There the effort of returning something
can exceed the benefit of making the calls more concise.

In a case like nmi_trigger(), what could possibly be gained by deviating
from the rule is dwarved many times over by having to consider the
tradeoffs and justifying them in review.  And if a caller shows up that
could use a return value, we'll waste some more time.  Not worth it.



  reply	other threads:[~2026-08-19 13:03 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20 15:08 [PATCH 0/4] hw/nmi: Remove @cpu_index argument Philippe Mathieu-Daudé
2024-02-20 15:08 ` [PATCH 1/4] hw/nmi: Use object_child_foreach_recursive() in nmi_children() Philippe Mathieu-Daudé
2024-03-20 13:09   ` Peter Maydell
2024-02-20 15:08 ` [PATCH 2/4] hw/s390x/virtio-ccw: Always deliver NMI to first CPU Philippe Mathieu-Daudé
2024-03-20 13:16   ` Peter Maydell
2024-03-20 14:12   ` David Hildenbrand
2024-02-20 15:08 ` [PATCH 3/4] hw/nmi: Remove @cpu_index argument from NMIClass::nmi_handler() Philippe Mathieu-Daudé
2024-03-20 13:23   ` Peter Maydell
2024-03-20 16:47     ` Philippe Mathieu-Daudé
2024-03-20 19:05       ` Markus Armbruster
2024-03-20 19:39         ` Peter Maydell
2024-02-20 15:08 ` [PATCH 4/4] hw/nmi: Remove @cpu_index argument from nmi_trigger() Philippe Mathieu-Daudé
2024-03-20 13:34   ` Peter Maydell
2026-08-11 10:17     ` Philippe Mathieu-Daudé
2026-08-19 13:02       ` Markus Armbruster [this message]
2024-02-20 15:19 ` [PATCH 0/4] hw/nmi: Remove @cpu_index argument Thomas Huth
2024-02-20 20:05   ` Philippe Mathieu-Daudé
2024-03-20 11:19   ` Philippe Mathieu-Daudé
2024-03-20 11:44     ` Mark Burton
2024-03-20 12:00     ` Peter Maydell
2024-03-20 12:31       ` Mark Burton
2024-03-20 13:55         ` Peter Maydell
2024-03-20 14:09           ` Mark Burton
2024-03-20 15:00             ` Peter Maydell
2024-03-20 15:40               ` Mark Burton
2024-03-22 14:08               ` Cédric Le Goater
2024-03-22 14:55                 ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tsoq5klm.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=minyard@acm.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox