Commit 9169cff1 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Alex Williamson
Browse files

vfio/mdev: Correct the function signatures for the mdev_type_attributes



The driver core standard is to pass in the properly typed object, the
properly typed attribute and the buffer data. It stems from the root
kobject method:

  ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,..)

Each subclass of kobject should provide their own function with the same
signature but more specific types, eg struct device uses:

  ssize_t (*show)(struct device *dev, struct device_attribute *attr,..)

In this case the existing signature is:

  ssize_t (*show)(struct kobject *kobj, struct device *dev,..)

Where kobj is a 'struct mdev_type *' and dev is 'mdev_type->parent->dev'.

Change the mdev_type related sysfs attribute functions to:

  ssize_t (*show)(struct mdev_type *mtype, struct mdev_type_attribute *attr,..)

In order to restore type safety and match the driver core standard

There are no current users of 'attr', but if it is ever needed it would be
hard to add in retroactively, so do it now.

Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Reviewed-by: default avatarCornelia Huck <cohuck@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Message-Id: <18-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com>
Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent c2ef2f50
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -54,14 +54,15 @@ intel_gvt_find_vgpu_type(struct intel_gvt *gvt, unsigned int type_group_id)
	return &gvt->types[type_group_id];
}

static ssize_t available_instances_show(struct kobject *kobj,
					struct device *dev, char *buf)
static ssize_t available_instances_show(struct mdev_type *mtype,
					struct mdev_type_attribute *attr,
					char *buf)
{
	struct intel_vgpu_type *type;
	unsigned int num = 0;
	void *gvt = kdev_to_i915(dev)->gvt;
	void *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt;

	type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(kobj));
	type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(mtype));
	if (!type)
		num = 0;
	else
@@ -70,19 +71,19 @@ static ssize_t available_instances_show(struct kobject *kobj,
	return sprintf(buf, "%u\n", num);
}

static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
		char *buf)
static ssize_t device_api_show(struct mdev_type *mtype,
			       struct mdev_type_attribute *attr, char *buf)
{
	return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING);
}

static ssize_t description_show(struct kobject *kobj, struct device *dev,
		char *buf)
static ssize_t description_show(struct mdev_type *mtype,
				struct mdev_type_attribute *attr, char *buf)
{
	struct intel_vgpu_type *type;
	void *gvt = kdev_to_i915(dev)->gvt;
	void *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt;

	type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(kobj));
	type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(mtype));
	if (!type)
		return 0;

+9 −6
Original line number Diff line number Diff line
@@ -71,23 +71,26 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb,
	return NOTIFY_DONE;
}

static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf)
static ssize_t name_show(struct mdev_type *mtype,
			 struct mdev_type_attribute *attr, char *buf)
{
	return sprintf(buf, "I/O subchannel (Non-QDIO)\n");
}
static MDEV_TYPE_ATTR_RO(name);

static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
			       char *buf)
static ssize_t device_api_show(struct mdev_type *mtype,
			       struct mdev_type_attribute *attr, char *buf)
{
	return sprintf(buf, "%s\n", VFIO_DEVICE_API_CCW_STRING);
}
static MDEV_TYPE_ATTR_RO(device_api);

static ssize_t available_instances_show(struct kobject *kobj,
					struct device *dev, char *buf)
static ssize_t available_instances_show(struct mdev_type *mtype,
					struct mdev_type_attribute *attr,
					char *buf)
{
	struct vfio_ccw_private *private = dev_get_drvdata(dev);
	struct vfio_ccw_private *private =
		dev_get_drvdata(mtype_get_parent_dev(mtype));

	return sprintf(buf, "%d\n", atomic_read(&private->avail));
}
+7 −5
Original line number Diff line number Diff line
@@ -366,15 +366,17 @@ static int vfio_ap_mdev_remove(struct mdev_device *mdev)
	return 0;
}

static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf)
static ssize_t name_show(struct mdev_type *mtype,
			 struct mdev_type_attribute *attr, char *buf)
{
	return sprintf(buf, "%s\n", VFIO_AP_MDEV_NAME_HWVIRT);
}

static MDEV_TYPE_ATTR_RO(name);

static ssize_t available_instances_show(struct kobject *kobj,
					struct device *dev, char *buf)
static ssize_t available_instances_show(struct mdev_type *mtype,
					struct mdev_type_attribute *attr,
					char *buf)
{
	return sprintf(buf, "%d\n",
		       atomic_read(&matrix_dev->available_instances));
@@ -382,8 +384,8 @@ static ssize_t available_instances_show(struct kobject *kobj,

static MDEV_TYPE_ATTR_RO(available_instances);

static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
			       char *buf)
static ssize_t device_api_show(struct mdev_type *mtype,
			       struct mdev_type_attribute *attr, char *buf)
{
	return sprintf(buf, "%s\n", VFIO_DEVICE_API_AP_STRING);
}
+12 −2
Original line number Diff line number Diff line
@@ -47,12 +47,22 @@ EXPORT_SYMBOL(mdev_get_type_group_id);
 * Used in mdev_type_attribute sysfs functions to return the index in the
 * supported_type_groups that the sysfs is called from.
 */
unsigned int mtype_get_type_group_id(struct kobject *mtype_kobj)
unsigned int mtype_get_type_group_id(struct mdev_type *mtype)
{
	return container_of(mtype_kobj, struct mdev_type, kobj)->type_group_id;
	return mtype->type_group_id;
}
EXPORT_SYMBOL(mtype_get_type_group_id);

/*
 * Used in mdev_type_attribute sysfs functions to return the parent struct
 * device
 */
struct device *mtype_get_parent_dev(struct mdev_type *mtype)
{
	return mtype->parent->dev;
}
EXPORT_SYMBOL(mtype_get_parent_dev);

/* Should be called holding parent_list_lock */
static struct mdev_parent *__find_parent_device(struct device *dev)
{
+6 −5
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ static ssize_t mdev_type_attr_show(struct kobject *kobj,
	ssize_t ret = -EIO;

	if (attr->show)
		ret = attr->show(kobj, type->parent->dev, buf);
		ret = attr->show(type, attr, buf);
	return ret;
}

@@ -39,7 +39,7 @@ static ssize_t mdev_type_attr_store(struct kobject *kobj,
	ssize_t ret = -EIO;

	if (attr->store)
		ret = attr->store(&type->kobj, type->parent->dev, buf, count);
		ret = attr->store(type, attr, buf, count);
	return ret;
}

@@ -48,8 +48,9 @@ static const struct sysfs_ops mdev_type_sysfs_ops = {
	.store = mdev_type_attr_store,
};

static ssize_t create_store(struct kobject *kobj, struct device *dev,
			    const char *buf, size_t count)
static ssize_t create_store(struct mdev_type *mtype,
			    struct mdev_type_attribute *attr, const char *buf,
			    size_t count)
{
	char *str;
	guid_t uuid;
@@ -67,7 +68,7 @@ static ssize_t create_store(struct kobject *kobj, struct device *dev,
	if (ret)
		return ret;

	ret = mdev_device_create(to_mdev_type(kobj), &uuid);
	ret = mdev_device_create(mtype, &uuid);
	if (ret)
		return ret;

Loading