Skip to content

Commit

Permalink
sunrpc/cache: convert to use string_escape_str()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Andy Shevchenko authored and J. Bruce Fields committed Dec 9, 2014
1 parent acf06a7 commit 1b2e122
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions net/sunrpc/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <linux/list.h>
#include <linux/module.h>
#include <linux/ctype.h>
#include <linux/string_helpers.h>
#include <asm/uaccess.h>
#include <linux/poll.h>
#include <linux/seq_file.h>
Expand Down Expand Up @@ -1067,30 +1068,15 @@ void qword_add(char **bpp, int *lp, char *str)
{
char *bp = *bpp;
int len = *lp;
char c;
int ret;

if (len < 0) return;

while ((c=*str++) && len)
switch(c) {
case ' ':
case '\t':
case '\n':
case '\\':
if (len >= 4) {
*bp++ = '\\';
*bp++ = '0' + ((c & 0300)>>6);
*bp++ = '0' + ((c & 0070)>>3);
*bp++ = '0' + ((c & 0007)>>0);
}
len -= 4;
break;
default:
*bp++ = c;
len--;
}
if (c || len <1) len = -1;
ret = string_escape_str(str, &bp, len, ESCAPE_OCTAL, "\\ \n\t");
if (ret < 0 || ret == len)
len = -1;
else {
len -= ret;
*bp++ = ' ';
len--;
}
Expand Down

0 comments on commit 1b2e122

Please sign in to comment.