From patchwork Tue Sep 7 15:16:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yevgeny Kliteynik X-Patchwork-Id: 161261 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o87FGwnu002890 for ; Tue, 7 Sep 2010 15:16:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757314Ab0IGPQ5 (ORCPT ); Tue, 7 Sep 2010 11:16:57 -0400 Received: from mail.mellanox.co.il ([194.90.237.43]:56183 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757059Ab0IGPQ5 (ORCPT ); Tue, 7 Sep 2010 11:16:57 -0400 Received: from Internal Mail-Server by MTLPINE2 (envelope-from kliteyn@mellanox.co.il) with SMTP; 7 Sep 2010 18:16:16 +0300 Received: from [10.4.1.29] (10.4.1.29) by mtlmail01.mtl.com (10.0.8.12) with Microsoft SMTP Server id 8.2.254.0; Tue, 7 Sep 2010 18:16:54 +0300 Message-ID: <4C86575C.8010607@mellanox.co.il> Date: Tue, 7 Sep 2010 18:16:44 +0300 From: Yevgeny Kliteynik Reply-To: kliteyn@dev.mellanox.co.il User-Agent: Thunderbird 1.5.0.5 (X11/20060719) MIME-Version: 1.0 To: Sasha Khapyorsky , Linux RDMA Subject: [PATCH] opensm/osm_ucast_file.c: closing file descriptor in error path Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 07 Sep 2010 15:16:58 +0000 (UTC) diff --git a/opensm/opensm/osm_ucast_file.c b/opensm/opensm/osm_ucast_file.c index 8cb3cb6..fef77a2 100644 --- a/opensm/opensm/osm_ucast_file.c +++ b/opensm/opensm/osm_ucast_file.c @@ -130,6 +130,7 @@ static int do_ucast_file_load(void *context) uint16_t lid; uint8_t port_num; unsigned lineno; + int status = -1; file_name = p_osm->subn.opt.lfts_file; if (!file_name) { @@ -143,7 +144,7 @@ static int do_ucast_file_load(void *context) if (!file) { OSM_LOG(&p_osm->log, OSM_LOG_ERROR | OSM_LOG_SYS, "ERR 6302: " "Can't open ucast dump file \'%s\': %m\n", file_name); - return -1; + goto Exit; } lineno = 0; @@ -173,7 +174,7 @@ static int do_ucast_file_load(void *context) "PARSE ERROR: %s:%u: " "cannot parse switch definition\n", file_name, lineno); - return -1; + goto Exit; } p = q + 8; sw_guid = strtoull(p, &q, 16); @@ -182,7 +183,7 @@ static int do_ucast_file_load(void *context) "PARSE ERROR: %s:%u: " "cannot parse switch guid: \'%s\'\n", file_name, lineno, p); - return -1; + goto Exit; } sw_guid = cl_hton64(sw_guid); @@ -202,7 +203,7 @@ static int do_ucast_file_load(void *context) "PARSE ERROR: %s:%u: " "cannot parse lid: \'%s\'\n", file_name, lineno, p); - return -1; + goto Exit; } p = q; while (isspace(*p)) @@ -213,7 +214,7 @@ static int do_ucast_file_load(void *context) "PARSE ERROR: %s:%u: " "cannot parse port: \'%s\'\n", file_name, lineno, p); - return -1; + goto Exit; } p = q; /* additionally try to extract guid */ @@ -241,9 +242,11 @@ static int do_ucast_file_load(void *context) add_path(p_osm, p_sw, lid, port_num, port_guid); } } - - fclose(file); - return 0; + status = 0; +Exit: + if (file) + fclose(file); + return status; } static int do_lid_matrix_file_load(void *context) @@ -257,6 +260,7 @@ static int do_lid_matrix_file_load(void *context) osm_switch_t *p_sw; unsigned lineno; uint16_t lid; + int status = -1; file_name = p_osm->subn.opt.lid_matrix_dump_file; if (!file_name) { @@ -270,7 +274,7 @@ static int do_lid_matrix_file_load(void *context) if (!file) { OSM_LOG(&p_osm->log, OSM_LOG_ERROR | OSM_LOG_SYS, "ERR 6305: " "Can't open lid matrix file \'%s\': %m\n", file_name); - return -1; + goto Exit; } lineno = 0; @@ -294,7 +298,7 @@ static int do_lid_matrix_file_load(void *context) "PARSE ERROR: %s:%u: " "cannot parse switch definition\n", file_name, lineno); - return -1; + goto Exit; } p = q + 8; guid = strtoull(p, &q, 16); @@ -303,7 +307,7 @@ static int do_lid_matrix_file_load(void *context) "PARSE ERROR: %s:%u: " "cannot parse switch guid: \'%s\'\n", file_name, lineno, p); - return -1; + goto Exit; } guid = cl_hton64(guid); @@ -328,7 +332,7 @@ static int do_lid_matrix_file_load(void *context) "PARSE ERROR: %s:%u: " "cannot parse lid: \'%s\'\n", file_name, lineno, p); - return -1; + goto Exit; } /* Just checked the range, so casting is safe */ lid = (uint16_t) num; @@ -342,7 +346,7 @@ static int do_lid_matrix_file_load(void *context) "PARSE ERROR: %s:%u: " "cannot parse hops number: \'%s\'\n", file_name, lineno, p); - return -1; + goto Exit; } /* Just checked the range, so casting is safe */ hops[len++] = (uint8_t) num; @@ -375,9 +379,11 @@ static int do_lid_matrix_file_load(void *context) add_lid_hops(p_osm, p_sw, lid, guid, hops, len); } } - - fclose(file); - return 0; + status = 0; +Exit: + if (file) + fclose(file); + return status; } int osm_ucast_file_setup(struct osm_routing_engine *r, osm_opensm_t *osm)