mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "John W. Linville" <linville@tuxdriver.com>,
	Johannes Berg <johannes@sipsolutions.net>,
	devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH 2/6] lib / string_helpers: introduce string_escape_mem()
Date: Thu, 03 Jul 2014 12:53:14 +0300	[thread overview]
Message-ID: <1404381194.5102.69.camel@smile.fi.intel.com> (raw)
In-Reply-To: <20140702150150.b87702934d47fd481646f6ff@linux-foundation.org>

On Wed, 2014-07-02 at 15:01 -0700, Andrew Morton wrote:
> On Wed,  2 Jul 2014 16:20:25 +0300 Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> > This is almost the opposite function to string_unescape(). Nevertheless it
> > handles \0 and could be used for any byte buffer.
> > 
> > The documentation is supplied together with the function prototype.
> > 
> > The test cases covers most of the scenarios and would be expanded later on.
> > 
> > ...
> >
> > --- a/include/linux/string_helpers.h
> > +++ b/include/linux/string_helpers.h
> > @@ -71,4 +71,87 @@ static inline int string_unescape_any_inplace(char *buf)
> >  	return string_unescape_any(buf, buf, 0);
> >  }
> >  
> > +#define ESCAPE_SPACE		0x01
> > +#define ESCAPE_SPECIAL		0x02
> > +#define ESCAPE_NULL		0x04
> > +#define ESCAPE_OCTAL		0x08
> > +#define ESCAPE_ANY		\
> > +	(ESCAPE_SPACE | ESCAPE_OCTAL | ESCAPE_SPECIAL | ESCAPE_NULL)
> > +#define ESCAPE_NP		0x10
> > +#define ESCAPE_ANY_NP		(ESCAPE_ANY | ESCAPE_NP)
> > +#define ESCAPE_HEX		0x20
> > +
> > +/**
> > + * string_escape_mem - quote characters in the given memory buffer
> 
> It drive me nuts when the kerneldoc is in the .h file.  Who thinks of
> looking there?  I realise that string_unescape() already did that, but
> I'd prefer that we fix string_unescape() rather than imitate it.

No problem, I will do this in separate patch.

> 
> > --- a/lib/string_helpers.c
> > +++ b/lib/string_helpers.c
> 
> This is a lot of code!  Adds nearly a kbyte.  I'm surprised that
> escaping a string is so verbose.
> I wonder if the implementation really needs to be so comprehensive?

I studied several kernel cases and try to cover most of them.

> Would a table-driven approach be more compact?

Do you mean something like ctype set of functions?

I wouldn't think so, we have a lot of variations how we would like to
escape. Currently I have such cases covered in terms of flags I
introduced (not all of them in this series):
 - ESCAPE_OCTAL (with dictionary)
 - ESCAPE_ANY_NP
 - ESCAPE_HEX | ESCAPE_NP
 - ESCAPE_NULL
... not yet in form of patch
 - ESCAPE_SPACE | ESCAPE_SPECIAL (with dictionary)

I can't currently realize how table could cover all of that.

> >  static int __init test_string_helpers_init(void)
> >  {
> >  	unsigned int i;
> > @@ -112,6 +315,16 @@ static int __init test_string_helpers_init(void)
> >  	test_string_unescape("unescape inplace",
> >  			     get_random_int() % (UNESCAPE_ANY + 1), true);
> >  
> > +	/* Without dictionary */
> > +	for (i = 0; i < (ESCAPE_ANY_NP | ESCAPE_HEX) + 1; i++)
> > +		test_string_escape("escape 0", escape0, i, TEST_STRING_2_DICT_0);
> > +
> > +	/* With dictionary */
> > +	for (i = 0; i < (ESCAPE_ANY_NP | ESCAPE_HEX) + 1; i++)
> > +		test_string_escape("escape 1", escape1, i, TEST_STRING_2_DICT_1);
> > +
> > +	test_string_escape_nomem();
> > +
> >  	return -EINVAL;
> >  }
> 
> I wonder why this returns -EINVAL.

The idea of course to not let module be loaded. I saw this return code
in test_kstrtox.c. Would you suggest better approach?


-- 
Andy Shevchenko <andriy.shevchenko@intel.com>
Intel Finland Oy


  reply	other threads:[~2014-07-03  9:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-02 13:20 [PATCH 0/6] lib / string_helpers: introduce string_escape_mem Andy Shevchenko
2014-07-02 13:20 ` [PATCH 1/6] lib / string_helpers: clean up test suite Andy Shevchenko
2014-07-02 21:54   ` Andrew Morton
2014-07-03  9:34     ` Andy Shevchenko
2014-07-02 13:20 ` [PATCH 2/6] lib / string_helpers: introduce string_escape_mem() Andy Shevchenko
2014-07-02 22:01   ` Andrew Morton
2014-07-03  9:53     ` Andy Shevchenko [this message]
2014-07-02 13:20 ` [PATCH 3/6] lib80211: re-use string_escape_mem_any_np() Andy Shevchenko
2014-07-02 13:43   ` Joe Perches
2014-07-02 14:06     ` Andy Shevchenko
2014-07-02 16:30       ` Joe Perches
2014-07-03 10:49         ` Andy Shevchenko
2014-07-02 13:20 ` [PATCH 4/6] staging: wlan-ng: re-use string_escape_mem() Andy Shevchenko
2014-07-02 13:20 ` [PATCH 5/6] staging: rtl8192e: " Andy Shevchenko
2014-07-02 13:35   ` Joe Perches
2014-07-02 14:11     ` Andy Shevchenko
2014-07-02 13:20 ` [PATCH 6/6] staging: rtl8192u: " Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404381194.5102.69.camel@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome