Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc847d5b authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull rdma fixes from Doug Ledford:
 "The new hfi1 driver in staging/rdma has had a number of fixup patches
  since being added to the tree.  This is the first batch of those fixes"

* tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma:
  IB/hfi: Properly set permissions for user device files
  IB/hfi1: mask vs shift confusion
  IB/hfi1: clean up some defines
  IB/hfi1: info leak in get_ctxt_info()
  IB/hfi1: fix a locking bug
  IB/hfi1: checking for NULL instead of IS_ERR
  IB/hfi1: fix sdma_descq_cnt parameter parsing
  IB/hfi1: fix copy_to/from_user() error handling
  IB/hfi1: fix pstateinfo from returning improperly byteswapped value
parents 2673ee56 e116a64f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2710,7 +2710,7 @@ int acquire_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
	if (sleep_ok) {
		mutex_lock(&ppd->hls_lock);
	} else {
		while (mutex_trylock(&ppd->hls_lock) == EBUSY)
		while (!mutex_trylock(&ppd->hls_lock))
			udelay(1);
	}

@@ -2758,7 +2758,7 @@ int release_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
	if (sleep_ok) {
		mutex_lock(&dd->pport->hls_lock);
	} else {
		while (mutex_trylock(&dd->pport->hls_lock) == EBUSY)
		while (!mutex_trylock(&dd->pport->hls_lock))
			udelay(1);
	}

+48 −6
Original line number Diff line number Diff line
@@ -57,11 +57,13 @@
#include "device.h"

static struct class *class;
static struct class *user_class;
static dev_t hfi1_dev;

int hfi1_cdev_init(int minor, const char *name,
		   const struct file_operations *fops,
		   struct cdev *cdev, struct device **devp)
		   struct cdev *cdev, struct device **devp,
		   bool user_accessible)
{
	const dev_t dev = MKDEV(MAJOR(hfi1_dev), minor);
	struct device *device = NULL;
@@ -78,7 +80,11 @@ int hfi1_cdev_init(int minor, const char *name,
		goto done;
	}

	if (user_accessible)
		device = device_create(user_class, NULL, dev, NULL, "%s", name);
	else
		device = device_create(class, NULL, dev, NULL, "%s", name);

	if (!IS_ERR(device))
		goto done;
	ret = PTR_ERR(device);
@@ -110,6 +116,26 @@ const char *class_name(void)
	return hfi1_class_name;
}

static char *hfi1_devnode(struct device *dev, umode_t *mode)
{
	if (mode)
		*mode = 0600;
	return kasprintf(GFP_KERNEL, "%s", dev_name(dev));
}

static const char *hfi1_class_name_user = "hfi1_user";
const char *class_name_user(void)
{
	return hfi1_class_name_user;
}

static char *hfi1_user_devnode(struct device *dev, umode_t *mode)
{
	if (mode)
		*mode = 0666;
	return kasprintf(GFP_KERNEL, "%s", dev_name(dev));
}

int __init dev_init(void)
{
	int ret;
@@ -125,7 +151,22 @@ int __init dev_init(void)
		ret = PTR_ERR(class);
		pr_err("Could not create device class (err %d)\n", -ret);
		unregister_chrdev_region(hfi1_dev, HFI1_NMINORS);
		goto done;
	}
	class->devnode = hfi1_devnode;

	user_class = class_create(THIS_MODULE, class_name_user());
	if (IS_ERR(user_class)) {
		ret = PTR_ERR(user_class);
		pr_err("Could not create device class for user accessible files (err %d)\n",
		       -ret);
		class_destroy(class);
		class = NULL;
		user_class = NULL;
		unregister_chrdev_region(hfi1_dev, HFI1_NMINORS);
		goto done;
	}
	user_class->devnode = hfi1_user_devnode;

done:
	return ret;
@@ -133,10 +174,11 @@ int __init dev_init(void)

void dev_cleanup(void)
{
	if (class) {
	class_destroy(class);
	class = NULL;
	}

	class_destroy(user_class);
	user_class = NULL;

	unregister_chrdev_region(hfi1_dev, HFI1_NMINORS);
}
+2 −1
Original line number Diff line number Diff line
@@ -52,7 +52,8 @@

int hfi1_cdev_init(int minor, const char *name,
		   const struct file_operations *fops,
		   struct cdev *cdev, struct device **devp);
		   struct cdev *cdev, struct device **devp,
		   bool user_accessible);
void hfi1_cdev_cleanup(struct cdev *cdev, struct device **devp);
const char *class_name(void);
int __init dev_init(void);
+18 −18
Original line number Diff line number Diff line
@@ -292,7 +292,7 @@ int hfi1_diag_add(struct hfi1_devdata *dd)
	if (atomic_inc_return(&diagpkt_count) == 1) {
		ret = hfi1_cdev_init(HFI1_DIAGPKT_MINOR, name,
				     &diagpkt_file_ops, &diagpkt_cdev,
				     &diagpkt_device);
				     &diagpkt_device, false);
	}

	return ret;
@@ -592,7 +592,8 @@ static int hfi1_snoop_add(struct hfi1_devdata *dd, const char *name)

	ret = hfi1_cdev_init(HFI1_SNOOP_CAPTURE_BASE + dd->unit, name,
			     &snoop_file_ops,
			     &dd->hfi1_snoop.cdev, &dd->hfi1_snoop.class_dev);
			     &dd->hfi1_snoop.cdev, &dd->hfi1_snoop.class_dev,
			     false);

	if (ret) {
		dd_dev_err(dd, "Couldn't create %s device: %d", name, ret);
@@ -1012,11 +1013,10 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
		case HFI1_SNOOP_IOCSETLINKSTATE_EXTRA:
			memset(&link_info, 0, sizeof(link_info));

			ret = copy_from_user(&link_info,
			if (copy_from_user(&link_info,
				(struct hfi1_link_info __user *)arg,
				sizeof(link_info));
			if (ret)
				break;
				sizeof(link_info)))
				ret = -EFAULT;

			value = link_info.port_state;
			index = link_info.port_number;
@@ -1080,9 +1080,10 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
		case HFI1_SNOOP_IOCGETLINKSTATE_EXTRA:
			if (cmd == HFI1_SNOOP_IOCGETLINKSTATE_EXTRA) {
				memset(&link_info, 0, sizeof(link_info));
				ret = copy_from_user(&link_info,
				if (copy_from_user(&link_info,
					(struct hfi1_link_info __user *)arg,
					sizeof(link_info));
					sizeof(link_info)))
					ret = -EFAULT;
				index = link_info.port_number;
			} else {
				ret = __get_user(index, (int __user *) arg);
@@ -1114,9 +1115,10 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
							ppd->link_speed_active;
				link_info.link_width_active =
							ppd->link_width_active;
				ret = copy_to_user(
				if (copy_to_user(
					(struct hfi1_link_info __user *)arg,
					&link_info, sizeof(link_info));
					&link_info, sizeof(link_info)))
					ret = -EFAULT;
			} else {
				ret = __put_user(value, (int __user *)arg);
			}
@@ -1142,10 +1144,9 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
			snoop_dbg("Setting filter");
			/* just copy command structure */
			argp = (unsigned long *)arg;
			ret = copy_from_user(&filter_cmd, (void __user *)argp,
					     sizeof(filter_cmd));
			if (ret < 0) {
				pr_alert("Error copying filter command\n");
			if (copy_from_user(&filter_cmd, (void __user *)argp,
					     sizeof(filter_cmd))) {
				ret = -EFAULT;
				break;
			}
			if (filter_cmd.opcode >= HFI1_MAX_FILTERS) {
@@ -1167,12 +1168,11 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
				break;
			}
			/* copy remaining data from userspace */
			ret = copy_from_user((u8 *)filter_value,
			if (copy_from_user((u8 *)filter_value,
					(void __user *)filter_cmd.value_ptr,
					filter_cmd.length);
			if (ret < 0) {
					filter_cmd.length)) {
				kfree(filter_value);
				pr_alert("Error copying filter data\n");
				ret = -EFAULT;
				break;
			}
			/* Drain packets first */
+7 −3
Original line number Diff line number Diff line
@@ -1181,6 +1181,7 @@ static int get_ctxt_info(struct file *fp, void __user *ubase, __u32 len)
	struct hfi1_filedata *fd = fp->private_data;
	int ret = 0;

	memset(&cinfo, 0, sizeof(cinfo));
	ret = hfi1_get_base_kinfo(uctxt, &cinfo);
	if (ret < 0)
		goto done;
@@ -2089,14 +2090,16 @@ static int user_add(struct hfi1_devdata *dd)

	if (atomic_inc_return(&user_count) == 1) {
		ret = hfi1_cdev_init(0, class_name(), &hfi1_file_ops,
				     &wildcard_cdev, &wildcard_device);
				     &wildcard_cdev, &wildcard_device,
				     true);
		if (ret)
			goto done;
	}

	snprintf(name, sizeof(name), "%s_%d", class_name(), dd->unit);
	ret = hfi1_cdev_init(dd->unit + 1, name, &hfi1_file_ops,
			     &dd->user_cdev, &dd->user_device);
			     &dd->user_cdev, &dd->user_device,
			     true);
	if (ret)
		goto done;

@@ -2104,7 +2107,8 @@ static int user_add(struct hfi1_devdata *dd)
		snprintf(name, sizeof(name),
			 "%s_ui%d", class_name(), dd->unit);
		ret = hfi1_cdev_init(dd->unit + UI_OFFSET, name, &ui_file_ops,
				     &dd->ui_cdev, &dd->ui_device);
				     &dd->ui_cdev, &dd->ui_device,
				     false);
		if (ret)
			goto done;
	}
Loading