nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Vishal Verma <vishal.l.verma@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH 2/5] ndctl: fix a resource leak in submit_get_firmware_info
Date: Fri, 10 Aug 2018 16:56:21 -0600	[thread overview]
Message-ID: <20180810225624.32383-3-vishal.l.verma@intel.com> (raw)
In-Reply-To: <20180810225624.32383-1-vishal.l.verma@intel.com>

Static analysis reports that we leak ndctl_cmd in the above function.
Fix by adding a proper cleanup path.

Cc: Dave Jiang <dave.jiang@intel.com>
Fixes: f86369ea29e2 ("ndctl: merge firmware-update into dimm.c as another dimm operation")
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/dimm.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/ndctl/dimm.c b/ndctl/dimm.c
index 97643a3..a4203f3 100644
--- a/ndctl/dimm.c
+++ b/ndctl/dimm.c
@@ -428,36 +428,39 @@ static int submit_get_firmware_info(struct ndctl_dimm *dimm,
 
 	rc = ndctl_cmd_submit(cmd);
 	if (rc < 0)
-		return rc;
+		goto out;
 
+	rc = -ENXIO;
 	status = ndctl_cmd_fw_xlat_firmware_status(cmd);
 	if (status != FW_SUCCESS) {
 		fprintf(stderr, "GET FIRMWARE INFO on DIMM %s failed: %#x\n",
 				ndctl_dimm_get_devname(dimm), status);
-		return -ENXIO;
+		goto out;
 	}
 
 	fw->store_size = ndctl_cmd_fw_info_get_storage_size(cmd);
 	if (fw->store_size == UINT_MAX)
-		return -ENXIO;
+		goto out;
 
 	fw->update_size = ndctl_cmd_fw_info_get_max_send_len(cmd);
 	if (fw->update_size == UINT_MAX)
-		return -ENXIO;
+		goto out;
 
 	fw->query_interval = ndctl_cmd_fw_info_get_query_interval(cmd);
 	if (fw->query_interval == UINT_MAX)
-		return -ENXIO;
+		goto out;
 
 	fw->max_query = ndctl_cmd_fw_info_get_max_query_time(cmd);
 	if (fw->max_query == UINT_MAX)
-		return -ENXIO;
+		goto out;
 
 	fw->run_version = ndctl_cmd_fw_info_get_run_version(cmd);
 	if (fw->run_version == ULLONG_MAX)
-		return -ENXIO;
+		goto out;
 
 	rc = verify_fw_size(uctx);
+
+out:
 	ndctl_cmd_unref(cmd);
 	return rc;
 }
-- 
2.14.4

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

  parent reply	other threads:[~2018-08-10 22:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-10 22:56 [ndctl PATCH 0/5] ndctl: misc static analysis fixes Vishal Verma
2018-08-10 22:56 ` [ndctl PATCH 1/5] ndctl, inject: fix a resource leak in ndctl_namespace_get_clear_unit Vishal Verma
2018-08-10 22:56 ` Vishal Verma [this message]
2018-08-10 22:56 ` [ndctl PATCH 3/5] libndctl: fix a resource leak in ndctl_dimm_get_{{event_}flags, health} Vishal Verma
2018-08-10 22:56 ` [ndctl PATCH 4/5] ndctl, test: fix a potential null pointer dereference in 'ndctl test' Vishal Verma
2018-08-10 22:56 ` [ndctl PATCH 5/5] ndctl, test: fix a resource leak in check_smart_threshold Vishal Verma
2018-08-10 22:58 ` [ndctl PATCH 0/5] ndctl: misc static analysis fixes Dave Jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180810225624.32383-3-vishal.l.verma@intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    --subject='Re: [ndctl PATCH 2/5] ndctl: fix a resource leak in submit_get_firmware_info' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).