From patchwork Wed Nov 11 05:43:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 7593771 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6AAF8BF90C for ; Wed, 11 Nov 2015 05:43:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7A1AB20561 for ; Wed, 11 Nov 2015 05:43:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 53EC920632 for ; Wed, 11 Nov 2015 05:43:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751386AbbKKFna (ORCPT ); Wed, 11 Nov 2015 00:43:30 -0500 Received: from mga03.intel.com ([134.134.136.65]:63907 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750999AbbKKFna (ORCPT ); Wed, 11 Nov 2015 00:43:30 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 10 Nov 2015 21:43:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,274,1444719600"; d="scan'208";a="816947478" Received: from phlsvsds.ph.intel.com ([10.228.195.38]) by orsmga001.jf.intel.com with ESMTP; 10 Nov 2015 21:43:30 -0800 Received: from phlsvsds.ph.intel.com (localhost.localdomain [127.0.0.1]) by phlsvsds.ph.intel.com (8.13.8/8.13.8) with ESMTP id tAB5hSTG009491; Wed, 11 Nov 2015 00:43:28 -0500 Received: (from iweiny@localhost) by phlsvsds.ph.intel.com (8.13.8/8.13.8/Submit) id tAB5hR4i009488; Wed, 11 Nov 2015 00:43:27 -0500 X-Authentication-Warning: phlsvsds.ph.intel.com: iweiny set sender to ira.weiny@intel.com using -f From: ira.weiny@intel.com To: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org Cc: dledford@redhat.com, linux-rdma@vger.kernel.org, dennis.dalessandro@intel.com, mike.marciniszyn@intel.com, Ira Weiny Subject: [PATCH 8/8] staging/rdma/hfi1: Return immediately on error Date: Wed, 11 Nov 2015 00:43:09 -0500 Message-Id: <1447220589-9067-9-git-send-email-ira.weiny@intel.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1447220589-9067-1-git-send-email-ira.weiny@intel.com> References: <1447220589-9067-1-git-send-email-ira.weiny@intel.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dennis Dalessandro Now that the spinlock is not taken throughout hfi1_ioctl it is safe to return early rather than setting a variable and falling through the switch. Reviewed-by: Mike Marciniszyn Signed-off-by: Dennis Dalessandro Signed-off-by: Ira Weiny --- drivers/staging/rdma/hfi1/diag.c | 59 ++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/drivers/staging/rdma/hfi1/diag.c b/drivers/staging/rdma/hfi1/diag.c index 34a8c4da71d2..0f01618cc5b7 100644 --- a/drivers/staging/rdma/hfi1/diag.c +++ b/drivers/staging/rdma/hfi1/diag.c @@ -1015,20 +1015,16 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) if (copy_from_user(&link_info, (struct hfi1_link_info __user *)arg, sizeof(link_info))) - ret = -EFAULT; + return -EFAULT; value = link_info.port_state; index = link_info.port_number; - if (index > dd->num_pports - 1) { - ret = -EINVAL; - break; - } + if (index > dd->num_pports - 1) + return -EINVAL; ppd = &dd->pport[index]; - if (!ppd) { - ret = -EINVAL; - break; - } + if (!ppd) + return -EINVAL; /* What we want to transition to */ phys_state = (value >> 4) & 0xF; @@ -1052,7 +1048,7 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) dev_state = HLS_DN_DISABLE; break; default: - ret = -EINVAL; + return -EINVAL; } ret = set_link_state(ppd, dev_state); break; @@ -1067,8 +1063,7 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) send_idle_sma(dd, SMA_IDLE_ACTIVE); break; default: - ret = -EINVAL; - break; + return -EINVAL; } if (ret) @@ -1081,7 +1076,7 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) if (copy_from_user(&link_info, (struct hfi1_link_info __user *)arg, sizeof(link_info))) - ret = -EFAULT; + return -EFAULT; index = link_info.port_number; } else { ret = __get_user(index, (int __user *)arg); @@ -1089,16 +1084,13 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) break; } - if (index > dd->num_pports - 1) { - ret = -EINVAL; - break; - } + if (index > dd->num_pports - 1) + return -EINVAL; ppd = &dd->pport[index]; - if (!ppd) { - ret = -EINVAL; - break; - } + if (!ppd) + return -EINVAL; + value = hfi1_ibphys_portstate(ppd); value <<= 4; value |= driver_lstate(ppd); @@ -1115,7 +1107,7 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) ppd->link_width_active; if (copy_to_user((struct hfi1_link_info __user *)arg, &link_info, sizeof(link_info))) - ret = -EFAULT; + return -EFAULT; } else { ret = __put_user(value, (int __user *)arg); } @@ -1146,14 +1138,12 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) /* just copy command structure */ argp = (unsigned long *)arg; if (copy_from_user(&filter_cmd, (void __user *)argp, - sizeof(filter_cmd))) { - ret = -EFAULT; - break; - } + sizeof(filter_cmd))) + return -EFAULT; + if (filter_cmd.opcode >= HFI1_MAX_FILTERS) { pr_alert("Invalid opcode in request\n"); - ret = -EINVAL; - break; + return -EINVAL; } snoop_dbg("Opcode %d Len %d Ptr %p", @@ -1162,17 +1152,15 @@ 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) { - ret = -ENOMEM; - break; - } + if (!filter_value) + return -ENOMEM; + /* copy remaining data from userspace */ if (copy_from_user((u8 *)filter_value, (void __user *)filter_cmd.value_ptr, filter_cmd.length)) { kfree(filter_value); - ret = -EFAULT; - break; + return -EFAULT; } /* Drain packets first */ spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); @@ -1202,8 +1190,7 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) snoop_flags |= SNOOP_USE_METADATA; break; default: - ret = -ENOTTY; - break; + return -ENOTTY; } return ret;