From: Caleb Sander Date: Wed, 30 Aug 2023 15:44:48 +0000 (-0600) Subject: fabrics: only look for spaces in strchomp() X-Git-Tag: v1.6~30 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=308c3e15e29177e9321ad3b7c39a4ad9b2961dcb;p=users%2Fsagi%2Flibnvme.git fabrics: only look for spaces in strchomp() strchomp() is only needed to strip trailing spaces from a string. There is no need to replace NUL characters with NUL characters. So simplify the check for "NUL or space" to just "space". Update the function description as well, as it doesn't strip all whitespace, just spaces. Signed-off-by: Caleb Sander --- diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index 6e434e44..acbcda35 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -47,7 +47,7 @@ const char *nvmf_dev = "/dev/nvme-fabrics"; /** - * strchomp() - Strip trailing white space + * strchomp() - Strip trailing spaces * @str: String to strip * @max: Maximum length of string */ @@ -55,11 +55,8 @@ static void strchomp(char *str, int max) { int i; - for (i = max - 1; i >= 0; i--) { - if (str[i] != '\0' && str[i] != ' ') - return; - else - str[i] = '\0'; + for (i = max - 1; i >= 0 && str[i] == ' '; i--) { + str[i] = '\0'; } }