diff mbox series

[v2,01/15] hw/pci/pcie_sriov: Replace fprintf(error_pretty) -> warn_reportf_err()

Message ID 20230203145536.17585-2-philmd@linaro.org
State New
Headers show
Series hw: Use QOM alias properties and few QOM/QDev cleanups | expand

Commit Message

Philippe Mathieu-Daudé Feb. 3, 2023, 2:55 p.m. UTC
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/pci/pcie_sriov.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Markus Armbruster Sept. 25, 2023, 10:24 a.m. UTC | #1
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/pci/pcie_sriov.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c
> index f0bd72e069..93b0624599 100644
> --- a/hw/pci/pcie_sriov.c
> +++ b/hw/pci/pcie_sriov.c
> @@ -196,19 +196,17 @@ static void register_vfs(PCIDevice *dev)
>  
>  static void unregister_vfs(PCIDevice *dev)
>  {
> -    Error *local_err = NULL;
>      uint16_t num_vfs = dev->exp.sriov_pf.num_vfs;
>      uint16_t i;
>  
>      trace_sriov_unregister_vfs(dev->name, PCI_SLOT(dev->devfn),
>                                 PCI_FUNC(dev->devfn), num_vfs);
>      for (i = 0; i < num_vfs; i++) {
> +        Error *errp = NULL;
>          PCIDevice *vf = dev->exp.sriov_pf.vf[i];
> -        object_property_set_bool(OBJECT(vf), "realized", false, &local_err);
> -        if (local_err) {
> -            fprintf(stderr, "Failed to unplug: %s\n",
> -                    error_get_pretty(local_err));
> -            error_free(local_err);
> +        object_property_set_bool(OBJECT(vf), "realized", false, &errp);
> +        if (errp) {
> +            warn_reportf_err(errp, "Failed to unplug: ");
>          }
>          object_unparent(OBJECT(vf));
>      }

We use @errp for Error **, and @err, @local_err and similar for Error *.
Recommend to stick with @local_err here, i.e. just

  -            fprintf(stderr, "Failed to unplug: %s\n",
  -                    error_get_pretty(local_err));
  -            error_free(local_err);
  +            warn_reportf_err(local_err, "Failed to unplug: ");
diff mbox series

Patch

diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c
index f0bd72e069..93b0624599 100644
--- a/hw/pci/pcie_sriov.c
+++ b/hw/pci/pcie_sriov.c
@@ -196,19 +196,17 @@  static void register_vfs(PCIDevice *dev)
 
 static void unregister_vfs(PCIDevice *dev)
 {
-    Error *local_err = NULL;
     uint16_t num_vfs = dev->exp.sriov_pf.num_vfs;
     uint16_t i;
 
     trace_sriov_unregister_vfs(dev->name, PCI_SLOT(dev->devfn),
                                PCI_FUNC(dev->devfn), num_vfs);
     for (i = 0; i < num_vfs; i++) {
+        Error *errp = NULL;
         PCIDevice *vf = dev->exp.sriov_pf.vf[i];
-        object_property_set_bool(OBJECT(vf), "realized", false, &local_err);
-        if (local_err) {
-            fprintf(stderr, "Failed to unplug: %s\n",
-                    error_get_pretty(local_err));
-            error_free(local_err);
+        object_property_set_bool(OBJECT(vf), "realized", false, &errp);
+        if (errp) {
+            warn_reportf_err(errp, "Failed to unplug: ");
         }
         object_unparent(OBJECT(vf));
     }