[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 01/31] errp: rename errp to errp_in where it is IN-argumen
From: |
Markus Armbruster |
Subject: |
Re: [PATCH v4 01/31] errp: rename errp to errp_in where it is IN-argument |
Date: |
Wed, 09 Oct 2019 20:48:42 +0200 |
Vladimir Sementsov-Ogievskiy <address@hidden> writes:
> 08.10.2019 15:05, Markus Armbruster wrote:
>> Vladimir Sementsov-Ogievskiy <address@hidden> writes:
>>
>>> 08.10.2019 12:08, Markus Armbruster wrote:
>>>> Vladimir Sementsov-Ogievskiy <address@hidden> writes:
>>>>
>>>>> Error **errp is almost always OUT-argument: it's assumed to be NULL, or
>>>>> pointer to NULL-initialized pointer, or pointer to error_abort or
>>>>> error_fatal, for callee to report error.
>>>>
>>>> Yes.
>>>>
>>>>> But very few functions instead get Error **errp as IN-argument:
>>>>> it's assumed to be set, and callee should clean it.
>>>>
>>>> What do you mean by "callee should clean"? Let's see below.
>>>>
>>>>> In such cases, rename errp to errp_in.
>>>>
>>>> I acknowledge that errp arguments that don't have the usual meaning can
>>>> be confusing.
>>>>
>>>> Naming can help, comments can help, but perhaps we can tweak the code to
>>>> avoid the problem instead. Let's see:
>>>>
>>>>> Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
>>>>> Reviewed-by: Eric Blake <address@hidden>
>> [...]
>>>> We can avoid the confusing Error **errp in all three cases by peeling
>>>> off an indirection. What do you think?
>>>>
>>>
>>> I like the idea, thanks! I think, I'll try to make a patch.
>>>
>>> But you are right, unfortunately there more cases, at least, pointed by
>>> Greg
>>>
>>> error_append_socket_sockfd_hint and
>>> error_append_security_model_hint
>>>
>>> Which don't free error..
>>
>> Neither do error_append_hint() and error_prepend().
>>
>> For anything named error_append_FOO_hint() or error_prepend_FOO(),
>> confusion seems unlikely.
>>
>>> But if they append hint, they should always be
>>> called
>>> on wrapped errp, accordingly to the problem about fatal_error, so they may
>>> be converted to Error *err too.. Hmm, I should think about the script to
>>> find
>>> such functions.
>>
>> I figure I better read more of your series before I comment on this
>> thought.
>>
>
> Me trying to find more such functions:
>
> script:
> # cat ../up-fix-error_append_hint/find.py
> #!/usr/bin/env python
> import re
> import sys
>
> ret_type = r'^[^{};#]+( |\*|\*\*)'
> name = r'(?P<name>\w+)'
> args = r'\([^{};#]*Error \*\*errp[^{};#]*\)'
> body_before_errp = r'((?<!errp)[^}]|(?<!^)})*'
>
> caller = '(if ?|assert|' \
> 'error_(v?prepend|get_pretty|append_hint|free|free_or_abort)|' \
> '(warn|error)_reportf?_err)'
>
> # Match 'caller(errp', 'caller(*errp', 'errp ?'
> access_errp = '(' + caller + r'\(\*?errp|errp \?)'
>
> r = re.compile(ret_type + name + args + '\s*^\{' + body_before_errp +
> access_errp, re.M)
>
> with open(sys.argv[1]) as f:
> text = f.read()
>
> for m in r.finditer(text):
> print(m.groupdict()['name'])
>
>
> search:
> # git ls-files | grep '\.\(h\|c\)$' | while read f; do
> ../up-fix-error_append_hint/find.py $f; done
> vmdk_co_create_opts_cb
Forwards errp to vmdk_create_extent().
Also asserts errp == NULL, which looks suspicious. Not your problem.
> error_append_security_model_hint
> error_append_socket_sockfd_hint
Convenience functions to append a canned hint with error_append_hint().
Their name makes confusion unlikely.
> qemu_file_get_error_obj
Returns an error object in an unusual way: error_copy() instead of
error_setg().
Suspicious-looking qemu_file_set_error_obj() nearby: it either stores
@err in @f, or reports it to stderr / current monitor. Not your
problem.
> hmp_handle_error
Covered by your patch, already discussed.
> qbus_list_bus
> qbus_list_dev
Convenience functions to append hints with error_append_hint().
Function names do not hint at that (pardon the pun).
> kvmppc_hint_smt_possible
Convenience function to append hints with error_append_hint(). Function
name hints weakly.
> vnc_client_io_error
Covered by your patch, already discussed.
> error_handle_fatal
> error_setv
> error_prepend
> error_setg_win32_internal
> error_free_or_abort
Let's not worry about error.c itself.
> vmdk_co_create_opts_cb and qemu_file_get_error_obj are false positives I think
Agree.
[PATCH v4 02/31] hw/core/loader-fit: fix freeing errp in fit_load_fdt, Vladimir Sementsov-Ogievskiy, 2019/10/01
[PATCH v4 08/31] ARM TCG CPUs: Fix error_append_hint/error_prepend usage, Vladimir Sementsov-Ogievskiy, 2019/10/01
[PATCH v4 12/31] ASPEED BMCs: Fix error_append_hint/error_prepend usage, Vladimir Sementsov-Ogievskiy, 2019/10/01
[PATCH v4 15/31] PCI: Fix error_append_hint/error_prepend usage, Vladimir Sementsov-Ogievskiy, 2019/10/01
[PATCH v4 14/31] PowerNV (Non-Virtualized): Fix error_append_hint/error_prepend usage, Vladimir Sementsov-Ogievskiy, 2019/10/01
[PATCH v4 09/31] PowerPC TCG CPUs: Fix error_append_hint/error_prepend usage, Vladimir Sementsov-Ogievskiy, 2019/10/01