All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: kvm@vger.kernel.org, Kirti Wankhede <kwankhede@nvidia.com>
Cc: "Raj, Ashok" <ashok.raj@intel.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Christoph Hellwig <hch@lst.de>,
	Leon Romanovsky <leonro@nvidia.com>,
	Max Gurtovoy <mgurtovoy@nvidia.com>,
	Tarun Gupta <targupta@nvidia.com>
Subject: [PATCH v2 14/18] vfio/mbochs: Use mdev_get_type_group_id()
Date: Tue,  6 Apr 2021 16:40:37 -0300	[thread overview]
Message-ID: <14-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> (raw)
In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com>

The mbochs_types array is parallel to the supported_type_groups array, so
the type_group_id indexes both. Instead of doing string searching just
directly index with type_group_id in all places.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 samples/vfio-mdev/mbochs.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c
index 365afbe2dea558..a1af30df10a2ee 100644
--- a/samples/vfio-mdev/mbochs.c
+++ b/samples/vfio-mdev/mbochs.c
@@ -205,16 +205,6 @@ static struct page *__mbochs_get_page(struct mdev_state *mdev_state,
 static struct page *mbochs_get_page(struct mdev_state *mdev_state,
 				    pgoff_t pgoff);
 
-static const struct mbochs_type *mbochs_find_type(struct kobject *kobj)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(mbochs_types); i++)
-		if (strcmp(mbochs_types[i].name, kobj->name) == 0)
-			return mbochs_types + i;
-	return NULL;
-}
-
 static void mbochs_create_config_space(struct mdev_state *mdev_state)
 {
 	STORE_LE16((u16 *) &mdev_state->vconfig[PCI_VENDOR_ID],
@@ -518,7 +508,8 @@ static int mbochs_reset(struct mdev_device *mdev)
 
 static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev)
 {
-	const struct mbochs_type *type = mbochs_find_type(kobj);
+	const struct mbochs_type *type =
+		&mbochs_types[mdev_get_type_group_id(mdev)];
 	struct device *dev = mdev_dev(mdev);
 	struct mdev_state *mdev_state;
 
@@ -544,7 +535,7 @@ static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev)
 		goto err_mem;
 
 	dev_info(dev, "%s: %s, %d MB, %ld pages\n", __func__,
-		 kobj->name, type->mbytes, mdev_state->pagecount);
+		 type->name, type->mbytes, mdev_state->pagecount);
 
 	mutex_init(&mdev_state->ops_lock);
 	mdev_state->mdev = mdev;
@@ -1349,7 +1340,8 @@ static MDEV_TYPE_ATTR_RO(name);
 static ssize_t
 description_show(struct kobject *kobj, struct device *dev, char *buf)
 {
-	const struct mbochs_type *type = mbochs_find_type(kobj);
+	const struct mbochs_type *type =
+		&mbochs_types[mtype_get_type_group_id(kobj)];
 
 	return sprintf(buf, "virtual display, %d MB video memory\n",
 		       type ? type->mbytes  : 0);
@@ -1359,7 +1351,8 @@ static MDEV_TYPE_ATTR_RO(description);
 static ssize_t
 available_instances_show(struct kobject *kobj, struct device *dev, char *buf)
 {
-	const struct mbochs_type *type = mbochs_find_type(kobj);
+	const struct mbochs_type *type =
+		&mbochs_types[mtype_get_type_group_id(kobj)];
 	int count = (max_mbytes - mbochs_used_mbytes) / type->mbytes;
 
 	return sprintf(buf, "%d\n", count);
-- 
2.31.1


  parent reply	other threads:[~2021-04-06 19:41 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06 19:40 [PATCH v2 00/18] Make vfio_mdev type safe Jason Gunthorpe
2021-04-06 19:40 ` [Intel-gfx] " Jason Gunthorpe
2021-04-06 19:40 ` Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 01/18] vfio/mdev: Fix missing static's on MDEV_TYPE_ATTR's Jason Gunthorpe
2021-04-07  5:09   ` Christoph Hellwig
2021-04-06 19:40 ` [PATCH v2 02/18] vfio/mdev: Do not allow a mdev_type to have a NULL parent pointer Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 03/18] vfio/mdev: Add missing typesafety around mdev_device Jason Gunthorpe
2021-04-07  5:16   ` Christoph Hellwig
2021-04-06 19:40 ` [PATCH v2 04/18] vfio/mdev: Simplify driver registration Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 05/18] vfio/mdev: Use struct mdev_type in struct mdev_device Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 06/18] vfio/mdev: Expose mdev_get/put_parent to mdev_private.h Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 07/18] vfio/mdev: Add missing reference counting to mdev_type Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 08/18] vfio/mdev: Reorganize mdev_device_create() Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 09/18] vfio/mdev: Add missing error handling to dev_set_name() Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 10/18] vfio/mdev: Remove duplicate storage of parent in mdev_device Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 11/18] vfio/mdev: Add mdev/mtype_get_type_group_id() Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 12/18] vfio/mtty: Use mdev_get_type_group_id() Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 13/18] vfio/mdpy: " Jason Gunthorpe
2021-04-06 19:40 ` Jason Gunthorpe [this message]
2021-04-06 19:40 ` [PATCH v2 15/18] vfio/gvt: Make DRM_I915_GVT depend on VFIO_MDEV Jason Gunthorpe
2021-04-06 19:40   ` [Intel-gfx] " Jason Gunthorpe
2021-04-12  7:27   ` Zhenyu Wang
2021-04-12  7:27     ` Zhenyu Wang
2021-04-06 19:40 ` [PATCH v2 16/18] vfio/gvt: Use mdev_get_type_group_id() Jason Gunthorpe
2021-04-06 19:40   ` [Intel-gfx] " Jason Gunthorpe
2021-04-12  7:30   ` Zhenyu Wang
2021-04-12  7:30     ` [Intel-gfx] " Zhenyu Wang
2021-04-06 19:40 ` [PATCH v2 17/18] vfio/mdev: Remove kobj from mdev_parent_ops->create() Jason Gunthorpe
2021-04-06 19:40   ` [Intel-gfx] " Jason Gunthorpe
2021-04-06 19:40   ` Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 18/18] vfio/mdev: Correct the function signatures for the mdev_type_attributes Jason Gunthorpe
2021-04-06 19:40   ` [Intel-gfx] " Jason Gunthorpe
2021-04-06 19:40   ` Jason Gunthorpe
2021-04-14 18:17 ` [PATCH v2 00/18] Make vfio_mdev type safe Alex Williamson
2021-04-14 18:17   ` [Intel-gfx] " Alex Williamson
2021-04-14 18:17   ` Alex Williamson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=14-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=ashok.raj@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=hch@lst.de \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=leonro@nvidia.com \
    --cc=mgurtovoy@nvidia.com \
    --cc=targupta@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.