All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/9] hw/usb: Cleanups around QOM style
@ 2023-02-20 15:05 Philippe Mathieu-Daudé
  2023-02-20 15:05 ` [PATCH 1/9] hw/usb/dev-smartcard-reader: Avoid forward-declaring CCIDBus Philippe Mathieu-Daudé
                   ` (8 more replies)
  0 siblings, 9 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-20 15:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster, Philippe Mathieu-Daudé

- Use QOM's OBJECT_DECLARE*TYPE() to declare typedef / macros
- Use QOM cast macros instead of container_of()

Philippe Mathieu-Daudé (9):
  hw/usb/dev-smartcard-reader: Avoid forward-declaring CCIDBus
  hw/usb/hcd-ohci: Use OHCIState type definition
  hw/usb/hcd-ohci-pci: Use QOM type-safe cast conversion macro
  hw/usb/hcd-uhci: Declare QOM macros using OBJECT_DECLARE_TYPE()
  hw/usb/hcd-uhci: Replace container_of() by UHCI_GET_CLASS() QOM macro
  hw/usb/hcd-xhci-nec: Declare QOM macros for NEC_XHCI
  hw/usb/hcd-xhci-nec: Replace container_of() by NEC_XHCI() QOM cast
    macro
  hw/usb/u2f: Declare QOM macros using OBJECT_DECLARE_TYPE()
  hw/usb/u2f-passthru: Use QOM type-safe cast conversion macros

 hw/usb/dev-smartcard-reader.c |  7 +++----
 hw/usb/hcd-ohci-pci.c         |  4 ++--
 hw/usb/hcd-ohci.c             |  2 +-
 hw/usb/hcd-ohci.h             | 10 ++++++----
 hw/usb/hcd-uhci.c             |  7 ++-----
 hw/usb/hcd-uhci.h             |  2 +-
 hw/usb/hcd-xhci-nec.c         |  8 +++++---
 hw/usb/u2f-passthru.c         |  7 ++++---
 hw/usb/u2f.h                  | 16 +++++-----------
 9 files changed, 29 insertions(+), 34 deletions(-)

-- 
2.38.1



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/9] hw/usb/dev-smartcard-reader: Avoid forward-declaring CCIDBus
  2023-02-20 15:05 [PATCH 0/9] hw/usb: Cleanups around QOM style Philippe Mathieu-Daudé
@ 2023-02-20 15:05 ` Philippe Mathieu-Daudé
  2023-02-20 19:08   ` Richard Henderson
  2023-02-20 15:05 ` [PATCH 2/9] hw/usb/hcd-ohci: Use OHCIState type definition Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-20 15:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster, Philippe Mathieu-Daudé

To avoid forward-declaring CCIDBus, declare CCID_BUS QOM
definitions before its use in the USBCCIDState structure.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/usb/dev-smartcard-reader.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index 28164d89be..be0a4fc3bc 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -278,7 +278,9 @@ typedef struct BulkIn {
 struct CCIDBus {
     BusState qbus;
 };
-typedef struct CCIDBus CCIDBus;
+
+#define TYPE_CCID_BUS "ccid-bus"
+OBJECT_DECLARE_SIMPLE_TYPE(CCIDBus, CCID_BUS)
 
 /*
  * powered - defaults to true, changed by PowerOn/PowerOff messages
@@ -1174,9 +1176,6 @@ static Property ccid_props[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
-#define TYPE_CCID_BUS "ccid-bus"
-OBJECT_DECLARE_SIMPLE_TYPE(CCIDBus, CCID_BUS)
-
 static const TypeInfo ccid_bus_info = {
     .name = TYPE_CCID_BUS,
     .parent = TYPE_BUS,
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/9] hw/usb/hcd-ohci: Use OHCIState type definition
  2023-02-20 15:05 [PATCH 0/9] hw/usb: Cleanups around QOM style Philippe Mathieu-Daudé
  2023-02-20 15:05 ` [PATCH 1/9] hw/usb/dev-smartcard-reader: Avoid forward-declaring CCIDBus Philippe Mathieu-Daudé
@ 2023-02-20 15:05 ` Philippe Mathieu-Daudé
  2023-02-20 19:09   ` Richard Henderson
  2023-02-20 15:05 ` [PATCH 3/9] hw/usb/hcd-ohci-pci: Use QOM type-safe cast conversion macro Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-20 15:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster, Philippe Mathieu-Daudé

Forward-define the type first, then use it for the ohci_die() handler.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/usb/hcd-ohci.c |  2 +-
 hw/usb/hcd-ohci.h | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index 9d68036d23..7ecf9b15b7 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -1827,7 +1827,7 @@ static USBBusOps ohci_bus_ops = {
 void usb_ohci_init(OHCIState *ohci, DeviceState *dev, uint32_t num_ports,
                    dma_addr_t localmem_base, char *masterbus,
                    uint32_t firstport, AddressSpace *as,
-                   void (*ohci_die_fn)(struct OHCIState *), Error **errp)
+                   void (*ohci_die_fn)(OHCIState *), Error **errp)
 {
     Error *err = NULL;
     int i;
diff --git a/hw/usb/hcd-ohci.h b/hw/usb/hcd-ohci.h
index 11ac57058d..8a9ba8b959 100644
--- a/hw/usb/hcd-ohci.h
+++ b/hw/usb/hcd-ohci.h
@@ -33,7 +33,9 @@ typedef struct OHCIPort {
     uint32_t ctrl;
 } OHCIPort;
 
-typedef struct OHCIState {
+typedef struct OHCIState OHCIState;
+
+struct OHCIState {
     USBBus bus;
     qemu_irq irq;
     MemoryRegion mem;
@@ -89,8 +91,8 @@ typedef struct OHCIState {
     uint32_t async_td;
     bool async_complete;
 
-    void (*ohci_die)(struct OHCIState *ohci);
-} OHCIState;
+    void (*ohci_die)(OHCIState *ohci);
+};
 
 #define TYPE_SYSBUS_OHCI "sysbus-ohci"
 OBJECT_DECLARE_SIMPLE_TYPE(OHCISysBusState, SYSBUS_OHCI)
@@ -112,7 +114,7 @@ extern const VMStateDescription vmstate_ohci_state;
 void usb_ohci_init(OHCIState *ohci, DeviceState *dev, uint32_t num_ports,
                    dma_addr_t localmem_base, char *masterbus,
                    uint32_t firstport, AddressSpace *as,
-                   void (*ohci_die_fn)(struct OHCIState *), Error **errp);
+                   void (*ohci_die_fn)(OHCIState *), Error **errp);
 void ohci_bus_stop(OHCIState *ohci);
 void ohci_stop_endpoints(OHCIState *ohci);
 void ohci_hard_reset(OHCIState *ohci);
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/9] hw/usb/hcd-ohci-pci: Use QOM type-safe cast conversion macro
  2023-02-20 15:05 [PATCH 0/9] hw/usb: Cleanups around QOM style Philippe Mathieu-Daudé
  2023-02-20 15:05 ` [PATCH 1/9] hw/usb/dev-smartcard-reader: Avoid forward-declaring CCIDBus Philippe Mathieu-Daudé
  2023-02-20 15:05 ` [PATCH 2/9] hw/usb/hcd-ohci: Use OHCIState type definition Philippe Mathieu-Daudé
@ 2023-02-20 15:05 ` Philippe Mathieu-Daudé
  2023-02-20 15:05 ` [PATCH 4/9] hw/usb/hcd-uhci: Declare QOM macros using OBJECT_DECLARE_TYPE() Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-20 15:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster, Philippe Mathieu-Daudé

Use the PCI_DEVICE() QOM cast macros to avoid accessing internal fields.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/usb/hcd-ohci-pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/usb/hcd-ohci-pci.c b/hw/usb/hcd-ohci-pci.c
index 6b630d35a7..3234408f1a 100644
--- a/hw/usb/hcd-ohci-pci.c
+++ b/hw/usb/hcd-ohci-pci.c
@@ -52,11 +52,11 @@ struct OHCIPCIState {
 static void ohci_pci_die(struct OHCIState *ohci)
 {
     OHCIPCIState *dev = container_of(ohci, OHCIPCIState, state);
+    PCIDevice *pdev = PCI_DEVICE(dev);
 
     ohci_sysbus_die(ohci);
 
-    pci_set_word(dev->parent_obj.config + PCI_STATUS,
-                 PCI_STATUS_DETECTED_PARITY);
+    pci_set_word(pdev->config + PCI_STATUS, PCI_STATUS_DETECTED_PARITY);
 }
 
 static void usb_ohci_realize_pci(PCIDevice *dev, Error **errp)
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 4/9] hw/usb/hcd-uhci: Declare QOM macros using OBJECT_DECLARE_TYPE()
  2023-02-20 15:05 [PATCH 0/9] hw/usb: Cleanups around QOM style Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2023-02-20 15:05 ` [PATCH 3/9] hw/usb/hcd-ohci-pci: Use QOM type-safe cast conversion macro Philippe Mathieu-Daudé
@ 2023-02-20 15:05 ` Philippe Mathieu-Daudé
  2023-02-20 19:11   ` Richard Henderson
  2023-02-20 15:05 ` [PATCH 5/9] hw/usb/hcd-uhci: Replace container_of() by UHCI_GET_CLASS() QOM macro Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-20 15:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster, Philippe Mathieu-Daudé

The automatic conversion done during commit a489d1951c
("Use OBJECT_DECLARE_TYPE when possible") missed this
model because the typedefs are in a different file unit
(hcd-uhci.c) than where the DECLARE_INSTANCE_CHECKER()
is (hcd-uhci.h). Manually convert to OBJECT_DECLARE_TYPE().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/usb/hcd-uhci.c | 2 --
 hw/usb/hcd-uhci.h | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index 30ae0104bb..f77ffda69a 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -60,9 +60,7 @@ enum {
     TD_RESULT_ASYNC_CONT,
 };
 
-typedef struct UHCIState UHCIState;
 typedef struct UHCIAsync UHCIAsync;
-typedef struct UHCIPCIDeviceClass UHCIPCIDeviceClass;
 
 struct UHCIPCIDeviceClass {
     PCIDeviceClass parent_class;
diff --git a/hw/usb/hcd-uhci.h b/hw/usb/hcd-uhci.h
index e0fdb98ef1..69f8b40c49 100644
--- a/hw/usb/hcd-uhci.h
+++ b/hw/usb/hcd-uhci.h
@@ -75,7 +75,7 @@ typedef struct UHCIState {
 } UHCIState;
 
 #define TYPE_UHCI "pci-uhci-usb"
-DECLARE_INSTANCE_CHECKER(UHCIState, UHCI, TYPE_UHCI)
+OBJECT_DECLARE_TYPE(UHCIState, UHCIPCIDeviceClass, UHCI)
 
 typedef struct UHCIInfo {
     const char *name;
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 5/9] hw/usb/hcd-uhci: Replace container_of() by UHCI_GET_CLASS() QOM macro
  2023-02-20 15:05 [PATCH 0/9] hw/usb: Cleanups around QOM style Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2023-02-20 15:05 ` [PATCH 4/9] hw/usb/hcd-uhci: Declare QOM macros using OBJECT_DECLARE_TYPE() Philippe Mathieu-Daudé
@ 2023-02-20 15:05 ` Philippe Mathieu-Daudé
  2023-02-20 19:11   ` Richard Henderson
  2023-02-20 15:05 ` [PATCH 6/9] hw/usb/hcd-xhci-nec: Declare QOM macros for NEC_XHCI Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-20 15:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster, Philippe Mathieu-Daudé

By using the QOM UHCI_GET_CLASS() cast macro we don't to
use the intermediate PCIDeviceClass variable.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/usb/hcd-uhci.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index f77ffda69a..8ac1175ad2 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -1159,8 +1159,7 @@ static USBBusOps uhci_bus_ops = {
 void usb_uhci_common_realize(PCIDevice *dev, Error **errp)
 {
     Error *err = NULL;
-    PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
-    UHCIPCIDeviceClass *u = container_of(pc, UHCIPCIDeviceClass, parent_class);
+    UHCIPCIDeviceClass *u = UHCI_GET_CLASS(dev);
     UHCIState *s = UHCI(dev);
     uint8_t *pci_conf = s->dev.config;
     int i;
@@ -1267,7 +1266,7 @@ void uhci_data_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
-    UHCIPCIDeviceClass *u = container_of(k, UHCIPCIDeviceClass, parent_class);
+    UHCIPCIDeviceClass *u = UHCI_CLASS(klass);
     UHCIInfo *info = data;
 
     k->realize = info->realize ? info->realize : usb_uhci_common_realize;
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 6/9] hw/usb/hcd-xhci-nec: Declare QOM macros for NEC_XHCI
  2023-02-20 15:05 [PATCH 0/9] hw/usb: Cleanups around QOM style Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2023-02-20 15:05 ` [PATCH 5/9] hw/usb/hcd-uhci: Replace container_of() by UHCI_GET_CLASS() QOM macro Philippe Mathieu-Daudé
@ 2023-02-20 15:05 ` Philippe Mathieu-Daudé
  2023-02-20 19:12   ` Richard Henderson
  2023-02-20 15:05 ` [PATCH 7/9] hw/usb/hcd-xhci-nec: Replace container_of() by NEC_XHCI() QOM cast macro Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-20 15:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster, Philippe Mathieu-Daudé

NEC_XHCI is a QOM object type. Declare its macros /
typedefs using OBJECT_DECLARE_SIMPLE_TYPE().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/usb/hcd-xhci-nec.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/usb/hcd-xhci-nec.c b/hw/usb/hcd-xhci-nec.c
index 13c9ac5dbd..d732be0ef9 100644
--- a/hw/usb/hcd-xhci-nec.c
+++ b/hw/usb/hcd-xhci-nec.c
@@ -27,14 +27,16 @@
 
 #include "hcd-xhci-pci.h"
 
-typedef struct XHCINecState {
+OBJECT_DECLARE_SIMPLE_TYPE(XHCINecState, NEC_XHCI)
+
+struct XHCINecState {
     /*< private >*/
     XHCIPciState parent_obj;
     /*< public >*/
     uint32_t flags;
     uint32_t intrs;
     uint32_t slots;
-} XHCINecState;
+};
 
 static Property nec_xhci_properties[] = {
     DEFINE_PROP_ON_OFF_AUTO("msi", XHCIPciState, msi, ON_OFF_AUTO_AUTO),
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 7/9] hw/usb/hcd-xhci-nec: Replace container_of() by NEC_XHCI() QOM cast macro
  2023-02-20 15:05 [PATCH 0/9] hw/usb: Cleanups around QOM style Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2023-02-20 15:05 ` [PATCH 6/9] hw/usb/hcd-xhci-nec: Declare QOM macros for NEC_XHCI Philippe Mathieu-Daudé
@ 2023-02-20 15:05 ` Philippe Mathieu-Daudé
  2023-02-20 19:13   ` Richard Henderson
  2023-02-20 15:05 ` [PATCH 8/9] hw/usb/u2f: Declare QOM macros using OBJECT_DECLARE_TYPE() Philippe Mathieu-Daudé
  2023-02-20 15:05 ` [PATCH 9/9] hw/usb/u2f-passthru: Use QOM type-safe cast conversion macros Philippe Mathieu-Daudé
  8 siblings, 1 reply; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-20 15:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/usb/hcd-xhci-nec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/usb/hcd-xhci-nec.c b/hw/usb/hcd-xhci-nec.c
index d732be0ef9..328e5bfe7c 100644
--- a/hw/usb/hcd-xhci-nec.c
+++ b/hw/usb/hcd-xhci-nec.c
@@ -53,7 +53,7 @@ static Property nec_xhci_properties[] = {
 static void nec_xhci_instance_init(Object *obj)
 {
     XHCIPciState *pci = XHCI_PCI(obj);
-    XHCINecState *nec = container_of(pci, XHCINecState, parent_obj);
+    XHCINecState *nec = NEC_XHCI(obj);
 
     pci->xhci.flags    = nec->flags;
     pci->xhci.numintrs = nec->intrs;
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 8/9] hw/usb/u2f: Declare QOM macros using OBJECT_DECLARE_TYPE()
  2023-02-20 15:05 [PATCH 0/9] hw/usb: Cleanups around QOM style Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2023-02-20 15:05 ` [PATCH 7/9] hw/usb/hcd-xhci-nec: Replace container_of() by NEC_XHCI() QOM cast macro Philippe Mathieu-Daudé
@ 2023-02-20 15:05 ` Philippe Mathieu-Daudé
  2023-02-20 19:22   ` Richard Henderson
  2023-02-20 15:05 ` [PATCH 9/9] hw/usb/u2f-passthru: Use QOM type-safe cast conversion macros Philippe Mathieu-Daudé
  8 siblings, 1 reply; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-20 15:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster, Philippe Mathieu-Daudé

hw/usb/u2f.h was added by commit 80e267f1d1 ("hw/usb: Add
U2F key base class"), almost the same time of the automatic
conversion done by commit c821774a3b ("Use OBJECT_DECLARE_TYPE
where posible"). Manually convert to OBJECT_DECLARE_TYPE().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/usb/u2f.h | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/hw/usb/u2f.h b/hw/usb/u2f.h
index a408a82927..8bff13141a 100644
--- a/hw/usb/u2f.h
+++ b/hw/usb/u2f.h
@@ -31,22 +31,16 @@
 #define U2FHID_PACKET_SIZE 64
 #define U2FHID_PENDING_IN_NUM 32
 
-typedef struct U2FKeyState U2FKeyState;
 typedef struct U2FKeyInfo U2FKeyInfo;
 
 #define TYPE_U2F_KEY "u2f-key"
-#define U2F_KEY(obj) \
-    OBJECT_CHECK(U2FKeyState, (obj), TYPE_U2F_KEY)
-#define U2F_KEY_CLASS(klass) \
-    OBJECT_CLASS_CHECK(U2FKeyClass, (klass), TYPE_U2F_KEY)
-#define U2F_KEY_GET_CLASS(obj) \
-    OBJECT_GET_CLASS(U2FKeyClass, (obj), TYPE_U2F_KEY)
+OBJECT_DECLARE_TYPE(U2FKeyState, U2FKeyClass, U2F_KEY)
 
 /*
  * Callbacks to be used by the U2F key base device (i.e. hw/u2f.c)
  * to interact with its variants (i.e. hw/u2f-*.c)
  */
-typedef struct U2FKeyClass {
+struct U2FKeyClass {
     /*< private >*/
     USBDeviceClass parent_class;
 
@@ -55,12 +49,12 @@ typedef struct U2FKeyClass {
                             const uint8_t packet[U2FHID_PACKET_SIZE]);
     void (*realize)(U2FKeyState *key, Error **errp);
     void (*unrealize)(U2FKeyState *key);
-} U2FKeyClass;
+};
 
 /*
  * State of the U2F key base device (i.e. hw/u2f.c)
  */
-typedef struct U2FKeyState {
+struct U2FKeyState {
     USBDevice dev;
     USBEndpoint *ep;
     uint8_t idle;
@@ -70,7 +64,7 @@ typedef struct U2FKeyState {
     uint8_t pending_in_start;
     uint8_t pending_in_end;
     uint8_t pending_in_num;
-} U2FKeyState;
+};
 
 /*
  * API to be used by the U2F key device variants (i.e. hw/u2f-*.c)
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 9/9] hw/usb/u2f-passthru: Use QOM type-safe cast conversion macros
  2023-02-20 15:05 [PATCH 0/9] hw/usb: Cleanups around QOM style Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2023-02-20 15:05 ` [PATCH 8/9] hw/usb/u2f: Declare QOM macros using OBJECT_DECLARE_TYPE() Philippe Mathieu-Daudé
@ 2023-02-20 15:05 ` Philippe Mathieu-Daudé
  8 siblings, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-20 15:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster, Philippe Mathieu-Daudé

Use the QOM cast macros to avoid accessing internal fields.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/usb/u2f-passthru.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/usb/u2f-passthru.c b/hw/usb/u2f-passthru.c
index fc93429c9c..b99c0b622f 100644
--- a/hw/usb/u2f-passthru.c
+++ b/hw/usb/u2f-passthru.c
@@ -299,7 +299,7 @@ static void u2f_passthru_recv_from_host(U2FPassthruState *key,
     if (transaction->resp_size >= transaction->resp_bcnt) {
         u2f_transaction_close(key, cid);
     }
-    u2f_send_to_guest(&key->base, packet);
+    u2f_send_to_guest(U2F_KEY(key), packet);
 }
 
 static void u2f_passthru_read(void *opaque)
@@ -316,9 +316,10 @@ static void u2f_passthru_read(void *opaque)
 
     ret = read(key->hidraw_fd, packet, sizeof(packet));
     if (ret < 0) {
+        USBDevice *udev = USB_DEVICE(key);
         /* Detach */
-        if (base->dev.attached) {
-            usb_device_detach(&base->dev);
+        if (udev->attached) {
+            usb_device_detach(udev);
             u2f_passthru_reset(key);
         }
         return;
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/9] hw/usb/dev-smartcard-reader: Avoid forward-declaring CCIDBus
  2023-02-20 15:05 ` [PATCH 1/9] hw/usb/dev-smartcard-reader: Avoid forward-declaring CCIDBus Philippe Mathieu-Daudé
@ 2023-02-20 19:08   ` Richard Henderson
  0 siblings, 0 replies; 17+ messages in thread
From: Richard Henderson @ 2023-02-20 19:08 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster

On 2/20/23 05:05, Philippe Mathieu-Daudé wrote:
> To avoid forward-declaring CCIDBus, declare CCID_BUS QOM
> definitions before its use in the USBCCIDState structure.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/usb/dev-smartcard-reader.c | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/9] hw/usb/hcd-ohci: Use OHCIState type definition
  2023-02-20 15:05 ` [PATCH 2/9] hw/usb/hcd-ohci: Use OHCIState type definition Philippe Mathieu-Daudé
@ 2023-02-20 19:09   ` Richard Henderson
  0 siblings, 0 replies; 17+ messages in thread
From: Richard Henderson @ 2023-02-20 19:09 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster

On 2/20/23 05:05, Philippe Mathieu-Daudé wrote:
> Forward-define the type first, then use it for the ohci_die() handler.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/usb/hcd-ohci.c |  2 +-
>   hw/usb/hcd-ohci.h | 10 ++++++----
>   2 files changed, 7 insertions(+), 5 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 4/9] hw/usb/hcd-uhci: Declare QOM macros using OBJECT_DECLARE_TYPE()
  2023-02-20 15:05 ` [PATCH 4/9] hw/usb/hcd-uhci: Declare QOM macros using OBJECT_DECLARE_TYPE() Philippe Mathieu-Daudé
@ 2023-02-20 19:11   ` Richard Henderson
  0 siblings, 0 replies; 17+ messages in thread
From: Richard Henderson @ 2023-02-20 19:11 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster

On 2/20/23 05:05, Philippe Mathieu-Daudé wrote:
> The automatic conversion done during commit a489d1951c
> ("Use OBJECT_DECLARE_TYPE when possible") missed this
> model because the typedefs are in a different file unit
> (hcd-uhci.c) than where the DECLARE_INSTANCE_CHECKER()
> is (hcd-uhci.h). Manually convert to OBJECT_DECLARE_TYPE().
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/usb/hcd-uhci.c | 2 --
>   hw/usb/hcd-uhci.h | 2 +-
>   2 files changed, 1 insertion(+), 3 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/9] hw/usb/hcd-uhci: Replace container_of() by UHCI_GET_CLASS() QOM macro
  2023-02-20 15:05 ` [PATCH 5/9] hw/usb/hcd-uhci: Replace container_of() by UHCI_GET_CLASS() QOM macro Philippe Mathieu-Daudé
@ 2023-02-20 19:11   ` Richard Henderson
  0 siblings, 0 replies; 17+ messages in thread
From: Richard Henderson @ 2023-02-20 19:11 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster

On 2/20/23 05:05, Philippe Mathieu-Daudé wrote:
> By using the QOM UHCI_GET_CLASS() cast macro we don't to
> use the intermediate PCIDeviceClass variable.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/usb/hcd-uhci.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 6/9] hw/usb/hcd-xhci-nec: Declare QOM macros for NEC_XHCI
  2023-02-20 15:05 ` [PATCH 6/9] hw/usb/hcd-xhci-nec: Declare QOM macros for NEC_XHCI Philippe Mathieu-Daudé
@ 2023-02-20 19:12   ` Richard Henderson
  0 siblings, 0 replies; 17+ messages in thread
From: Richard Henderson @ 2023-02-20 19:12 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster

On 2/20/23 05:05, Philippe Mathieu-Daudé wrote:
> NEC_XHCI is a QOM object type. Declare its macros /
> typedefs using OBJECT_DECLARE_SIMPLE_TYPE().
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/usb/hcd-xhci-nec.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 7/9] hw/usb/hcd-xhci-nec: Replace container_of() by NEC_XHCI() QOM cast macro
  2023-02-20 15:05 ` [PATCH 7/9] hw/usb/hcd-xhci-nec: Replace container_of() by NEC_XHCI() QOM cast macro Philippe Mathieu-Daudé
@ 2023-02-20 19:13   ` Richard Henderson
  0 siblings, 0 replies; 17+ messages in thread
From: Richard Henderson @ 2023-02-20 19:13 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster

On 2/20/23 05:05, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/usb/hcd-xhci-nec.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 8/9] hw/usb/u2f: Declare QOM macros using OBJECT_DECLARE_TYPE()
  2023-02-20 15:05 ` [PATCH 8/9] hw/usb/u2f: Declare QOM macros using OBJECT_DECLARE_TYPE() Philippe Mathieu-Daudé
@ 2023-02-20 19:22   ` Richard Henderson
  0 siblings, 0 replies; 17+ messages in thread
From: Richard Henderson @ 2023-02-20 19:22 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Gerd Hoffmann, Markus Armbruster

On 2/20/23 05:05, Philippe Mathieu-Daudé wrote:
> hw/usb/u2f.h was added by commit 80e267f1d1 ("hw/usb: Add
> U2F key base class"), almost the same time of the automatic
> conversion done by commit c821774a3b ("Use OBJECT_DECLARE_TYPE
> where posible"). Manually convert to OBJECT_DECLARE_TYPE().
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/usb/u2f.h | 16 +++++-----------
>   1 file changed, 5 insertions(+), 11 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2023-02-20 19:23 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-20 15:05 [PATCH 0/9] hw/usb: Cleanups around QOM style Philippe Mathieu-Daudé
2023-02-20 15:05 ` [PATCH 1/9] hw/usb/dev-smartcard-reader: Avoid forward-declaring CCIDBus Philippe Mathieu-Daudé
2023-02-20 19:08   ` Richard Henderson
2023-02-20 15:05 ` [PATCH 2/9] hw/usb/hcd-ohci: Use OHCIState type definition Philippe Mathieu-Daudé
2023-02-20 19:09   ` Richard Henderson
2023-02-20 15:05 ` [PATCH 3/9] hw/usb/hcd-ohci-pci: Use QOM type-safe cast conversion macro Philippe Mathieu-Daudé
2023-02-20 15:05 ` [PATCH 4/9] hw/usb/hcd-uhci: Declare QOM macros using OBJECT_DECLARE_TYPE() Philippe Mathieu-Daudé
2023-02-20 19:11   ` Richard Henderson
2023-02-20 15:05 ` [PATCH 5/9] hw/usb/hcd-uhci: Replace container_of() by UHCI_GET_CLASS() QOM macro Philippe Mathieu-Daudé
2023-02-20 19:11   ` Richard Henderson
2023-02-20 15:05 ` [PATCH 6/9] hw/usb/hcd-xhci-nec: Declare QOM macros for NEC_XHCI Philippe Mathieu-Daudé
2023-02-20 19:12   ` Richard Henderson
2023-02-20 15:05 ` [PATCH 7/9] hw/usb/hcd-xhci-nec: Replace container_of() by NEC_XHCI() QOM cast macro Philippe Mathieu-Daudé
2023-02-20 19:13   ` Richard Henderson
2023-02-20 15:05 ` [PATCH 8/9] hw/usb/u2f: Declare QOM macros using OBJECT_DECLARE_TYPE() Philippe Mathieu-Daudé
2023-02-20 19:22   ` Richard Henderson
2023-02-20 15:05 ` [PATCH 9/9] hw/usb/u2f-passthru: Use QOM type-safe cast conversion macros Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.