From: Markus Armbruster <armbru@redhat.com>
To: BALATON Zoltan <balaton@eik.bme.hu>
Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org,
David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [PATCH 2/4] smbus: Fix spd_data_generate() error API violation
Date: Tue, 21 Apr 2020 07:28:55 +0200 [thread overview]
Message-ID: <87h7xd5rvs.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <alpine.BSF.2.22.395.2004201613040.29873@zero.eik.bme.hu> (BALATON Zoltan's message of "Mon, 20 Apr 2020 16:20:37 +0200 (CEST)")
BALATON Zoltan <balaton@eik.bme.hu> writes:
> On Mon, 20 Apr 2020, Markus Armbruster wrote:
>> The Error ** argument must be NULL, &error_abort, &error_fatal, or a
>> pointer to a variable containing NULL. Passing an argument of the
>> latter kind twice without clearing it in between is wrong: if the
>> first call sets an error, it no longer points to NULL for the second
>> call.
>>
>> spd_data_generate() can pass @errp to error_setg() more than once when
>> it adjusts both memory size and type. Harmless, because no caller
>> passes anything that needs adjusting. Until the previous commit,
>> sam460ex passed types that needed adjusting, but not sizes.
>>
>> spd_data_generate()'s contract is rather awkward:
>>
>> If everything's fine, return non-null and don't set an error.
>>
>> Else, if memory size or type need adjusting, return non-null and
>> set an error describing the adjustment.
>>
>> Else, return null and set an error reporting why no data can be
>> generated.
>>
>> Its callers treat the error as a warning even when null is returned.
>> They don't create the "smbus-eeprom" device then. Suspicious.
>
> The idea here again is to make it work if there's a way it could work
> rather than throw back an error to user and bail. This is for user
> convenience in the likely case the user knows nothing about the board
> or SPD data restrictions.
We're in perfect agreement that the user of QEMU should not need to know
anything about memory type and number of banks. QEMU should pick a
sensible configuration for any memory size it supports.
> You seem to disagree with this
Here's what I actually disagree with:
1. QEMU warning the user about its choice of memory type, but only
sometimes. Why warn? There is nothing wrong, and there is nothing the
user can do to avoid the condition that triggers the warning.
2. QEMU changing the user's memory size. Yes, I understand that's an
attempt to be helpful, but I prefer my tools not to second-guess my
intent.
> and want to
> remove all such logic from everywhere. Despite the title of this patch
> it's not just fixing error API usage but removing those fix ups.
I'm removing unused code that is also broken. If you want to keep it,
please fix it, and provide a user and/or a unit test. Without that, it
is a trap for future callers.
> If Error cannot be used for this could you change error_setg to
> warn_report and keep the fix ups untouched? That fixes the problem
> with error (although leaves no chance to board code to handle
> errors). Maybe fix Error to be usable for what it's intended for
> rather than removing cases it can't handle.
Error is designed for errors, not warnings.
A function either succeeds (no error) or fails (one error).
It can be pressed into service for warnings (you did, although in a
buggy way). You still can return at most one Error per Error **
parameter. If you need multiple warnings, use multiple parameters
(ugh!). You could also try to squash multiple warnings into one the
hints mechanism.
I'd advise against combining warn_report() and Error ** in one function.
A function should either take care of talking to the user completely, or
leave it to its caller completely.
next prev parent reply other threads:[~2020-04-21 5:30 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-20 13:28 [PATCH 0/4] Subject: [PATCH 0/4] smbus: SPD fixes Markus Armbruster
2020-04-20 13:28 ` [PATCH 1/4] sam460ex: Revert change to SPD memory type for <= 128 MiB Markus Armbruster
2020-04-20 14:12 ` BALATON Zoltan
2020-04-21 5:28 ` Markus Armbruster
2020-04-22 13:56 ` BALATON Zoltan
2020-04-29 5:18 ` Markus Armbruster
2020-04-20 13:28 ` [PATCH 2/4] smbus: Fix spd_data_generate() error API violation Markus Armbruster
2020-04-20 14:20 ` BALATON Zoltan
2020-04-21 5:28 ` Markus Armbruster [this message]
2020-04-22 13:43 ` BALATON Zoltan
2020-04-24 9:45 ` Markus Armbruster
2020-04-24 10:18 ` Philippe Mathieu-Daudé
2020-04-24 11:23 ` Markus Armbruster
2020-04-24 13:52 ` BALATON Zoltan
2020-04-29 5:42 ` Markus Armbruster
2020-04-20 13:28 ` [PATCH 3/4] bamboo, sam460ex: Tidy up error message for unsupported RAM size Markus Armbruster
2020-04-20 13:50 ` Philippe Mathieu-Daudé
2020-04-20 13:28 ` [PATCH 4/4] smbus: Fix spd_data_generate() for number of banks > 2 Markus Armbruster
2020-04-20 13:53 ` Philippe Mathieu-Daudé
2020-04-20 14:37 ` BALATON Zoltan
2020-04-21 4:57 ` Markus Armbruster
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=87h7xd5rvs.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=balaton@eik.bme.hu \
--cc=david@gibson.dropbear.id.au \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.