diff mbox series

[v4,06/16] pci/shpc: refactor shpc_device_plug_common()

Message ID 20230213140103.1518173-7-vsementsov@yandex-team.ru
State New
Headers show
Series pci hotplug tracking | expand

Commit Message

Vladimir Sementsov-Ogievskiy Feb. 13, 2023, 2 p.m. UTC
Rename it to shpc_device_get_slot(), to mention what it does rather
than how it is used. It also helps to reuse it in further commit.

Also, add a return value and get rid of local_err.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 hw/pci/shpc.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

Comments

Anton Kuchin Feb. 14, 2023, 7:36 p.m. UTC | #1
On 13/02/2023 16:00, Vladimir Sementsov-Ogievskiy wrote:
> Rename it to shpc_device_get_slot(), to mention what it does rather
> than how it is used. It also helps to reuse it in further commit.
>
> Also, add a return value and get rid of local_err.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>   hw/pci/shpc.c | 19 ++++++++-----------
>   1 file changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
> index 9f964b1d70..e7bc7192f1 100644
> --- a/hw/pci/shpc.c
> +++ b/hw/pci/shpc.c
> @@ -496,8 +496,9 @@ static const MemoryRegionOps shpc_mmio_ops = {
>           .max_access_size = 4,
>       },
>   };
> -static void shpc_device_plug_common(PCIDevice *affected_dev, int *slot,
> -                                    SHPCDevice *shpc, Error **errp)
> +
> +static bool shpc_device_get_slot(PCIDevice *affected_dev, int *slot,
> +                                 SHPCDevice *shpc, Error **errp)
>   {
>       int pci_slot = PCI_SLOT(affected_dev->devfn);
>       *slot = SHPC_PCI_TO_IDX(pci_slot);
> @@ -507,21 +508,20 @@ static void shpc_device_plug_common(PCIDevice *affected_dev, int *slot,
>                      "controller. Valid slots are between %d and %d.",
>                      pci_slot, SHPC_IDX_TO_PCI(0),
>                      SHPC_IDX_TO_PCI(shpc->nslots) - 1);
> -        return;
> +        return false;
>       }
> +
> +    return true;
>   }
>   
>   void shpc_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
>                               Error **errp)
>   {
> -    Error *local_err = NULL;
>       PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
>       SHPCDevice *shpc = pci_hotplug_dev->shpc;
>       int slot;
>   
> -    shpc_device_plug_common(PCI_DEVICE(dev), &slot, shpc, &local_err);
> -    if (local_err) {
> -        error_propagate(errp, local_err);
> +    if (!shpc_device_get_slot(PCI_DEVICE(dev), &slot, shpc, errp)) {
>           return;
>       }
>   
> @@ -563,16 +563,13 @@ void shpc_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
>   void shpc_device_unplug_request_cb(HotplugHandler *hotplug_dev,
>                                      DeviceState *dev, Error **errp)
>   {
> -    Error *local_err = NULL;
>       PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
>       SHPCDevice *shpc = pci_hotplug_dev->shpc;
>       uint8_t state;
>       uint8_t led;
>       int slot;
>   
> -    shpc_device_plug_common(PCI_DEVICE(dev), &slot, shpc, &local_err);
> -    if (local_err) {
> -        error_propagate(errp, local_err);
> +    if (!shpc_device_get_slot(PCI_DEVICE(dev), &slot, shpc, errp)) {
>           return;
>       }
>   
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
diff mbox series

Patch

diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index 9f964b1d70..e7bc7192f1 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -496,8 +496,9 @@  static const MemoryRegionOps shpc_mmio_ops = {
         .max_access_size = 4,
     },
 };
-static void shpc_device_plug_common(PCIDevice *affected_dev, int *slot,
-                                    SHPCDevice *shpc, Error **errp)
+
+static bool shpc_device_get_slot(PCIDevice *affected_dev, int *slot,
+                                 SHPCDevice *shpc, Error **errp)
 {
     int pci_slot = PCI_SLOT(affected_dev->devfn);
     *slot = SHPC_PCI_TO_IDX(pci_slot);
@@ -507,21 +508,20 @@  static void shpc_device_plug_common(PCIDevice *affected_dev, int *slot,
                    "controller. Valid slots are between %d and %d.",
                    pci_slot, SHPC_IDX_TO_PCI(0),
                    SHPC_IDX_TO_PCI(shpc->nslots) - 1);
-        return;
+        return false;
     }
+
+    return true;
 }
 
 void shpc_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
                             Error **errp)
 {
-    Error *local_err = NULL;
     PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
     SHPCDevice *shpc = pci_hotplug_dev->shpc;
     int slot;
 
-    shpc_device_plug_common(PCI_DEVICE(dev), &slot, shpc, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!shpc_device_get_slot(PCI_DEVICE(dev), &slot, shpc, errp)) {
         return;
     }
 
@@ -563,16 +563,13 @@  void shpc_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
 void shpc_device_unplug_request_cb(HotplugHandler *hotplug_dev,
                                    DeviceState *dev, Error **errp)
 {
-    Error *local_err = NULL;
     PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
     SHPCDevice *shpc = pci_hotplug_dev->shpc;
     uint8_t state;
     uint8_t led;
     int slot;
 
-    shpc_device_plug_common(PCI_DEVICE(dev), &slot, shpc, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!shpc_device_get_slot(PCI_DEVICE(dev), &slot, shpc, errp)) {
         return;
     }