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

Commit 845e30e6 authored by Ira Weiny's avatar Ira Weiny Committed by Greg Kroah-Hartman
Browse files

staging/rdma/hfi1: Return early from hfi1_ioctl parameter errors



Rather than have a switch in a large else clause make the parameter checks
return immediately.

Signed-off-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: default avatarIra Weiny <ira.weiny@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ae1724df
Loading
Loading
Loading
Loading
+173 −175
Original line number Diff line number Diff line
@@ -987,17 +987,15 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
	if (!dd)
		return -ENODEV;

	spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags);

	mode_flag = dd->hfi1_snoop.mode_flag;

	if (((_IOC_DIR(cmd) & _IOC_READ)
	    && !access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd)))
	    || ((_IOC_DIR(cmd) & _IOC_WRITE)
	    && !access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd)))) {
		ret = -EFAULT;
		return -EFAULT;
	} else if (!capable(CAP_SYS_ADMIN)) {
		ret = -EPERM;
		return -EPERM;
	} else if ((mode_flag & HFI1_PORT_CAPTURE_MODE) &&
		   (cmd != HFI1_SNOOP_IOCCLEARQUEUE) &&
		   (cmd != HFI1_SNOOP_IOCCLEARFILTER) &&
@@ -1008,8 +1006,11 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
		 * 3.Set capture filter
		 * Other are invalid.
		 */
		ret = -EINVAL;
	} else {
		return -EINVAL;
	}

	spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags);

	switch (cmd) {
	case HFI1_SNOOP_IOCSETLINKSTATE:
		snoop_dbg("HFI1_SNOOP_IOCSETLINKSTATE is not valid");
@@ -1121,8 +1122,7 @@ 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;
				if (copy_to_user(
					(struct hfi1_link_info __user *)arg,
			if (copy_to_user((struct hfi1_link_info __user *)arg,
					 &link_info, sizeof(link_info)))
				ret = -EFAULT;
		} else {
@@ -1168,7 +1168,6 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
		filter_value = kcalloc(filter_cmd.length, sizeof(u8),
				       GFP_KERNEL);
		if (!filter_value) {
				pr_alert("Not enough memory\n");
			ret = -ENOMEM;
			break;
		}
@@ -1210,7 +1209,6 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
		ret = -ENOTTY;
		break;
	}
	}
done:
	spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags);
	return ret;