From patchwork Mon Nov 16 22:32:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 7631281 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 5BC17BF90C for ; Mon, 16 Nov 2015 22:33:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 66BF2205B1 for ; Mon, 16 Nov 2015 22:33:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A02F205B6 for ; Mon, 16 Nov 2015 22:33:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752666AbbKPWdK (ORCPT ); Mon, 16 Nov 2015 17:33:10 -0500 Received: from mga03.intel.com ([134.134.136.65]:4086 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752828AbbKPWdJ (ORCPT ); Mon, 16 Nov 2015 17:33:09 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 16 Nov 2015 14:33:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,304,1444719600"; d="scan'208";a="840050751" Received: from phlsvsds.ph.intel.com ([10.228.195.38]) by fmsmga001.fm.intel.com with ESMTP; 16 Nov 2015 14:33:08 -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 tAGMX7Nx025242; Mon, 16 Nov 2015 17:33:07 -0500 Received: (from iweiny@localhost) by phlsvsds.ph.intel.com (8.13.8/8.13.8/Submit) id tAGMX7Rr025239; Mon, 16 Nov 2015 17:33:07 -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, mike.marciniszyn@intel.com, Dennis Dalessandro , Ira Weiny Subject: [PATCH v2 7/7] staging/rdma/hfi1: Return immediately on error Date: Mon, 16 Nov 2015 17:32:40 -0500 Message-Id: <1447713160-24858-8-git-send-email-ira.weiny@intel.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1447713160-24858-1-git-send-email-ira.weiny@intel.com> References: <1447713160-24858-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.7 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 --- Changes from V1: Squashed removal of goto which is safe after this patch staging/rdma/hfi1: remove unneeded goto done drivers/staging/rdma/hfi1/diag.c | 62 ++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/drivers/staging/rdma/hfi1/diag.c b/drivers/staging/rdma/hfi1/diag.c index a4dd4cbc2bea..7cc862062c5e 100644 --- a/drivers/staging/rdma/hfi1/diag.c +++ b/drivers/staging/rdma/hfi1/diag.c @@ -1011,20 +1011,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; @@ -1048,8 +1044,7 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) dev_state = HLS_DN_DISABLE; break; default: - ret = -EINVAL; - goto done; + return -EINVAL; } ret = set_link_state(ppd, dev_state); break; @@ -1064,8 +1059,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) @@ -1078,7 +1072,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); @@ -1086,16 +1080,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); @@ -1112,7 +1103,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); } @@ -1143,14 +1134,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", @@ -1159,17 +1148,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); @@ -1199,10 +1186,9 @@ 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; } -done: + return ret; }