diff mbox series

[1/7] hw/virtio/virtio-pmem: Replace impossible check by assertion

Message ID 20231017140150.44995-2-philmd@linaro.org
State Superseded
Headers show
Series hw: Few more QOM/QDev cleanups | expand

Commit Message

Philippe Mathieu-Daudé Oct. 17, 2023, 2:01 p.m. UTC
The get_memory_region() handler is used when (un)plugging the
device, which can only occur *after* it is realized.

virtio_pmem_realize() ensure the instance can not be realized
without 'memdev'. Remove the superfluous check, replacing it
by an assertion.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/virtio/virtio-pmem.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Manos Pitsidianakis Oct. 17, 2023, 5:20 p.m. UTC | #1
On Tue, 17 Oct 2023 17:01, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>The get_memory_region() handler is used when (un)plugging the
>device, which can only occur *after* it is realized.
>
>virtio_pmem_realize() ensure the instance can not be realized
>without 'memdev'. Remove the superfluous check, replacing it
>by an assertion.
>
>Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>---
> hw/virtio/virtio-pmem.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
>diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c
>index c3512c2dae..cc24812d2e 100644
>--- a/hw/virtio/virtio-pmem.c
>+++ b/hw/virtio/virtio-pmem.c
>@@ -147,10 +147,7 @@ static void virtio_pmem_fill_device_info(const VirtIOPMEM *pmem,
> static MemoryRegion *virtio_pmem_get_memory_region(VirtIOPMEM *pmem,
>                                                    Error **errp)
> {
>-    if (!pmem->memdev) {
>-        error_setg(errp, "'%s' property must be set", VIRTIO_PMEM_MEMDEV_PROP);
>-        return NULL;
>-    }
>+    assert(pmem->memdev);
> 
>     return &pmem->memdev->mr;
> }
>-- 
>2.41.0
>

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
diff mbox series

Patch

diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c
index c3512c2dae..cc24812d2e 100644
--- a/hw/virtio/virtio-pmem.c
+++ b/hw/virtio/virtio-pmem.c
@@ -147,10 +147,7 @@  static void virtio_pmem_fill_device_info(const VirtIOPMEM *pmem,
 static MemoryRegion *virtio_pmem_get_memory_region(VirtIOPMEM *pmem,
                                                    Error **errp)
 {
-    if (!pmem->memdev) {
-        error_setg(errp, "'%s' property must be set", VIRTIO_PMEM_MEMDEV_PROP);
-        return NULL;
-    }
+    assert(pmem->memdev);
 
     return &pmem->memdev->mr;
 }