From patchwork Wed Jan 9 06:29:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggang LI X-Patchwork-Id: 10753505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E23F17D2 for ; Wed, 9 Jan 2019 06:29:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAD3F28D71 for ; Wed, 9 Jan 2019 06:29:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA61728D77; Wed, 9 Jan 2019 06:29:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,SUBJ_OBFU_PUNCT_FEW autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8392A28D71 for ; Wed, 9 Jan 2019 06:29:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729721AbfAIG3R (ORCPT ); Wed, 9 Jan 2019 01:29:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42526 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729679AbfAIG3R (ORCPT ); Wed, 9 Jan 2019 01:29:17 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1775FC0528C4; Wed, 9 Jan 2019 06:29:17 +0000 (UTC) Received: from localhost (ovpn-12-20.pek2.redhat.com [10.72.12.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 52300600C3; Wed, 9 Jan 2019 06:29:15 +0000 (UTC) From: Honggang Li To: hal@dev.mellanox.co.il Cc: linux-rdma@vger.kernel.org, Honggang Li Subject: [ibsim patch v2] umad2sim.c: make_path should check the return value of mkdir Date: Wed, 9 Jan 2019 14:29:07 +0800 Message-Id: <20190109062907.18321-1-honli@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 09 Jan 2019 06:29:17 +0000 (UTC) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Issue was detected by Coverity. --------------------------- ibsim-0.7/umad2sim/umad2sim.c:151: check_return: Calling "mkdir(dir, 493U)" without checking return value. This library function may fail and return an error code. --------------------------- Also covert the function into a void function, as none of callers checked the return value of make_path. Signed-off-by: Honggang Li --- umad2sim/umad2sim.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/umad2sim/umad2sim.c b/umad2sim/umad2sim.c index b5a0532d0c72..46510b011cca 100644 --- a/umad2sim/umad2sim.c +++ b/umad2sim/umad2sim.c @@ -137,7 +137,7 @@ static void convert_sysfs_path(char *new_path, unsigned size, snprintf(new_path, size, "%s/%s", umad2sim_sysfs_prefix, old_path); } -static int make_path(char *path) +static void make_path(char *path) { char dir[1024]; char *p; @@ -148,14 +148,13 @@ static int make_path(char *path) p = strchr(p, '/'); if (p) *p = '\0'; - mkdir(dir, 0755); + if (mkdir(dir, 0755) && errno != EEXIST) + IBPANIC("Failed to make directory <%s>", dir); if (p) { *p = '/'; p++; } } while (p && p[0]); - - return 0; } static int file_printf(char *path, char *name, const char *fmt, ...)