diff mbox

[5/6] staging: rtl8192e: re-use string_escape_mem()

Message ID 1404307229-19186-6-git-send-email-andriy.shevchenko@linux.intel.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Andy Shevchenko July 2, 2014, 1:20 p.m. UTC
Let's use kernel's library function to escape a buffer.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/staging/rtl8192e/rtllib.h | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

Comments

Joe Perches July 2, 2014, 1:35 p.m. UTC | #1
On Wed, 2014-07-02 at 16:20 +0300, Andy Shevchenko wrote:
> Let's use kernel's library function to escape a buffer.
[]
> diff --git a/drivers/staging/rtl8192e/rtllib.h b/drivers/staging/rtl8192e/rtllib.h
[]
> @@ -2956,7 +2957,6 @@ extern inline int rtllib_get_scans(struct rtllib_device *ieee)
>  static inline const char *escape_essid(const char *essid, u8 essid_len)
>  {
>  	static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
> -	const char *s = essid;
>  	char *d = escaped;
>  
>  	if (rtllib_is_empty_essid(essid, essid_len)) {
> @@ -2965,15 +2965,8 @@ static inline const char *escape_essid(const char *essid, u8 essid_len)
>  	}
>  
>  	essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE);
> -	while (essid_len--) {
> -		if (*s == '\0') {
> -			*d++ = '\\';
> -			*d++ = '0';
> -			s++;
> -		} else {
> -			*d++ = *s++;
> -		}
> -	}
> +	d += string_escape_mem(essid, essid_len, escaped, sizeof(escaped) - 1,
> +			       ESCAPE_NULL, NULL);

I'd've probably used

	d += string_escape_mem(essid, essid_len, d, ...
or
	d = escaped + string_escap_mem(essid, essid_len, escaped, ...

so there's some relation between the thing being added to

>  	*d = '\0';

or maybe not used d at all with

	escaped[1 + string_escape_mem(etc...)] = 0;

>  	return escaped;
>  }

Unrelated but this isn't a thread safe or multiple instance
safe function.

It seems it's used only in debugging message output though.

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Shevchenko July 2, 2014, 2:11 p.m. UTC | #2
On Wed, 2014-07-02 at 06:35 -0700, Joe Perches wrote:
> On Wed, 2014-07-02 at 16:20 +0300, Andy Shevchenko wrote:
> > Let's use kernel's library function to escape a buffer.

[]

> > @@ -2965,15 +2965,8 @@ static inline const char *escape_essid(const char *essid, u8 essid_len)
> >  	}
> >  
> >  	essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE);
> > -	while (essid_len--) {
> > -		if (*s == '\0') {
> > -			*d++ = '\\';
> > -			*d++ = '0';
> > -			s++;
> > -		} else {
> > -			*d++ = *s++;
> > -		}
> > -	}
> > +	d += string_escape_mem(essid, essid_len, escaped, sizeof(escaped) - 1,
> > +			       ESCAPE_NULL, NULL);
> 
> I'd've probably used
> 
> 	d += string_escape_mem(essid, essid_len, d, ...
> or
> 	d = escaped + string_escap_mem(essid, essid_len, escaped, ...
> 
> so there's some relation between the thing being added to
> 
> >  	*d = '\0';
> 
> or maybe not used d at all with
> 
> 	escaped[1 + string_escape_mem(etc...)] = 0;

Perhaps without '1 + ' part. I could update this as well if someone
insists.

> 
> >  	return escaped;
> >  }
> 
> Unrelated but this isn't a thread safe or multiple instance
> safe function.

Do you mean escape_ssid() or string_escape_mem() or both?

For the string_escape_mem() I think caller should take care of.

> It seems it's used only in debugging message output though.
diff mbox

Patch

diff --git a/drivers/staging/rtl8192e/rtllib.h b/drivers/staging/rtl8192e/rtllib.h
index 83f5f57..cb99160 100644
--- a/drivers/staging/rtl8192e/rtllib.h
+++ b/drivers/staging/rtl8192e/rtllib.h
@@ -31,6 +31,7 @@ 
 #include <linux/timer.h>
 #include <linux/sched.h>
 #include <linux/semaphore.h>
+#include <linux/string_helpers.h>
 
 #include <linux/delay.h>
 #include <linux/wireless.h>
@@ -2956,7 +2957,6 @@  extern inline int rtllib_get_scans(struct rtllib_device *ieee)
 static inline const char *escape_essid(const char *essid, u8 essid_len)
 {
 	static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
-	const char *s = essid;
 	char *d = escaped;
 
 	if (rtllib_is_empty_essid(essid, essid_len)) {
@@ -2965,15 +2965,8 @@  static inline const char *escape_essid(const char *essid, u8 essid_len)
 	}
 
 	essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE);
-	while (essid_len--) {
-		if (*s == '\0') {
-			*d++ = '\\';
-			*d++ = '0';
-			s++;
-		} else {
-			*d++ = *s++;
-		}
-	}
+	d += string_escape_mem(essid, essid_len, escaped, sizeof(escaped) - 1,
+			       ESCAPE_NULL, NULL);
 	*d = '\0';
 	return escaped;
 }