Calling error_report() from within a function using Error to return
error information is almost always wrong.  Example:

    QMP command qmp_migrate()
    calls rdma_start_outgoing_migration()
    calls qemu_rdma_source_init()
    calls qemu_rdma_reg_control()

The first four have an Error **errp parameter, and use it to return
error information.  Good.

The last one does not.  Instead, qemu_rdma_reg_control() calls
error_report() on failure:

    error_report("qemu_rdma_reg_control failed");
    return -1;

Its caller qemu_rdma_source_init() detects the failure and sets an
error:

        ret = qemu_rdma_reg_control(rdma, idx);
        if (ret) {
            error_setg(temp, "RDMA ERROR: rdma migration: error registering %d 
control!",
                                                            idx);
            goto err_rdma_source_init;
        }

Because of this, QMP command migrate spams stderr on this particular
failure.  Inappropriate.

Easy enough to fix, but I'm after the error pattern, not a single
instance that happened to catch my eye.

Problem: find call chains from functions using Error to error_report().

Two sub-problems:

1. Find functions using Error

   Doesn't have to be perfect.  I have a simple Coccinelle script
   (appended) that spits out some 4400 functions.  I run it like

    $ spatch --sp-file find-error-fns.cocci --macro-file 
scripts/cocci-macro-file.h `git-grep -Fl 'Error **' \*.[ch]`

2. Find call chains from these functions to error_report()

   I'm hoping vrc can do that for me.  How?



Here's my find-error-fns.cocci:

@r@
identifier fn, errp;
position p;
@@
 fn@p(..., Error **errp, ...)
 {
     ...
 }
@script:python@
fn << r.fn;
p << r.p;
@@
print(f'{p[0].file}:{p[0].line}:{p[0].column}:{fn}')


Reply via email to