From patchwork Thu Jan 7 12:20:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Khapyorsky X-Patchwork-Id: 71578 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o07CFrBW029482 for ; Thu, 7 Jan 2010 12:17:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752518Ab0AGMQ7 (ORCPT ); Thu, 7 Jan 2010 07:16:59 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752543Ab0AGMQ7 (ORCPT ); Thu, 7 Jan 2010 07:16:59 -0500 Received: from mail-fx0-f225.google.com ([209.85.220.225]:39732 "EHLO mail-fx0-f225.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752518Ab0AGMQ6 (ORCPT ); Thu, 7 Jan 2010 07:16:58 -0500 Received: by fxm25 with SMTP id 25so11581480fxm.21 for ; Thu, 07 Jan 2010 04:16:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:received:date:from:to :subject:message-id:mime-version:content-type:content-disposition :user-agent; bh=4KWakKlhh8LcH32ELcYExWPpHHRtNCuendBTZrflYB4=; b=rg/1yAm7fpDJFTEzstqt8XTAIjaKluAv13kG94PaB7TfqpCfkZf/+DbDCTJcD+8B0q tEx40aqcQSEIGTAOH4oylUG7Ny8Q3NA1y2Olc2HTPHnoWcpTGCPWtfW5U9aUqAjBtYoH PdtXqhHmUSBDBpuBfVLH8LEBmJKN868CZ8w/g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=vqTbE6buFnu+GsL6SogrlWIMoD0jUORwDvnvWhoGs/bmz4ThPxvxPZ0LDdZ/shDN44 XadsZkD/dRSwK4D9Ewb9PMfsp/jS7+MNt5Fx73azjlnbY/2gdW0Bse5TD6XhsM2qlHdA 0zHUkDddAypxkfQadu04ajCm+NGuqMh3bF6+s= Received: by 10.102.217.14 with SMTP id p14mr2382999mug.116.1262866616581; Thu, 07 Jan 2010 04:16:56 -0800 (PST) Received: from me.localdomain (85.64.35.106.dynamic.barak-online.net [85.64.35.106]) by mx.google.com with ESMTPS id 14sm29707244muo.34.2010.01.07.04.16.55 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 07 Jan 2010 04:16:55 -0800 (PST) Received: by me.localdomain (Postfix, from userid 1000) id 735D011DF8; Thu, 7 Jan 2010 14:20:09 +0200 (IST) Date: Thu, 7 Jan 2010 14:20:09 +0200 From: Sasha Khapyorsky To: linux-rdma Subject: [PATCH] opensm/osm_sa_infrominfo.c: fixes and simplifications in lid range check Message-ID: <20100107122009.GB26089@me> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org diff --git a/opensm/opensm/osm_sa_informinfo.c b/opensm/opensm/osm_sa_informinfo.c index c1ab481..9fb3608 100644 --- a/opensm/opensm/osm_sa_informinfo.c +++ b/opensm/opensm/osm_sa_informinfo.c @@ -91,7 +91,6 @@ static boolean_t validate_ports_access_rights(IN osm_sa_t * sa, osm_port_t *p_port; ib_net64_t portguid; uint16_t lid_range_begin, lid_range_end, lid; - const cl_ptr_vector_t *p_tbl; OSM_LOG_ENTER(sa->p_log); @@ -124,6 +123,8 @@ static boolean_t validate_ports_access_rights(IN osm_sa_t * sa, goto Exit; } } else { + size_t lids_size; + /* gid is zero - check if LID range is defined */ lid_range_begin = cl_ntoh16(p_infr_rec->inform_record.inform_info. @@ -136,25 +137,28 @@ static boolean_t validate_ports_access_rights(IN osm_sa_t * sa, cl_ntoh16(p_infr_rec->inform_record.inform_info. lid_range_end); + lids_size = cl_ptr_vector_get_size(&sa->p_subn->port_lid_tbl); + /* lid_range_end is set to zero if no range desired. In this case - just make it equal to the lid_range_begin. */ if (lid_range_end == 0) lid_range_end = lid_range_begin; + else if (lid_range_end >= lids_size) + lid_range_end = lids_size - 1; + + if (lid_range_begin >= lids_size) { + /* requested lids are out of range */ + OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4302: " + "Given LIDs (%u-%u) are out of range (%zu)\n", + lid_range_begin, lid_range_end, lids_size); + valid = FALSE; + goto Exit; + } /* go over all defined lids within the range and make sure that the requester port can access them according to current partitioning. */ for (lid = lid_range_begin; lid <= lid_range_end; lid++) { - p_tbl = &sa->p_subn->port_lid_tbl; - if (cl_ptr_vector_get_size(p_tbl) > lid) - p_port = cl_ptr_vector_get(p_tbl, lid); - else { - /* lid requested is out of range */ - OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 4302: " - "Given LID (%u) is out of range:%u\n", - lid, cl_ptr_vector_get_size(p_tbl)); - valid = FALSE; - goto Exit; - } + p_port = osm_get_port_by_lid(sa->p_subn, cl_hton16(lid)); if (p_port == NULL) continue;