Skip to contentSkip to conversation

some simplifications in hw/core/fw-path-provider.c

PATCH In review Daniel Henrique Barboza 2 participants 4 messages Jan 21, 2022

lore
Share & tools
lore
#0 lore raw

cover some simplifications in hw/core/fw-path-provider.c

Hi,

These are somes simplifications I found interesting to make while I was investigating Gitlab #720.

It isn't clear in the MAINTAINERS file who is responsible for this file, so I'm ccing the QOM maintainers since it's the closest match.

Daniel Henrique Barboza (2):
hw/core/fw-path-provider: turn fw_path_provider_get_dev_path() static hw/core/fw-path-provider.c: open code fw_path_provider_get_dev_path()

 hw/core/fw-path-provider.c    | 14 +++-----------
 include/hw/fw-path-provider.h |  2 --
 2 files changed, 3 insertions(+), 13 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 hw/core/fw-path-provider: turn fw_path_provider_get_dev_path() static

This function is used only by fw_path_provider_try_get_dev_path() in the same file.

---
 hw/core/fw-path-provider.c    | 4 ++--
 include/hw/fw-path-provider.h | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)
hw/core/fw-path-provider.c +2 -2
index 4840faefd1..4bcf4e7e34 100644
@@ -19,8 +19,8 @@
 #include "hw/fw-path-provider.h"
 #include "qemu/module.h"
 
-char *fw_path_provider_get_dev_path(FWPathProvider *p, BusState *bus,
-                                    DeviceState *dev)
+static char *fw_path_provider_get_dev_path(FWPathProvider *p, BusState *bus,
+                                           DeviceState *dev)
 {
     FWPathProviderClass *k = FW_PATH_PROVIDER_GET_CLASS(p);
 
include/hw/fw-path-provider.h +0 -2
index 8e1d45651c..9ef50ebe4a 100644
@@ -36,8 +36,6 @@ struct FWPathProviderClass {
     char *(*get_dev_path)(FWPathProvider *p, BusState *bus, DeviceState *dev);
 };
 
-char *fw_path_provider_get_dev_path(FWPathProvider *p, BusState *bus,
-                                    DeviceState *dev);
 char *fw_path_provider_try_get_dev_path(Object *o, BusState *bus,
                                         DeviceState *dev);
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/2 hw/core/fw-path-provider.c: open code fw_path_provider_get_dev_path()

In reply to Daniel Henrique Barboza

fw_path_provider_get_dev_path() is 2 lines long and it's used only by fw_path_provider_try_get_dev_path(), which checks if FWPathProvider is not NULL before calling it.

Open coding fw_path_provider_get_dev_path() into fw_path_provider_try_get_dev_path() simplifies the code inside fw-path-provider.c and make it easier to grep our way into finding the callers of the FWPathProviderClass::get_dev_path() interface.

---
 hw/core/fw-path-provider.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
hw/core/fw-path-provider.c +3 -11
index 4bcf4e7e34..b8fa649fe2 100644
@@ -19,25 +19,17 @@
 #include "hw/fw-path-provider.h"
 #include "qemu/module.h"
 
-static char *fw_path_provider_get_dev_path(FWPathProvider *p, BusState *bus,
-                                           DeviceState *dev)
-{
-    FWPathProviderClass *k = FW_PATH_PROVIDER_GET_CLASS(p);
-
-    return k->get_dev_path(p, bus, dev);
-}
-
 char *fw_path_provider_try_get_dev_path(Object *o, BusState *bus,
                                         DeviceState *dev)
 {
     FWPathProvider *p = (FWPathProvider *)
         object_dynamic_cast(o, TYPE_FW_PATH_PROVIDER);
 
-    if (p) {
-        return fw_path_provider_get_dev_path(p, bus, dev);
+    if (!p) {
+        return NULL;
     }
 
-    return NULL;
+    return FW_PATH_PROVIDER_GET_CLASS(p)->get_dev_path(p, bus, dev);
 }
 
 static const TypeInfo fw_path_provider_info = {
Signature · 1 line
2.34.1
Reviewed-by Philippe Mathieu-Daudé on the v1 series
#3 lore raw
In reply to Daniel Henrique Barboza
Quoted 5 lines · Daniel Henrique Barboza

Hi,

These are somes simplifications I found interesting to make while I was investigating Gitlab #720.

Quoted 7 lines

It isn't clear in the MAINTAINERS file who is responsible for this file, so I'm ccing the QOM maintainers since it's the closest match.

Daniel Henrique Barboza (2):
hw/core/fw-path-provider: turn fw_path_provider_get_dev_path() static hw/core/fw-path-provider.c: open code fw_path_provider_get_dev_path()