From 8f51686dc6689d5ca91480828a85cbcc0c027dcb Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Wed, 18 Feb 2026 00:40:47 +0900 Subject: [PATCH] libnvme/json: check write return value for build warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the following build warnings output. [61/232] Compiling C object libnvme/src/libnvme-test.so.p/nvme_json.c.o ../libnvme/src/nvme/json.c: In function ‘json_update_config’: ../libnvme/src/nvme/json.c:438:9: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 438 | write(fd, "\n", 1); | ^~~~~~~~~~~~~~~~~~ [62/232] Compiling C object libnvme/src/libnvme.so.3.0.0.p/nvme_json.c.o ../libnvme/src/nvme/json.c: In function ‘json_update_config’: ../libnvme/src/nvme/json.c:438:9: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 438 | write(fd, "\n", 1); | ^~~~~~~~~~~~~~~~~~ Fixes: 74b30d2556c3 ("json: update nvme_dump_config to a file descriptor") Signed-off-by: Tokunori Ikegami --- libnvme/src/nvme/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libnvme/src/nvme/json.c b/libnvme/src/nvme/json.c index 3121cece8c..e095de53b4 100644 --- a/libnvme/src/nvme/json.c +++ b/libnvme/src/nvme/json.c @@ -435,10 +435,9 @@ int json_update_config(struct nvme_global_ctx *ctx, int fd) ret = json_object_to_fd(fd, json_root, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE); - write(fd, "\n", 1); - if (ret < 0) { + if (ret < 0 || write(fd, "\n", 1) < 0) { nvme_msg(ctx, LOG_ERR, "Failed to write JSON config file: %s\n", - json_util_get_last_err()); + ret ? json_util_get_last_err() : strerror(errno)); ret = -EIO; } json_object_put(json_root);