[PATCH] virtio_pci: use container_of replace type conversion

Subsystems: the rest, virtio core

STALE1455d

2 messages, 2 authors, 2022-08-19 · open the first message on its own page

[PATCH] virtio_pci: use container_of replace type conversion

From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Date: 2022-08-16 03:06:10

Replace type conversion with container_of() in
vp_modern_set_queue_reset()/vp_modern_get_queue_reset() .
Also combine declarations and assignments.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
 drivers/virtio/virtio_pci_modern_dev.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c
index 869cb46bef96..530c954439de 100644
--- a/drivers/virtio/virtio_pci_modern_dev.c
+++ b/drivers/virtio/virtio_pci_modern_dev.c
@@ -482,12 +482,12 @@ EXPORT_SYMBOL_GPL(vp_modern_set_status);
  */
 int vp_modern_get_queue_reset(struct virtio_pci_modern_device *mdev, u16 index)
 {
-	struct virtio_pci_modern_common_cfg __iomem *cfg;
-
-	cfg = (struct virtio_pci_modern_common_cfg __iomem *)mdev->common;
+	struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
+	struct virtio_pci_modern_common_cfg __iomem *mcfg =
+		container_of(cfg, struct virtio_pci_modern_common_cfg, cfg);
 
-	vp_iowrite16(index, &cfg->cfg.queue_select);
-	return vp_ioread16(&cfg->queue_reset);
+	vp_iowrite16(index, &cfg->queue_select);
+	return vp_ioread16(&mcfg->queue_reset);
 }
 EXPORT_SYMBOL_GPL(vp_modern_get_queue_reset);
 
@@ -498,17 +498,17 @@ EXPORT_SYMBOL_GPL(vp_modern_get_queue_reset);
  */
 void vp_modern_set_queue_reset(struct virtio_pci_modern_device *mdev, u16 index)
 {
-	struct virtio_pci_modern_common_cfg __iomem *cfg;
-
-	cfg = (struct virtio_pci_modern_common_cfg __iomem *)mdev->common;
+	struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
+	struct virtio_pci_modern_common_cfg __iomem *mcfg =
+		container_of(cfg, struct virtio_pci_modern_common_cfg, cfg);
 
-	vp_iowrite16(index, &cfg->cfg.queue_select);
-	vp_iowrite16(1, &cfg->queue_reset);
+	vp_iowrite16(index, &cfg->queue_select);
+	vp_iowrite16(1, &mcfg->queue_reset);
 
-	while (vp_ioread16(&cfg->queue_reset))
+	while (vp_ioread16(&mcfg->queue_reset))
 		msleep(1);
 
-	while (vp_ioread16(&cfg->cfg.queue_enable))
+	while (vp_ioread16(&cfg->queue_enable))
 		msleep(1);
 }
 EXPORT_SYMBOL_GPL(vp_modern_set_queue_reset);
-- 
2.31.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH] virtio_pci: use container_of replace type conversion

From: Jason Wang <hidden>
Date: 2022-08-19 06:30:31

On Tue, Aug 16, 2022 at 11:06 AM Xuan Zhuo [off-list ref] wrote:
Replace type conversion with container_of() in
vp_modern_set_queue_reset()/vp_modern_get_queue_reset() .
Also combine declarations and assignments.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Jason Wang <redacted>
quoted hunk
---
 drivers/virtio/virtio_pci_modern_dev.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c
index 869cb46bef96..530c954439de 100644
--- a/drivers/virtio/virtio_pci_modern_dev.c
+++ b/drivers/virtio/virtio_pci_modern_dev.c
@@ -482,12 +482,12 @@ EXPORT_SYMBOL_GPL(vp_modern_set_status);
  */
 int vp_modern_get_queue_reset(struct virtio_pci_modern_device *mdev, u16 index)
 {
-       struct virtio_pci_modern_common_cfg __iomem *cfg;
-
-       cfg = (struct virtio_pci_modern_common_cfg __iomem *)mdev->common;
+       struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
+       struct virtio_pci_modern_common_cfg __iomem *mcfg =
+               container_of(cfg, struct virtio_pci_modern_common_cfg, cfg);

-       vp_iowrite16(index, &cfg->cfg.queue_select);
-       return vp_ioread16(&cfg->queue_reset);
+       vp_iowrite16(index, &cfg->queue_select);
+       return vp_ioread16(&mcfg->queue_reset);
 }
 EXPORT_SYMBOL_GPL(vp_modern_get_queue_reset);
@@ -498,17 +498,17 @@ EXPORT_SYMBOL_GPL(vp_modern_get_queue_reset);
  */
 void vp_modern_set_queue_reset(struct virtio_pci_modern_device *mdev, u16 index)
 {
-       struct virtio_pci_modern_common_cfg __iomem *cfg;
-
-       cfg = (struct virtio_pci_modern_common_cfg __iomem *)mdev->common;
+       struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
+       struct virtio_pci_modern_common_cfg __iomem *mcfg =
+               container_of(cfg, struct virtio_pci_modern_common_cfg, cfg);

-       vp_iowrite16(index, &cfg->cfg.queue_select);
-       vp_iowrite16(1, &cfg->queue_reset);
+       vp_iowrite16(index, &cfg->queue_select);
+       vp_iowrite16(1, &mcfg->queue_reset);

-       while (vp_ioread16(&cfg->queue_reset))
+       while (vp_ioread16(&mcfg->queue_reset))
                msleep(1);

-       while (vp_ioread16(&cfg->cfg.queue_enable))
+       while (vp_ioread16(&cfg->queue_enable))
                msleep(1);
 }
 EXPORT_SYMBOL_GPL(vp_modern_set_queue_reset);
--
2.31.0
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help