From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by dpdk.org (Postfix) with ESMTP id EA1582C52 for ; Tue, 6 Nov 2018 20:30:10 +0100 (CET) Received: by mail-pg1-f196.google.com with SMTP id c10-v6so6254605pgq.4 for ; Tue, 06 Nov 2018 11:30:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FiP8fEOMwEYXV3ynB5vs09VgJcAWxxg7hYsDdibfxjw=; b=sMQhNELLBjMt2fpDu0T+DGLm6pGiXBr0Fti2oIBk1brUIuFswZpaB3zFVnbwch1G1B db1CAPECrMGqou9B0YjJmk8Q5YvyTbLWg6NgcHrmddRfvseMtvViHjDNZK06XNWAN8kn 7SGo7hjzcdk3VeQ8zTVcaOovG4TX3sUOE8dAPQucNaig5BZv9k6TrMfvlciURyZ3sYvg PZ+ciEVDrtLaIhn+UT6o5PZdIrPj/BioxK/Rft8/q9O7nNpuZ5He/t8qPwYZp4pnAd7+ /2eLYzEPomqM1TlSt5KzsPZLtKwQ3tTbGy7qORdSs4QsPY19m8wJNDufck7pSl1pHlxN 6S1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FiP8fEOMwEYXV3ynB5vs09VgJcAWxxg7hYsDdibfxjw=; b=fjSKIm2AEMEQ8rgNGhUUHMC/mAuKdqk/ZPjHfR2mUfOZiat/xnQUHK4r78PAKi2vtQ qkGdU7TMDXfW8imtdAHgO29+wFOPAdST7tV6wF8bBFj5kpVsxANKaMS1Bkqc+WP5Oxxi YVSiH/0Zlj18LJV1/s21v73I+D7eOt9X21LUjYQn9iY9y048DmWikrDGfpCpQV6BprFI dIBA7bqTppKdsGZhyqVZ4uBIOcPk2vmIm1sT3I+JZYXXGXRQUSHPbQpJF19QRmlSYkPJ Q8yKMokhS2868SfOlE7MVmm2P+KdEeAuU20xzChbMyUmJW+umUPrNNGY9cTrhlGofyRI YMWQ== X-Gm-Message-State: AGRZ1gJR0DNni3DuQonkgwxkVqt5a8H3mtm383zHbzU8MkhDOuVY6h/4 0habyhvmnD2kuoeTKQCPqkfZrtDQKeU= X-Google-Smtp-Source: AJdET5d8Pb0oZ/B5s0wtTgjy6B4spSLZ+yLPEedHqeZrEQ5+Q/e5nYtR6DskelZyJp00MivXStYAoA== X-Received: by 2002:a62:9702:: with SMTP id n2-v6mr27379665pfe.222.1541532609430; Tue, 06 Nov 2018 11:30:09 -0800 (PST) Received: from localhost.localdomain ([167.220.105.115]) by smtp.gmail.com with ESMTPSA id a18sm9638633pgj.30.2018.11.06.11.30.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 11:30:08 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 6 Nov 2018 11:30:03 -0800 Message-Id: <20181106193005.5383-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181106193005.5383-1-stephen@networkplumber.org> References: <20181106193005.5383-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH 2/4] bus/vmbus: fix directory handle leak on error X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Nov 2018 19:30:11 -0000 If sysfs directory was incorrectly formatted then the vmbus setup code would leak a directory handle in the error path. Coverity issue: 302848 Fixes: 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support") Signed-off-by: Stephen Hemminger --- drivers/bus/vmbus/linux/vmbus_uio.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/bus/vmbus/linux/vmbus_uio.c b/drivers/bus/vmbus/linux/vmbus_uio.c index 856c6d66785d..12e97e3a420a 100644 --- a/drivers/bus/vmbus/linux/vmbus_uio.c +++ b/drivers/bus/vmbus/linux/vmbus_uio.c @@ -329,6 +329,7 @@ int vmbus_uio_get_subchan(struct vmbus_channel *primary, char chan_path[PATH_MAX], subchan_path[PATH_MAX]; struct dirent *ent; DIR *chan_dir; + int err; snprintf(chan_path, sizeof(chan_path), "%s/%s/channels", @@ -344,7 +345,6 @@ int vmbus_uio_get_subchan(struct vmbus_channel *primary, while ((ent = readdir(chan_dir))) { unsigned long relid, subid, monid; char *endp; - int err; if (ent->d_name[0] == '.') continue; @@ -364,8 +364,7 @@ int vmbus_uio_get_subchan(struct vmbus_channel *primary, if (err) { VMBUS_LOG(NOTICE, "invalid subchannel id %lu", subid); - closedir(chan_dir); - return err; + goto fail; } if (subid == 0) @@ -382,17 +381,20 @@ int vmbus_uio_get_subchan(struct vmbus_channel *primary, if (err) { VMBUS_LOG(NOTICE, "invalid monitor id %lu", monid); - return err; + goto fail; } err = vmbus_chan_create(dev, relid, subid, monid, subchan); if (err) { VMBUS_LOG(NOTICE, "subchannel setup failed"); - return err; + goto fail; } break; } closedir(chan_dir); return (ent == NULL) ? -ENOENT : 0; +fail: + closedir(chan_dir); + return err; } -- 2.17.1