mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 05:02:12 +00:00
vfio/mtty: Use mdev_get_type_group_id()
The type_group_id directly gives the single or dual port index, no need for string searching. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Message-Id: <12-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
parent
15fcc44be0
commit
c594b26ff7
@ -711,23 +711,7 @@ accessfailed:
|
||||
static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
|
||||
{
|
||||
struct mdev_state *mdev_state;
|
||||
char name[MTTY_STRING_LEN];
|
||||
int nr_ports = 0, i;
|
||||
|
||||
if (!mdev)
|
||||
return -EINVAL;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
snprintf(name, MTTY_STRING_LEN, "%s-%d",
|
||||
dev_driver_string(mdev_parent_dev(mdev)), i + 1);
|
||||
if (!strcmp(kobj->name, name)) {
|
||||
nr_ports = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!nr_ports)
|
||||
return -EINVAL;
|
||||
int nr_ports = mdev_get_type_group_id(mdev) + 1;
|
||||
|
||||
mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL);
|
||||
if (mdev_state == NULL)
|
||||
@ -1311,18 +1295,11 @@ static const struct attribute_group *mdev_dev_groups[] = {
|
||||
static ssize_t
|
||||
name_show(struct kobject *kobj, struct device *dev, char *buf)
|
||||
{
|
||||
char name[MTTY_STRING_LEN];
|
||||
int i;
|
||||
const char *name_str[2] = {"Single port serial", "Dual port serial"};
|
||||
static const char *name_str[2] = { "Single port serial",
|
||||
"Dual port serial" };
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
snprintf(name, MTTY_STRING_LEN, "%s-%d",
|
||||
dev_driver_string(dev), i + 1);
|
||||
if (!strcmp(kobj->name, name))
|
||||
return sprintf(buf, "%s\n", name_str[i]);
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
return sysfs_emit(buf, "%s\n",
|
||||
name_str[mtype_get_type_group_id(kobj)]);
|
||||
}
|
||||
|
||||
static MDEV_TYPE_ATTR_RO(name);
|
||||
@ -1330,22 +1307,9 @@ static MDEV_TYPE_ATTR_RO(name);
|
||||
static ssize_t
|
||||
available_instances_show(struct kobject *kobj, struct device *dev, char *buf)
|
||||
{
|
||||
char name[MTTY_STRING_LEN];
|
||||
int i;
|
||||
struct mdev_state *mds;
|
||||
int ports = 0, used = 0;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
snprintf(name, MTTY_STRING_LEN, "%s-%d",
|
||||
dev_driver_string(dev), i + 1);
|
||||
if (!strcmp(kobj->name, name)) {
|
||||
ports = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ports)
|
||||
return -EINVAL;
|
||||
unsigned int ports = mtype_get_type_group_id(kobj) + 1;
|
||||
int used = 0;
|
||||
|
||||
list_for_each_entry(mds, &mdev_devices_list, next)
|
||||
used += mds->nr_ports;
|
||||
|
Loading…
Reference in New Issue
Block a user