linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>,
	linux-nvme@lists.infradead.org
Cc: kbusch@kernel.org, Kev Dorman <kdorman036@gmail.com>
Subject: Re: [PATCH nvme-cli] nvme: fix asprintf return value check
Date: Sat, 25 Apr 2020 10:34:28 -0700	[thread overview]
Message-ID: <3dda409b-bb72-1019-5ce8-e22781d45ba3@acm.org> (raw)
In-Reply-To: <20200425055852.2921-1-chaitanya.kulkarni@wdc.com>

On 2020-04-24 22:58, Chaitanya Kulkarni wrote:
> diff --git a/nvme-topology.c b/nvme-topology.c
> index e938f23..4dbadce 100644
> --- a/nvme-topology.c
> +++ b/nvme-topology.c
> @@ -357,9 +357,9 @@ static int verify_legacy_ns(struct nvme_namespace *n)
>  		char tmp_address[64] = "";
>  		legacy_get_pci_bdf(path, tmp_address);
>  		if (tmp_address[0]) {
> -			if (asprintf(&n->ctrl->transport, "pcie") != 1)
> +			if (asprintf(&n->ctrl->transport, "pcie") == -1)
>  				return -1;
> -			if (asprintf(&n->ctrl->address, "%s", tmp_address) != 1)
> +			if (asprintf(&n->ctrl->address, "%s", tmp_address) == -1)
>  				return -1;
>  		}
>  	}

How about using "< 0" to check for errors? I think that's a more widely
used approach to check for errors than checking for "== -1".

Will a memory leak occur if the first asprintf() call succeeds and the
second asprintf() call fails?

Thanks,

Bart.

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  reply	other threads:[~2020-04-25 17:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-25  5:58 [PATCH nvme-cli] nvme: fix asprintf return value check Chaitanya Kulkarni
2020-04-25 17:34 ` Bart Van Assche [this message]
2020-04-25 18:09   ` Chaitanya Kulkarni

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=3dda409b-bb72-1019-5ce8-e22781d45ba3@acm.org \
    --to=bvanassche@acm.org \
    --cc=chaitanya.kulkarni@wdc.com \
    --cc=kbusch@kernel.org \
    --cc=kdorman036@gmail.com \
    --cc=linux-nvme@lists.infradead.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).