Re: [PATCH v7 10/22] s390: vfio-ap: sysfs interfaces to configure adapters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 26 Jul 2018 21:54:17 +0200
Christian Borntraeger <borntraeger@xxxxxxxxxx> wrote:

> +/**
> + * assign_adapter_store
> + *
> + * @dev: the matrix device
> + * @attr: a mediated matrix device attribute
> + * @buf: a buffer containing the adapter ID (APID) to be assigned
> + * @count: the number of bytes in @buf
> + *
> + * Parses the APID from @buf and assigns it to the mediated matrix device.
> + *
> + * Returns the number of bytes processed if the APID is valid; otherwise returns
> + * an error.
> + */
> +static ssize_t assign_adapter_store(struct device *dev,
> +				    struct device_attribute *attr,
> +				    const char *buf, size_t count)
> +{
> +	int ret;
> +	unsigned long apid;
> +	struct mdev_device *mdev = mdev_from_dev(dev);
> +	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> +	unsigned long max_apid = matrix_mdev->matrix.apm_max;
> +
> +	ret = kstrtoul(buf, 0, &apid);
> +	if (ret || (apid > max_apid)) {
> +		pr_warn("%s: %s: adapter id '%s' not a value from 0 to %02lu(%#04lx)\n",
> +		       VFIO_AP_MODULE_NAME, __func__, buf, max_apid, max_apid);

I'm not sure how helpful a message to the syslog is if you are writing
to sysfs attributes. If you decide to drop the message, you could do

if (apid > max_apid)
	ret = -EINVAL;

if (ret)
	return ret;

which looks more straightforward to me.

> +
> +		if (!ret)
> +			ret = -EINVAL;
> +
> +		return ret;
> +	}
> +
> +	/* Set the bit in the AP mask (APM) corresponding to the AP adapter
> +	 * number (APID). The bits in the mask, from most significant to least
> +	 * significant bit, correspond to APIDs 0-255.
> +	 */
> +	mutex_lock(&matrix_dev.lock);
> +	set_bit_inv(apid, matrix_mdev->matrix.apm);
> +	ret = count;
> +
> +	mutex_unlock(&matrix_dev.lock);
> +
> +	return ret;
> +}
> +static DEVICE_ATTR_WO(assign_adapter);
> +
> +/**
> + * unassign_adapter_store
> + *
> + * @dev: the matrix device
> + * @attr: a mediated matrix device attribute
> + * @buf: a buffer containing the adapter ID (APID) to be assigned
> + * @count: the number of bytes in @buf
> + *
> + * Parses the APID from @buf and unassigns it from the mediated matrix device.
> + * The APID must be a valid value
> + *
> + * Returns the number of bytes processed if the APID is valid; otherwise returns
> + * an error.
> + */
> +static ssize_t unassign_adapter_store(struct device *dev,
> +				      struct device_attribute *attr,
> +				      const char *buf, size_t count)
> +{
> +	int ret;
> +	unsigned long apid;
> +	struct mdev_device *mdev = mdev_from_dev(dev);
> +	struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> +
> +	unsigned long max_apid = matrix_mdev->matrix.apm_max;
> +
> +	ret = kstrtoul(buf, 0, &apid);
> +	if (ret || (apid > max_apid)) {
> +		pr_warn("%s: %s: adapter id '%s' must be a value from 0 to %02lu(%#04lx)\n",
> +		       VFIO_AP_MODULE_NAME, __func__, buf, max_apid, max_apid);

dito

> +
> +		if (!ret)
> +			ret = -EINVAL;
> +
> +		return ret;
> +	}
> +
> +	mutex_lock(&matrix_dev.lock);
> +	if (!test_bit_inv(apid, matrix_mdev->matrix.apm)) {
> +		pr_warn("%s: %s: adapter id %02lu(%#04lx) not assigned\n",
> +		       VFIO_AP_MODULE_NAME, __func__, apid, apid);
> +		ret = -ENODEV;

Any reason why this needs to be an error? Setting a bit that was set
before is not an error, either.

> +		goto done;
> +	}
> +
> +	clear_bit_inv((unsigned long)apid, matrix_mdev->matrix.apm);
> +	ret = count;
> +
> +done:
> +	mutex_unlock(&matrix_dev.lock);
> +
> +	return ret;
> +}
> +DEVICE_ATTR_WO(unassign_adapter);
--
To unsubscribe from this list: send the line "unsubscribe linux-s390" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Kernel Development]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Info]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Linux Media]     [Device Mapper]

  Powered by Linux