From patchwork Fri Nov 28 15:50:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 5404391 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 50BA3BEEA8 for ; Fri, 28 Nov 2014 15:50:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 74BF42016C for ; Fri, 28 Nov 2014 15:50:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C542200E7 for ; Fri, 28 Nov 2014 15:50:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750951AbaK1Pum (ORCPT ); Fri, 28 Nov 2014 10:50:42 -0500 Received: from mga11.intel.com ([192.55.52.93]:7787 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750729AbaK1Pum (ORCPT ); Fri, 28 Nov 2014 10:50:42 -0500 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 28 Nov 2014 07:50:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,862,1389772800"; d="scan'208";a="422703855" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.90]) by FMSMGA003.fm.intel.com with ESMTP; 28 Nov 2014 07:40:43 -0800 Received: from andy by smile with local (Exim 4.84) (envelope-from ) id 1XuNod-0006hT-LT; Fri, 28 Nov 2014 17:50:39 +0200 From: Andy Shevchenko To: linux-nfs@vger.kernel.org, "J. Bruce Fields" , "David S. Miller" Cc: Andy Shevchenko Subject: [PATCH v1] sunrpc/cache: convert to use string_escape_str() Date: Fri, 28 Nov 2014 17:50:28 +0200 Message-Id: <1417189828-25688-1-git-send-email-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.1.3 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- net/sunrpc/cache.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index 0663621..5cf60a4 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -1067,32 +1068,16 @@ 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 { *bp++ = ' '; - len--; + len -= ret - 1; } *bpp = bp; *lp = len;