Skip to content

Commit 1b2e122

Browse files
andy-shevJ. Bruce Fields
authored andcommitted
sunrpc/cache: convert to use string_escape_str()
There is nice kernel helper to escape a given strings by provided rules. Let's use it instead of custom approach. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> [bfields@redhat.com: fix length calculation] Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent acf06a7 commit 1b2e122

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

net/sunrpc/cache.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/list.h>
2121
#include <linux/module.h>
2222
#include <linux/ctype.h>
23+
#include <linux/string_helpers.h>
2324
#include <asm/uaccess.h>
2425
#include <linux/poll.h>
2526
#include <linux/seq_file.h>
@@ -1067,30 +1068,15 @@ void qword_add(char **bpp, int *lp, char *str)
10671068
{
10681069
char *bp = *bpp;
10691070
int len = *lp;
1070-
char c;
1071+
int ret;
10711072

10721073
if (len < 0) return;
10731074

1074-
while ((c=*str++) && len)
1075-
switch(c) {
1076-
case ' ':
1077-
case '\t':
1078-
case '\n':
1079-
case '\\':
1080-
if (len >= 4) {
1081-
*bp++ = '\\';
1082-
*bp++ = '0' + ((c & 0300)>>6);
1083-
*bp++ = '0' + ((c & 0070)>>3);
1084-
*bp++ = '0' + ((c & 0007)>>0);
1085-
}
1086-
len -= 4;
1087-
break;
1088-
default:
1089-
*bp++ = c;
1090-
len--;
1091-
}
1092-
if (c || len <1) len = -1;
1075+
ret = string_escape_str(str, &bp, len, ESCAPE_OCTAL, "\\ \n\t");
1076+
if (ret < 0 || ret == len)
1077+
len = -1;
10931078
else {
1079+
len -= ret;
10941080
*bp++ = ' ';
10951081
len--;
10961082
}

0 commit comments

Comments
 (0)