From patchwork Mon Dec 30 15:59:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hal Rosenstock X-Patchwork-Id: 3419761 X-Patchwork-Delegate: hal@mellanox.com Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C04E59F37A for ; Mon, 30 Dec 2013 16:00:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 79E1E2010E for ; Mon, 30 Dec 2013 16:00:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5860320109 for ; Mon, 30 Dec 2013 16:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932073Ab3L3P77 (ORCPT ); Mon, 30 Dec 2013 10:59:59 -0500 Received: from mail-ea0-f174.google.com ([209.85.215.174]:50867 "EHLO mail-ea0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932069Ab3L3P76 (ORCPT ); Mon, 30 Dec 2013 10:59:58 -0500 Received: by mail-ea0-f174.google.com with SMTP id b10so5147414eae.33 for ; Mon, 30 Dec 2013 07:59:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:content-type:content-transfer-encoding; bh=b+QEXFK7sj+v8PAha4JDD7amrzNMFl5cfwBpP7Iyi68=; b=g5xSns0ji7j19IzGRrqCGuC19735kpLwUzCbfgZPch6CryNZaRJKl0WJH73zFZahC1 pE8ynjo1z5MHGJMJk8BfJZ4RKnAlWoLQL9ysaVa8cU3Z4DaJ/sSoKY5TJqeEaQapU49g BFhn8g+7/Vda7g9O1CaPjr2hTbURgkMJbfETIoJwzUMiIwDh8NF+RYlWTLHzutHvLvZM o+TVqejZKUzMGLdsCN+sZvlIpGzn/iU4KqYnV8INGWDfd9eXwqcuQGCF5eUxU6diYcyQ XptuRAx/IrJ5TtnJTkGBPoNv7n7jB2bP8/fjnf/GeoEuZXEUpSo5pYs7kbg7P2mMPV+w Aqpg== X-Gm-Message-State: ALoCoQnFbu0uAI0x3ssaVfr+q0ix3qJk7lahzbSXHOaL++/BCp2QUByZ+AmOZj0dhCfiV7V5owEz X-Received: by 10.14.88.134 with SMTP id a6mr54811923eef.5.1388419197295; Mon, 30 Dec 2013 07:59:57 -0800 (PST) Received: from [192.168.1.102] (c-98-229-118-119.hsd1.ma.comcast.net. [98.229.118.119]) by mx.google.com with ESMTPSA id b41sm109824902eef.16.2013.12.30.07.59.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Dec 2013 07:59:56 -0800 (PST) Message-ID: <52C1987A.6000802@dev.mellanox.co.il> Date: Mon, 30 Dec 2013 10:59:54 -0500 From: Hal Rosenstock User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: "linux-rdma (linux-rdma@vger.kernel.org)" CC: Bart Van Assche Subject: [PATCH opensm] osm_db_files.c: Some minor fixes/improvements to osm_db_store 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.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 1. Check p_domain_imp->dirty flag under lock 2. Handle malloc failure for temporary file name 3. Move malloc outside of lock Items 1 and 2 above were: Pointed-out-by: Bart Van Assche in http://marc.info/?l=linux-rdma&m=138763427730411&w=2 Signed-off-by: Hal Rosenstock --- -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/opensm/osm_db_files.c b/opensm/osm_db_files.c index 38ee9a9..b43b5e6 100644 --- a/opensm/osm_db_files.c +++ b/opensm/osm_db_files.c @@ -475,16 +475,21 @@ int osm_db_store(IN osm_db_domain_t * p_domain, p_domain_imp = (osm_db_domain_imp_t *) p_domain->p_domain_imp; - if (p_domain_imp->dirty == FALSE) - goto Exit; - p_tmp_file_name = malloc(sizeof(char) * (strlen(p_domain_imp->file_name) + 8)); + if (!p_tmp_file_name) { + OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 6113: " + "Failed to allocate memory for temporary file name\n"); + goto Exit; + } strcpy(p_tmp_file_name, p_domain_imp->file_name); strcat(p_tmp_file_name, ".tmp"); cl_spinlock_acquire(&p_domain_imp->lock); + if (p_domain_imp->dirty == FALSE) + goto Exit; + /* open up the output file */ p_file = fopen(p_tmp_file_name, "w"); if (!p_file) {