diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2014-11-28 10:50:28 -0500 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2014-12-09 11:30:20 -0500 |
commit | 1b2e122d167d8983775eb57d55349c331e6aa6c7 (patch) | |
tree | fdddc65373252c4ba53a97e7ffafd8c43ac6f2a5 /net | |
parent | acf06a7fa12070abb3eab24fc4bc30e361a7c416 (diff) |
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>
Diffstat (limited to 'net')
-rw-r--r-- | net/sunrpc/cache.c | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index 066362141133..33fb105d4352 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/list.h> | 20 | #include <linux/list.h> |
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/ctype.h> | 22 | #include <linux/ctype.h> |
23 | #include <linux/string_helpers.h> | ||
23 | #include <asm/uaccess.h> | 24 | #include <asm/uaccess.h> |
24 | #include <linux/poll.h> | 25 | #include <linux/poll.h> |
25 | #include <linux/seq_file.h> | 26 | #include <linux/seq_file.h> |
@@ -1067,30 +1068,15 @@ void qword_add(char **bpp, int *lp, char *str) | |||
1067 | { | 1068 | { |
1068 | char *bp = *bpp; | 1069 | char *bp = *bpp; |
1069 | int len = *lp; | 1070 | int len = *lp; |
1070 | char c; | 1071 | int ret; |
1071 | 1072 | ||
1072 | if (len < 0) return; | 1073 | if (len < 0) return; |
1073 | 1074 | ||
1074 | while ((c=*str++) && len) | 1075 | ret = string_escape_str(str, &bp, len, ESCAPE_OCTAL, "\\ \n\t"); |
1075 | switch(c) { | 1076 | if (ret < 0 || ret == len) |
1076 | case ' ': | 1077 | len = -1; |
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; | ||
1093 | else { | 1078 | else { |
1079 | len -= ret; | ||
1094 | *bp++ = ' '; | 1080 | *bp++ = ' '; |
1095 | len--; | 1081 | len--; |
1096 | } | 1082 | } |