-
Notifications
You must be signed in to change notification settings - Fork 668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nvme-print-json: extern json object add functions #2487
Conversation
Separated the commit from the PR #2484. |
ced6518
to
4ab769c
Compare
nvme-print-json.c
Outdated
for (i = 0; i < len; i++) | ||
sprintf(&value[strlen(value)], "%02x", buf[len - i - 1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a quadratic algorithm for what should be linear. Can you just keep track of the current length in a local variable?
Reversing the bytes also seems a little weird, but I guess I don't know what the intended use case is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a quadratic algorithm for what should be linear. Can you just keep track of the current length in a local variable?
Just fix this as mentioned.
Reversing the bytes also seems a little weird, but I guess I don't know what the intended use case is.
Unfortunately I do not any idea to resovle this. This outputs the little endian bytes endian as a big endian string as below for example.
buf[0] = 0xaa;
buf[1] = 0xbb;
buf[2] = 0xcc;
buf[3] = 0xdd;
value = "0xddccbbaa"
Thank you for your reviewing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really looked into it, so just a stupid comment from my side on the output order. Shouldn't this be output how the spec defines it? IIRC everything as little endian? (if this statement is untrue, I blame my vacation...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @igaw. It's hard to say without knowing how this function is going to be used. (I would expect the functions to be added in the same patch set as users of the functions.) But for generic "print bytes" functionality, it seems like it would make sense to print the bytes in the order they appear. If the function is interpreting the bytes as an integer, it might make more sense to have "unit" in the function name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
For example the existing fw-activate-history command outputs the loge page GUID value as below as a big endian string.
tokunori@tokunori-desktop:~/nvme-cli$ nvme-build ocp fw-activate-history /dev/nvme0
Firmware History Log:
log identifier: 194
valid entries: 0
entries:
log page version: 1
log page guid: 0xd11cf3ac8ab24de2a3f6dab4769a796d
Also the OCP specification is also describes same as below as D11CF3AC8AB24DE2A3F6DAB4769A796Dh.
So seems the ocp commands just follow the specification descritions.
4ab769c
to
6ac6fd4
Compare
nvme-print-json.c
Outdated
|
||
_cleanup_free_ char *value = NULL; | ||
|
||
if (!o || !k || !buf || !len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to handle all these cases? I don't see the other JSON value add functions checking their arguments like this. Seems like this would be papering over a bug in the caller...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which do you suggest?
- Ignore the invalid value with the checking then the function caused a null pointer exception or any unexpected error. (I do not think this function behavior correct.)
- Change the void function to return any error by the checking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this as add a error message by the checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logging the error at least is an improvement. But in what situation do we expect a caller to pass in these invalid values? Seems like unnecessary overhead to check them. If null pointers are passed, we will get a pretty clear segfault.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Just fixed as below. Thank you.
if (!buf || !len) {
obj_add_str(o, k, "No information provided");
return;
}
return; | ||
} | ||
|
||
sprintf(value, "0x"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this being overwritten by the hex characters of the first byte?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Sorry the fix was not correct. Thanks for your suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the overwritten error.
14cc520
to
8cc6169
Compare
Some additinal functions introduced and fix obj_add_uint_0nx error. Signed-off-by: Tokunori Ikegami <[email protected]>
8cc6169
to
a1d3885
Compare
Thanks! |
Some additinal functions introduced and fix obj_add_uint_0nx error.