Skip to content
Snippets Groups Projects
  1. Jul 16, 2020
  2. Jul 10, 2020
    • Peter Maydell's avatar
      Merge remote-tracking branch 'remotes/mcayland/tags/qemu-openbios-20200707' into staging · 45db94cc
      Peter Maydell authored
      
      qemu-openbios queue
      
      # gpg: Signature made Tue 07 Jul 2020 21:57:37 BST
      # gpg:                using RSA key CC621AB98E82200D915CC9C45BC2C56FAE0F321F
      # gpg:                issuer "mark.cave-ayland@ilande.co.uk"
      # gpg: Good signature from "Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>" [full]
      # Primary key fingerprint: CC62 1AB9 8E82 200D 915C  C9C4 5BC2 C56F AE0F 321F
      
      * remotes/mcayland/tags/qemu-openbios-20200707:
        Update OpenBIOS images to 75fbb41d built from submodule.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      45db94cc
    • Peter Maydell's avatar
      Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2020-07-07-v2' into staging · f2a1cf91
      Peter Maydell authored
      
      Error reporting patches patches for 2020-07-07
      
      # gpg: Signature made Fri 10 Jul 2020 14:24:42 BST
      # gpg:                using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653
      # gpg:                issuer "armbru@redhat.com"
      # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full]
      # gpg:                 aka "Markus Armbruster <armbru@pond.sub.org>" [full]
      # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867  4E5F 3870 B400 EB91 8653
      
      * remotes/armbru/tags/pull-error-2020-07-07-v2: (53 commits)
        xen: Use ERRP_GUARD()
        nbd: Use ERRP_GUARD()
        virtio-9p: Use ERRP_GUARD()
        fw_cfg: Use ERRP_GUARD()
        pflash: Use ERRP_GUARD()
        sd: Use ERRP_GUARD()
        scripts: Coccinelle script to use ERRP_GUARD()
        error: New macro ERRP_GUARD()
        hmp: Ignore Error objects where the return value suffices
        qdev: Ignore Error objects where the return value suffices
        qemu-img: Ignore Error objects where the return value suffices
        error: Avoid error_propagate() after migrate_add_blocker()
        qapi: Purge error_propagate() from QAPI core
        qapi: Smooth visitor error checking in generated code
        qapi: Smooth another visitor error checking pattern
        block/parallels: Simplify parallels_open() after previous commit
        error: Reduce unnecessary error propagation
        error: Eliminate error_propagate() manually
        error: Eliminate error_propagate() with Coccinelle, part 2
        error: Eliminate error_propagate() with Coccinelle, part 1
        ...
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      f2a1cf91
    • Vladimir Sementsov-Ogievskiy's avatar
      xen: Use ERRP_GUARD() · 1de7096d
      Vladimir Sementsov-Ogievskiy authored
      
      If we want to check error after errp-function call, we need to
      introduce local_err and then propagate it to errp. Instead, use
      the ERRP_GUARD() macro, benefits are:
      1. No need of explicit error_propagate call
      2. No need of explicit local_err variable: use errp directly
      3. ERRP_GUARD() leaves errp as is if it's not NULL or
         &error_fatal, this means that we don't break error_abort
         (we'll abort on error_set, not on error_propagate)
      
      If we want to add some info to errp (by error_prepend() or
      error_append_hint()), we must use the ERRP_GUARD() macro.
      Otherwise, this info will not be added when errp == &error_fatal
      (the program will exit prior to the error_append_hint() or
      error_prepend() call).  No such cases are being fixed here.
      
      This commit is generated by command
      
          sed -n '/^X86 Xen CPUs$/,/^$/{s/^F: //p}' MAINTAINERS | \
          xargs git ls-files | grep '\.[hc]$' | \
          xargs spatch \
              --sp-file scripts/coccinelle/errp-guard.cocci \
              --macro-file scripts/cocci-macro-file.h \
              --in-place --no-show-diff --max-width 80
      
      Reported-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reported-by: default avatarGreg Kurz <groug@kaod.org>
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      [Commit message tweaked]
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20200707165037.1026246-9-armbru@redhat.com>
      [ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
      auto-propagated-errp.cocci to errp-guard.cocci.  Commit message
      tweaked again.]
      1de7096d
    • Vladimir Sementsov-Ogievskiy's avatar
      nbd: Use ERRP_GUARD() · 795d946d
      Vladimir Sementsov-Ogievskiy authored
      
      If we want to check error after errp-function call, we need to
      introduce local_err and then propagate it to errp. Instead, use
      the ERRP_GUARD() macro, benefits are:
      1. No need of explicit error_propagate call
      2. No need of explicit local_err variable: use errp directly
      3. ERRP_GUARD() leaves errp as is if it's not NULL or
         &error_fatal, this means that we don't break error_abort
         (we'll abort on error_set, not on error_propagate)
      
      If we want to add some info to errp (by error_prepend() or
      error_append_hint()), we must use the ERRP_GUARD() macro.
      Otherwise, this info will not be added when errp == &error_fatal
      (the program will exit prior to the error_append_hint() or
      error_prepend() call).  Fix several such cases, e.g. in nbd_read().
      
      This commit is generated by command
      
          sed -n '/^Network Block Device (NBD)$/,/^$/{s/^F: //p}' \
              MAINTAINERS | \
          xargs git ls-files | grep '\.[hc]$' | \
          xargs spatch \
              --sp-file scripts/coccinelle/errp-guard.cocci \
              --macro-file scripts/cocci-macro-file.h \
              --in-place --no-show-diff --max-width 80
      
      Reported-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reported-by: default avatarGreg Kurz <groug@kaod.org>
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
      [Commit message tweaked]
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20200707165037.1026246-8-armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      [ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
      auto-propagated-errp.cocci to errp-guard.cocci.  Commit message
      tweaked again.]
      795d946d
    • Vladimir Sementsov-Ogievskiy's avatar
      virtio-9p: Use ERRP_GUARD() · 92c45122
      Vladimir Sementsov-Ogievskiy authored
      
      If we want to check error after errp-function call, we need to
      introduce local_err and then propagate it to errp. Instead, use
      the ERRP_GUARD() macro, benefits are:
      1. No need of explicit error_propagate call
      2. No need of explicit local_err variable: use errp directly
      3. ERRP_GUARD() leaves errp as is if it's not NULL or
         &error_fatal, this means that we don't break error_abort
         (we'll abort on error_set, not on error_propagate)
      
      If we want to add some info to errp (by error_prepend() or
      error_append_hint()), we must use the ERRP_GUARD() macro.
      Otherwise, this info will not be added when errp == &error_fatal
      (the program will exit prior to the error_append_hint() or
      error_prepend() call).  Fix such a case in
      v9fs_device_realize_common().
      
      This commit is generated by command
      
          sed -n '/^virtio-9p$/,/^$/{s/^F: //p}' MAINTAINERS | \
          xargs git ls-files | grep '\.[hc]$' | \
          xargs spatch \
              --sp-file scripts/coccinelle/errp-guard.cocci \
              --macro-file scripts/cocci-macro-file.h \
              --in-place --no-show-diff --max-width 80
      
      Reported-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reported-by: default avatarGreg Kurz <groug@kaod.org>
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Acked-by: default avatarGreg Kurz <groug@kaod.org>
      Reviewed-by: default avatarChristian Schoenebeck <qemu_oss@crudebyte.com>
      [Commit message tweaked]
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20200707165037.1026246-7-armbru@redhat.com>
      [ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
      auto-propagated-errp.cocci to errp-guard.cocci.  Commit message
      tweaked again.]
      92c45122
    • Vladimir Sementsov-Ogievskiy's avatar
      fw_cfg: Use ERRP_GUARD() · 8b4b5275
      Vladimir Sementsov-Ogievskiy authored
      
      If we want to check error after errp-function call, we need to
      introduce local_err and then propagate it to errp. Instead, use
      the ERRP_GUARD() macro, benefits are:
      1. No need of explicit error_propagate call
      2. No need of explicit local_err variable: use errp directly
      3. ERRP_GUARD() leaves errp as is if it's not NULL or
         &error_fatal, this means that we don't break error_abort
         (we'll abort on error_set, not on error_propagate)
      
      If we want to add some info to errp (by error_prepend() or
      error_append_hint()), we must use the ERRP_GUARD() macro.
      Otherwise, this info will not be added when errp == &error_fatal
      (the program will exit prior to the error_append_hint() or
      error_prepend() call).  No such cases are being fixed here.
      
      This commit is generated by command
      
          sed -n '/^Firmware configuration (fw_cfg)$/,/^$/{s/^F: //p}' \
              MAINTAINERS | \
          xargs git ls-files | grep '\.[hc]$' | \
          xargs spatch \
              --sp-file scripts/coccinelle/errp-guard.cocci \
              --macro-file scripts/cocci-macro-file.h \
              --in-place --no-show-diff --max-width 80
      
      Reported-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reported-by: default avatarGreg Kurz <groug@kaod.org>
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      [Commit message tweaked]
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20200707165037.1026246-6-armbru@redhat.com>
      [ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
      auto-propagated-errp.cocci to errp-guard.cocci.  Commit message
      tweaked again.  Coccinelle script rerun for commit 32031489
      "hw/nvram/fw_cfg: Add the FW_CFG_DATA_GENERATOR interface"]
      8b4b5275
    • Vladimir Sementsov-Ogievskiy's avatar
      pflash: Use ERRP_GUARD() · 76612456
      Vladimir Sementsov-Ogievskiy authored
      
      If we want to check error after errp-function call, we need to
      introduce local_err and then propagate it to errp. Instead, use
      the ERRP_GUARD() macro, benefits are:
      1. No need of explicit error_propagate call
      2. No need of explicit local_err variable: use errp directly
      3. ERRP_GUARD() leaves errp as is if it's not NULL or
         &error_fatal, this means that we don't break error_abort
         (we'll abort on error_set, not on error_propagate)
      
      If we want to add some info to errp (by error_prepend() or
      error_append_hint()), we must use the ERRP_GUARD() macro.
      Otherwise, this info will not be added when errp == &error_fatal
      (the program will exit prior to the error_append_hint() or
      error_prepend() call).  No such cases are being fixed here.
      
      This commit is generated by command
      
          sed -n '/^Parallel NOR Flash devices$/,/^$/{s/^F: //p}' \
              MAINTAINERS | \
          xargs git ls-files | grep '\.[hc]$' | \
          xargs spatch \
              --sp-file scripts/coccinelle/errp-guard.cocci \
              --macro-file scripts/cocci-macro-file.h \
              --in-place --no-show-diff --max-width 80
      
      Reported-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reported-by: default avatarGreg Kurz <groug@kaod.org>
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      [Commit message tweaked]
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20200707165037.1026246-5-armbru@redhat.com>
      [ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
      auto-propagated-errp.cocci to errp-guard.cocci.  Commit message
      tweaked again.]
      76612456
    • Vladimir Sementsov-Ogievskiy's avatar
      sd: Use ERRP_GUARD() · de1b3800
      Vladimir Sementsov-Ogievskiy authored
      
      If we want to check error after errp-function call, we need to
      introduce local_err and then propagate it to errp. Instead, use
      the ERRP_GUARD() macro, benefits are:
      1. No need of explicit error_propagate call
      2. No need of explicit local_err variable: use errp directly
      3. ERRP_GUARD() leaves errp as is if it's not NULL or
         &error_fatal, this means that we don't break error_abort
         (we'll abort on error_set, not on error_propagate)
      
      If we want to add some info to errp (by error_prepend() or
      error_append_hint()), we must use the ERRP_GUARD() macro.
      Otherwise, this info will not be added when errp == &error_fatal
      (the program will exit prior to the error_append_hint() or
      error_prepend() call).  No such cases are being fixed here.
      
      This commit is generated by command
      
          sed -n '/^SD (Secure Card)$/,/^$/{s/^F: //p}' \
              MAINTAINERS | \
          xargs git ls-files | grep '\.[hc]$' | \
          xargs spatch \
              --sp-file scripts/coccinelle/errp-guard.cocci \
              --macro-file scripts/cocci-macro-file.h \
              --in-place --no-show-diff --max-width 80
      
      Reported-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reported-by: default avatarGreg Kurz <groug@kaod.org>
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      [Commit message tweaked]
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20200707165037.1026246-4-armbru@redhat.com>
      [ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
      auto-propagated-errp.cocci to errp-guard.cocci.  Commit message
      tweaked again.]
      de1b3800
    • Vladimir Sementsov-Ogievskiy's avatar
      scripts: Coccinelle script to use ERRP_GUARD() · 8220f3ac
      Vladimir Sementsov-Ogievskiy authored
      
      Script adds ERRP_GUARD() macro invocations where appropriate and
      does corresponding changes in code (look for details in
      include/qapi/error.h)
      
      Usage example:
      spatch --sp-file scripts/coccinelle/errp-guard.cocci \
       --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff \
       --max-width 80 FILES...
      
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20200707165037.1026246-3-armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      [ERRP_AUTO_PROPAGATE() renamed to ERRP_GUARD(), and
      auto-propagated-errp.cocci to errp-guard.cocci]
      8220f3ac
    • Vladimir Sementsov-Ogievskiy's avatar
      error: New macro ERRP_GUARD() · ae7c80a7
      Vladimir Sementsov-Ogievskiy authored
      
      Introduce a new ERRP_GUARD() macro, to be used at start of functions
      with an errp OUT parameter.
      
      It has three goals:
      
      1. Fix issue with error_fatal and error_prepend/error_append_hint: the
      user can't see this additional information, because exit() happens in
      error_setg earlier than information is added. [Reported by Greg Kurz]
      
      2. Fix issue with error_abort and error_propagate: when we wrap
      error_abort by local_err+error_propagate, the resulting coredump will
      refer to error_propagate and not to the place where error happened.
      (the macro itself doesn't fix the issue, but it allows us to [3.] drop
      the local_err+error_propagate pattern, which will definitely fix the
      issue) [Reported by Kevin Wolf]
      
      3. Drop local_err+error_propagate pattern, which is used to workaround
      void functions with errp parameter, when caller wants to know resulting
      status. (Note: actually these functions could be merely updated to
      return int error code).
      
      To achieve these goals, later patches will add invocations
      of this macro at the start of functions with either use
      error_prepend/error_append_hint (solving 1) or which use
      local_err+error_propagate to check errors, switching those
      functions to use *errp instead (solving 2 and 3).
      
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Reviewed-by: default avatarPaul Durrant <paul@xen.org>
      Reviewed-by: default avatarGreg Kurz <groug@kaod.org>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      [Merge comments properly with recent commit "error: Document Error API
      usage rules", and edit for clarity.  Put ERRP_AUTO_PROPAGATE() before
      its helpers, and touch up style.  Tweak commit message.]
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20200707165037.1026246-2-armbru@redhat.com>
      [Rename ERRP_AUTO_PROPAGATE() to ERRP_GUARD(), tweak commit message
      again]
      ae7c80a7
    • Markus Armbruster's avatar
      hmp: Ignore Error objects where the return value suffices · a43770df
      Markus Armbruster authored
      
      qdev_print_props() receives and throws away Error objects just to
      check for object_property_get_str() and object_property_print()
      failure.  Unnecessary, both return suitable values, so use those
      instead.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-46-armbru@redhat.com>
      a43770df
    • Markus Armbruster's avatar
      qdev: Ignore Error objects where the return value suffices · 2d226cf6
      Markus Armbruster authored
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-45-armbru@redhat.com>
      2d226cf6
    • Markus Armbruster's avatar
      qemu-img: Ignore Error objects where the return value suffices · 9e194e06
      Markus Armbruster authored
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-44-armbru@redhat.com>
      [One more in img_amend() due to commit 0bc2a50e17 "qemu-option: Use
      returned bool to check for failure"]
      9e194e06
    • Markus Armbruster's avatar
      error: Avoid error_propagate() after migrate_add_blocker() · 386f6c07
      Markus Armbruster authored
      
      When migrate_add_blocker(blocker, &errp) is followed by
      error_propagate(errp, err), we can often just as well do
      migrate_add_blocker(..., errp).
      
      Do that with this Coccinelle script:
      
          @@
          expression blocker, err, errp;
          expression ret;
          @@
          -    ret = migrate_add_blocker(blocker, &err);
          -    if (err) {
          +    ret = migrate_add_blocker(blocker, errp);
          +    if (ret < 0) {
                   ... when != err;
          -        error_propagate(errp, err);
                   ...
               }
      
          @@
          expression blocker, err, errp;
          @@
          -    migrate_add_blocker(blocker, &err);
          -    if (err) {
          +    if (migrate_add_blocker(blocker, errp) < 0) {
                   ... when != err;
          -        error_propagate(errp, err);
                   ...
               }
      
      Double-check @err is not used afterwards.  Dereferencing it would be
      use after free, but checking whether it's null would be legitimate.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-43-armbru@redhat.com>
      386f6c07
    • Markus Armbruster's avatar
      qapi: Purge error_propagate() from QAPI core · 7b3cb803
      Markus Armbruster authored
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-42-armbru@redhat.com>
      7b3cb803
    • Markus Armbruster's avatar
      qapi: Smooth visitor error checking in generated code · cdd2b228
      Markus Armbruster authored
      
      Use visitor functions' return values to check for failure.  Eliminate
      error_propagate() that are now unnecessary.  Delete @err that are now
      unused.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-41-armbru@redhat.com>
      cdd2b228
    • Markus Armbruster's avatar
      qapi: Smooth another visitor error checking pattern · b11a093c
      Markus Armbruster authored
      
      Convert
      
          visit_type_FOO(v, ..., &ptr, &err);
          ...
          if (err) {
              ...
          }
      
      to
      
          visit_type_FOO(v, ..., &ptr, errp);
          ...
          if (!ptr) {
              ...
          }
      
      for functions that set @ptr to non-null / null on success / error.
      
      Eliminate error_propagate() that are now unnecessary.  Delete @err
      that are now unused.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-40-armbru@redhat.com>
      b11a093c
    • Markus Armbruster's avatar
      block/parallels: Simplify parallels_open() after previous commit · 4bc6d7ee
      Markus Armbruster authored
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-39-armbru@redhat.com>
      4bc6d7ee
    • Markus Armbruster's avatar
      error: Reduce unnecessary error propagation · a5f9b9df
      Markus Armbruster authored
      
      When all we do with an Error we receive into a local variable is
      propagating to somewhere else, we can just as well receive it there
      right away, even when we need to keep error_propagate() for other
      error paths.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-38-armbru@redhat.com>
      a5f9b9df
    • Markus Armbruster's avatar
      error: Eliminate error_propagate() manually · 992861fb
      Markus Armbruster authored
      
      When all we do with an Error we receive into a local variable is
      propagating to somewhere else, we can just as well receive it there
      right away.  The previous two commits did that for sufficiently simple
      cases with Coccinelle.  Do it for several more manually.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-37-armbru@redhat.com>
      992861fb
    • Markus Armbruster's avatar
      error: Eliminate error_propagate() with Coccinelle, part 2 · af175e85
      Markus Armbruster authored
      
      When all we do with an Error we receive into a local variable is
      propagating to somewhere else, we can just as well receive it there
      right away.  The previous commit did that with a Coccinelle script I
      consider fairly trustworthy.  This commit uses the same script with
      the matching of return taken out, i.e. we convert
      
          if (!foo(..., &err)) {
              ...
              error_propagate(errp, err);
              ...
          }
      
      to
      
          if (!foo(..., errp)) {
              ...
              ...
          }
      
      This is unsound: @err could still be read between afterwards.  I don't
      know how to express "no read of @err without an intervening write" in
      Coccinelle.  Instead, I manually double-checked for uses of @err.
      
      Suboptimal line breaks tweaked manually.  qdev_realize() simplified
      further to placate scripts/checkpatch.pl.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-36-armbru@redhat.com>
      af175e85
    • Markus Armbruster's avatar
      error: Eliminate error_propagate() with Coccinelle, part 1 · 668f62ec
      Markus Armbruster authored
      
      When all we do with an Error we receive into a local variable is
      propagating to somewhere else, we can just as well receive it there
      right away.  Convert
      
          if (!foo(..., &err)) {
              ...
              error_propagate(errp, err);
              ...
              return ...
          }
      
      to
      
          if (!foo(..., errp)) {
              ...
              ...
              return ...
          }
      
      where nothing else needs @err.  Coccinelle script:
      
          @rule1 forall@
          identifier fun, err, errp, lbl;
          expression list args, args2;
          binary operator op;
          constant c1, c2;
          symbol false;
          @@
               if (
          (
          -        fun(args, &err, args2)
          +        fun(args, errp, args2)
          |
          -        !fun(args, &err, args2)
          +        !fun(args, errp, args2)
          |
          -        fun(args, &err, args2) op c1
          +        fun(args, errp, args2) op c1
          )
                  )
               {
                   ... when != err
                       when != lbl:
                       when strict
          -        error_propagate(errp, err);
                   ... when != err
          (
                   return;
          |
                   return c2;
          |
                   return false;
          )
               }
      
          @rule2 forall@
          identifier fun, err, errp, lbl;
          expression list args, args2;
          expression var;
          binary operator op;
          constant c1, c2;
          symbol false;
          @@
          -    var = fun(args, &err, args2);
          +    var = fun(args, errp, args2);
               ... when != err
               if (
          (
                   var
          |
                   !var
          |
                   var op c1
          )
                  )
               {
                   ... when != err
                       when != lbl:
                       when strict
          -        error_propagate(errp, err);
                   ... when != err
          (
                   return;
          |
                   return c2;
          |
                   return false;
          |
                   return var;
          )
               }
      
          @depends on rule1 || rule2@
          identifier err;
          @@
          -    Error *err = NULL;
               ... when != err
      
      Not exactly elegant, I'm afraid.
      
      The "when != lbl:" is necessary to avoid transforming
      
               if (fun(args, &err)) {
                   goto out
               }
               ...
           out:
               error_propagate(errp, err);
      
      even though other paths to label out still need the error_propagate().
      For an actual example, see sclp_realize().
      
      Without the "when strict", Coccinelle transforms vfio_msix_setup(),
      incorrectly.  I don't know what exactly "when strict" does, only that
      it helps here.
      
      The match of return is narrower than what I want, but I can't figure
      out how to express "return where the operand doesn't use @err".  For
      an example where it's too narrow, see vfio_intx_enable().
      
      Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
      confused by ARMSSE being used both as typedef and function-like macro
      there.  Converted manually.
      
      Line breaks tidied up manually.  One nested declaration of @local_err
      deleted manually.  Preexisting unwanted blank line dropped in
      hw/riscv/sifive_e.c.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-35-armbru@redhat.com>
      668f62ec
    • Markus Armbruster's avatar
      error: Avoid unnecessary error_propagate() after error_setg() · dcfe4805
      Markus Armbruster authored
      
      Replace
      
          error_setg(&err, ...);
          error_propagate(errp, err);
      
      by
      
          error_setg(errp, ...);
      
      Related pattern:
      
          if (...) {
              error_setg(&err, ...);
              goto out;
          }
          ...
       out:
          error_propagate(errp, err);
          return;
      
      When all paths to label out are that way, replace by
      
          if (...) {
              error_setg(errp, ...);
              return;
          }
      
      and delete the label along with the error_propagate().
      
      When we have at most one other path that actually needs to propagate,
      and maybe one at the end that where propagation is unnecessary, e.g.
      
          foo(..., &err);
          if (err) {
              goto out;
          }
          ...
          bar(..., &err);
       out:
          error_propagate(errp, err);
          return;
      
      move the error_propagate() to where it's needed, like
      
          if (...) {
              foo(..., &err);
              error_propagate(errp, err);
              return;
          }
          ...
          bar(..., errp);
          return;
      
      and transform the error_setg() as above.
      
      In some places, the transformation results in obviously unnecessary
      error_propagate().  The next few commits will eliminate them.
      
      Bonus: the elimination of gotos will make later patches in this series
      easier to review.
      
      Candidates for conversion tracked down with this Coccinelle script:
      
          @@
          identifier err, errp;
          expression list args;
          @@
          -    error_setg(&err, args);
          +    error_setg(errp, args);
               ... when != err
               error_propagate(errp, err);
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-34-armbru@redhat.com>
      dcfe4805
    • Markus Armbruster's avatar
      qdev: Use returned bool to check for failure, Coccinelle part · 0c0e618d
      Markus Armbruster authored
      
      The previous commit enables conversion of
      
          qdev_prop_set_drive_err(..., &err);
          if (err) {
          ...
          }
      
      to
      
          if (!qdev_prop_set_drive_err(..., errp)) {
          ...
          }
      
      Coccinelle script:
      
          @@
          identifier fun = qdev_prop_set_drive_err;
          expression list args;
          typedef Error;
          Error *err;
          @@
          -    fun(args, &err);
          -    if (err)
          +    if (!fun(args, &err))
               {
                   ...
               }
      
      One line break tidied up manually.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-33-armbru@redhat.com>
      0c0e618d
    • Markus Armbruster's avatar
      qdev: Make functions taking Error ** return bool, not void · 73ac1aac
      Markus Armbruster authored
      
      See recent commit "error: Document Error API usage rules" for
      rationale.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-32-armbru@redhat.com>
      73ac1aac
    • Markus Armbruster's avatar
      qom: Make functions taking Error ** return bool, not 0/-1 · b783f54d
      Markus Armbruster authored
      
      Just for consistency.  Also fix the example in object_set_props()'s
      documentation.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-31-armbru@redhat.com>
      b783f54d
    • Markus Armbruster's avatar
      qom: Use returned bool to check for failure, manual part · f07ad48d
      Markus Armbruster authored
      
      The previous commit used Coccinelle to convert from checking the Error
      object to checking the return value.  Convert a few more manually.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-30-armbru@redhat.com>
      f07ad48d
    • Markus Armbruster's avatar
      qom: Use returned bool to check for failure, Coccinelle part · 778a2dc5
      Markus Armbruster authored
      
      The previous commit enables conversion of
      
          foo(..., &err);
          if (err) {
              ...
          }
      
      to
      
          if (!foo(..., errp)) {
              ...
          }
      
      for QOM functions that now return true / false on success / error.
      Coccinelle script:
      
          @@
          identifier fun = {
              object_apply_global_props, object_initialize_child_with_props,
              object_initialize_child_with_propsv, object_property_get,
              object_property_get_bool, object_property_parse, object_property_set,
              object_property_set_bool, object_property_set_int,
              object_property_set_link, object_property_set_qobject,
              object_property_set_str, object_property_set_uint, object_set_props,
              object_set_propv, user_creatable_add_dict,
              user_creatable_complete, user_creatable_del
          };
          expression list args, args2;
          typedef Error;
          Error *err;
          @@
          -    fun(args, &err, args2);
          -    if (err)
          +    if (!fun(args, &err, args2))
               {
                   ...
               }
      
      Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
      ARMSSE being used both as typedef and function-like macro there.
      Convert manually.
      
      Line breaks tidied up manually.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-29-armbru@redhat.com>
      778a2dc5
    • Markus Armbruster's avatar
      qom: Make functions taking Error ** return bool, not void · 6fd5bef1
      Markus Armbruster authored
      
      See recent commit "error: Document Error API usage rules" for
      rationale.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-28-armbru@redhat.com>
      6fd5bef1
    • Markus Armbruster's avatar
      qom: Put name parameter before value / visitor parameter · 5325cc34
      Markus Armbruster authored
      
      The object_property_set_FOO() setters take property name and value in
      an unusual order:
      
          void object_property_set_FOO(Object *obj, FOO_TYPE value,
                                       const char *name, Error **errp)
      
      Having to pass value before name feels grating.  Swap them.
      
      Same for object_property_set(), object_property_get(), and
      object_property_parse().
      
      Convert callers with this Coccinelle script:
      
          @@
          identifier fun = {
              object_property_get, object_property_parse, object_property_set_str,
              object_property_set_link, object_property_set_bool,
              object_property_set_int, object_property_set_uint, object_property_set,
              object_property_set_qobject
          };
          expression obj, v, name, errp;
          @@
          -    fun(obj, v, name, errp)
          +    fun(obj, name, v, errp)
      
      Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
      message "no position information".  Convert that one manually.
      
      Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
      ARMSSE being used both as typedef and function-like macro there.
      Convert manually.
      
      Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
      by RXCPU being used both as typedef and function-like macro there.
      Convert manually.  The other files using RXCPU that way don't need
      conversion.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-27-armbru@redhat.com>
      [Straightforwad conflict with commit 2336172d "audio: set default
      value for pcspk.iobase property" resolved]
      5325cc34
    • Markus Armbruster's avatar
      qom: Use return values to check for error where that's simpler · 1c94a351
      Markus Armbruster authored
      
      When using the Error object to check for error, we need to receive it
      into a local variable, then propagate() it to @errp.
      
      Using the return value permits allows receiving it straight to @errp.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-26-armbru@redhat.com>
      1c94a351
    • Markus Armbruster's avatar
      qom: Don't handle impossible object_property_get_link() failure · 4d21fcd5
      Markus Armbruster authored
      
      Don't handle object_property_get_link() failure that can't happen
      unless the programmer screwed up, pass &error_abort.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Message-Id: <20200707160613.848843-25-armbru@redhat.com>
      4d21fcd5
    • Markus Armbruster's avatar
      qom: Crash more nicely on object_property_get_link() failure · 552d7f49
      Markus Armbruster authored
      
      Pass &error_abort instead of NULL where the returned value is
      dereferenced or asserted to be non-null.  Drop a now redundant
      assertion.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-24-armbru@redhat.com>
      552d7f49
    • Markus Armbruster's avatar
      qom: Rename qdev_get_type() to object_get_type() · 90c69fb9
      Markus Armbruster authored
      
      Commit 2f262e06 lifted qdev_get_type() from qdev to object without
      renaming it accordingly.  Do that now.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-23-armbru@redhat.com>
      90c69fb9
    • Markus Armbruster's avatar
      qom: Use error_reportf_err() instead of g_printerr() in examples · fdb0df87
      Markus Armbruster authored
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-22-armbru@redhat.com>
      fdb0df87
    • Markus Armbruster's avatar
      s390x/pci: Fix harmless mistake in zpci's property fid's setter · 5af3a056
      Markus Armbruster authored
      
      s390_pci_set_fid() sets zpci->fid_defined to true even when
      visit_type_uint32() failed.  Reproducer: "-device zpci,fid=junk".
      Harmless in practice, because qdev_device_add() then fails, throwing
      away @zpci.  Fix it anyway.
      
      Cc: Matthew Rosato <mjrosato@linux.ibm.com>
      Cc: Cornelia Huck <cohuck@redhat.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarMatthew Rosato <mjrosato@linux.ibm.com>
      Reviewed-by: default avatarCornelia Huck <cohuck@redhat.com>
      Message-Id: <20200707160613.848843-21-armbru@redhat.com>
      5af3a056
    • Markus Armbruster's avatar
      qapi: Use returned bool to check for failure, manual part · 14217038
      Markus Armbruster authored
      
      The previous commit used Coccinelle to convert from checking the Error
      object to checking the return value.  Convert a few more manually.
      Also tweak control flow in places to conform to the conventional "if
      error bail out" pattern.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-20-armbru@redhat.com>
      14217038
Loading