libnvme/json: check write return value for build warnings#3101
Merged
igaw merged 1 commit intolinux-nvme:masterfrom Feb 20, 2026
Merged
libnvme/json: check write return value for build warnings#3101igaw merged 1 commit intolinux-nvme:masterfrom
igaw merged 1 commit intolinux-nvme:masterfrom
Conversation
igaw
reviewed
Feb 18, 2026
| JSON_C_TO_STRING_NOSLASHESCAPE); | ||
| write(fd, "\n", 1); | ||
| if (ret < 0) { | ||
| if (ret < 0 || write(fd, "\n", 1) < 0) { |
Collaborator
There was a problem hiding this comment.
The log message could then be missleading when json_object_to_fd is succesfull and then the write fails. In this case json_util_get_last_error will not be correct.
something like this here would be less confusing
ret = json_object_to_fd(fd, json_root,
JSON_C_TO_STRING_PRETTY |
JSON_C_TO_STRING_NOSLASHESCAPE);
if (ret < 0) {
nvme_msg(ctx, LOG_ERR, "Failed to write JSON config file: %s\n",
json_util_get_last_err());
[...]
};
ret = write(...)
if (ret < 0) {
nvme_msg(...);
}(though highly unlikely to happen)
Contributor
Author
There was a problem hiding this comment.
How about this?
nvme_msg(ctx, LOG_ERR, "Failed to write JSON config file: %s\n",
ret ? json_util_get_last_err() : strerror());
Contributor
Author
There was a problem hiding this comment.
Just fixed as commented. Thank you.
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: 74b30d2 ("json: update nvme_dump_config to a file descriptor")
Signed-off-by: Tokunori Ikegami <[email protected]>
fd341bc to
8f51686
Compare
Collaborator
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: 74b30d2 ("json: update nvme_dump_config to a file descriptor")