public inbox for [email protected]
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Jens Axboe <[email protected]>
Cc: fio Mailing List <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>,
	Ammar Faizi <[email protected]>
Subject: [PATCH v1 4/6] engines/net: Replace `malloc()`+`memset()` with `calloc()`
Date: Wed, 27 Apr 2022 04:20:42 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

From: Ammar Faizi <[email protected]>

Replace `malloc()` + `memset()` with `calloc()`. While in there, handle
the ENOMEM case of it.

Signed-off-by: Ammar Faizi <[email protected]>
---
 engines/net.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/engines/net.c b/engines/net.c
index c6cec584..8a898748 100644
--- a/engines/net.c
+++ b/engines/net.c
@@ -1363,6 +1363,10 @@ static int fio_netio_setup(struct thread_data *td)
 {
 	struct netio_data *nd;
 
+	nd = calloc(1, sizeof(*nd));
+	if (!nd)
+		return 1;
+
 	if (!td->files_index) {
 		add_file(td, td->o.filename ?: "net", 0, 0);
 		td->o.nr_files = td->o.nr_files ?: 1;
@@ -1370,9 +1374,6 @@ static int fio_netio_setup(struct thread_data *td)
 	}
 
 	if (!td->io_ops_data) {
-		nd = malloc(sizeof(*nd));
-
-		memset(nd, 0, sizeof(*nd));
 		nd->listenfd = -1;
 		nd->pipes[0] = nd->pipes[1] = -1;
 		td->io_ops_data = nd;
@@ -1391,7 +1392,8 @@ static int fio_netio_setup_splice(struct thread_data *td)
 {
 	struct netio_data *nd;
 
-	fio_netio_setup(td);
+	if (fio_netio_setup(td))
+		return 1;
 
 	nd = td->io_ops_data;
 	if (nd) {
-- 
Ammar Faizi


  parent reply	other threads:[~2022-04-26 21:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-26 21:20 [PATCH v1 0/6] Small fio cleanups and fixes Ammar Faizi
2022-04-26 21:20 ` [PATCH v1 1/6] backend: Fix indentation Ammar Faizi
2022-04-26 21:20 ` [PATCH v1 2/6] get_cgroup_root: Handle `ENOMEM` case on `malloc()` call Ammar Faizi
2022-04-26 21:20 ` [PATCH v1 3/6] stat: " Ammar Faizi
2022-04-26 21:24   ` Ammar Faizi
2022-04-26 21:20 ` Ammar Faizi [this message]
2022-04-26 21:31   ` [PATCH v1 4/6] engines/net: Replace `malloc()`+`memset()` with `calloc()` Ammar Faizi
2022-04-26 21:20 ` [PATCH v1 5/6] json: Change `if (!strlen(str))` to `if (!str[0])` Ammar Faizi
2022-04-26 21:20 ` [PATCH v1 6/6] Makefile: Suppress `-Wimplicit-fallthrough` when compiling `lex.yy` Ammar Faizi

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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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