* [PATCH nvme-cli] nvme: fix asprintf return value check
@ 2020-04-25 5:58 Chaitanya Kulkarni
2020-04-25 17:34 ` Bart Van Assche
0 siblings, 1 reply; 3+ messages in thread
From: Chaitanya Kulkarni @ 2020-04-25 5:58 UTC (permalink / raw)
To: linux-nvme; +Cc: kbusch, Kev Dorman, Chaitanya Kulkarni
The asprintf(3) function resturns -1 on error not 1. Fix that.
Fixes a032a481d74 ("nvme: fix compiler warnings")
Suggested-by: Kev Dorman <kdorman036@gmail.com>
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
nvme-topology.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
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;
}
}
--
2.22.1
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH nvme-cli] nvme: fix asprintf return value check
2020-04-25 5:58 [PATCH nvme-cli] nvme: fix asprintf return value check Chaitanya Kulkarni
@ 2020-04-25 17:34 ` Bart Van Assche
2020-04-25 18:09 ` Chaitanya Kulkarni
0 siblings, 1 reply; 3+ messages in thread
From: Bart Van Assche @ 2020-04-25 17:34 UTC (permalink / raw)
To: Chaitanya Kulkarni, linux-nvme; +Cc: kbusch, Kev Dorman
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH nvme-cli] nvme: fix asprintf return value check
2020-04-25 17:34 ` Bart Van Assche
@ 2020-04-25 18:09 ` Chaitanya Kulkarni
0 siblings, 0 replies; 3+ messages in thread
From: Chaitanya Kulkarni @ 2020-04-25 18:09 UTC (permalink / raw)
To: Bart Van Assche, linux-nvme; +Cc: kbusch, Kev Dorman
> 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.
>
Thanks for the comment, will send a V2.
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-25 18:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-25 5:58 [PATCH nvme-cli] nvme: fix asprintf return value check Chaitanya Kulkarni
2020-04-25 17:34 ` Bart Van Assche
2020-04-25 18:09 ` Chaitanya Kulkarni
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).