forked from Minki/linux
vfio/mbochs: Use mdev_get_type_group_id()
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> Message-Id: <14-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
parent
adc9d1f6f5
commit
3d3a360e57
@ -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,
|
static struct page *mbochs_get_page(struct mdev_state *mdev_state,
|
||||||
pgoff_t pgoff);
|
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)
|
static void mbochs_create_config_space(struct mdev_state *mdev_state)
|
||||||
{
|
{
|
||||||
STORE_LE16((u16 *) &mdev_state->vconfig[PCI_VENDOR_ID],
|
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)
|
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 device *dev = mdev_dev(mdev);
|
||||||
struct mdev_state *mdev_state;
|
struct mdev_state *mdev_state;
|
||||||
|
|
||||||
@ -544,7 +535,7 @@ static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev)
|
|||||||
goto err_mem;
|
goto err_mem;
|
||||||
|
|
||||||
dev_info(dev, "%s: %s, %d MB, %ld pages\n", __func__,
|
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);
|
mutex_init(&mdev_state->ops_lock);
|
||||||
mdev_state->mdev = mdev;
|
mdev_state->mdev = mdev;
|
||||||
@ -1349,7 +1340,8 @@ static MDEV_TYPE_ATTR_RO(name);
|
|||||||
static ssize_t
|
static ssize_t
|
||||||
description_show(struct kobject *kobj, struct device *dev, char *buf)
|
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",
|
return sprintf(buf, "virtual display, %d MB video memory\n",
|
||||||
type ? type->mbytes : 0);
|
type ? type->mbytes : 0);
|
||||||
@ -1359,7 +1351,8 @@ static MDEV_TYPE_ATTR_RO(description);
|
|||||||
static ssize_t
|
static ssize_t
|
||||||
available_instances_show(struct kobject *kobj, struct device *dev, char *buf)
|
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;
|
int count = (max_mbytes - mbochs_used_mbytes) / type->mbytes;
|
||||||
|
|
||||||
return sprintf(buf, "%d\n", count);
|
return sprintf(buf, "%d\n", count);
|
||||||
|
Loading…
Reference in New Issue
Block a user