* [PATCH] alsa: 6fire: don't use custom hex_to_bin()
@ 2011-09-23 11:32 Andy Shevchenko
2011-09-23 11:32 ` [PATCH] fat: " Andy Shevchenko
2011-09-23 13:22 ` [PATCH] alsa: 6fire: " Takashi Iwai
0 siblings, 2 replies; 21+ messages in thread
From: Andy Shevchenko @ 2011-09-23 11:32 UTC (permalink / raw)
To: linux-kernel; +Cc: Andy Shevchenko, Takashi Iwai, alsa-devel
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org
---
sound/usb/6fire/firmware.c | 25 ++++++++++++-------------
1 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/sound/usb/6fire/firmware.c b/sound/usb/6fire/firmware.c
index 3ebbdec..3b5f517 100644
--- a/sound/usb/6fire/firmware.c
+++ b/sound/usb/6fire/firmware.c
@@ -17,6 +17,7 @@
#include <linux/firmware.h>
#include <linux/module.h>
#include <linux/bitrev.h>
+#include <linux/kernel.h>
#include "firmware.h"
#include "chip.h"
@@ -60,21 +61,19 @@ struct ihex_record {
unsigned int txt_offset; /* current position in txt_data */
};
-static u8 usb6fire_fw_ihex_nibble(const u8 n)
-{
- if (n >= '0' && n <= '9')
- return n - '0';
- else if (n >= 'A' && n <= 'F')
- return n - ('A' - 10);
- else if (n >= 'a' && n <= 'f')
- return n - ('a' - 10);
- return 0;
-}
-
static u8 usb6fire_fw_ihex_hex(const u8 *data, u8 *crc)
{
- u8 val = (usb6fire_fw_ihex_nibble(data[0]) << 4) |
- usb6fire_fw_ihex_nibble(data[1]);
+ u8 val = 0;
+ int hval;
+
+ hval = hex_to_bin(data[0]);
+ if (hval >= 0)
+ val |= (hval << 4);
+
+ hval = hex_to_bin(data[1]);
+ if (hval >= 0)
+ val |= hval;
+
*crc += val;
return val;
}
--
1.7.6.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH] fat: don't use custom hex_to_bin()
2011-09-23 11:32 [PATCH] alsa: 6fire: don't use custom hex_to_bin() Andy Shevchenko
@ 2011-09-23 11:32 ` Andy Shevchenko
2011-09-23 12:05 ` Denys Vlasenko
2011-09-23 13:22 ` [PATCH] alsa: 6fire: " Takashi Iwai
1 sibling, 1 reply; 21+ messages in thread
From: Andy Shevchenko @ 2011-09-23 11:32 UTC (permalink / raw)
To: linux-kernel; +Cc: Andy Shevchenko, OGAWA Hirofumi
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---
fs/fat/namei_vfat.c | 22 ++++++----------------
1 files changed, 6 insertions(+), 16 deletions(-)
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index bb3f29c..09cec4c 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -21,6 +21,8 @@
#include <linux/slab.h>
#include <linux/buffer_head.h>
#include <linux/namei.h>
+#include <linux/kernel.h>
+
#include "fat.h"
/*
@@ -505,7 +507,6 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
struct nls_table *nls)
{
const unsigned char *ip;
- unsigned char nc;
unsigned char *op;
unsigned int ec;
int i, k, fill;
@@ -530,21 +531,10 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
return -EINVAL;
ec = 0;
for (k = 1; k < 5; k++) {
- nc = ip[k];
- ec <<= 4;
- if (nc >= '0' && nc <= '9') {
- ec |= nc - '0';
- continue;
- }
- if (nc >= 'a' && nc <= 'f') {
- ec |= nc - ('a' - 10);
- continue;
- }
- if (nc >= 'A' && nc <= 'F') {
- ec |= nc - ('A' - 10);
- continue;
- }
- return -EINVAL;
+ int val = hex_to_bin(ip[k]);
+ if (val < 0)
+ return -EINVAL;
+ ec = (ec << 4) | val;
}
*op++ = ec & 0xFF;
*op++ = ec >> 8;
--
1.7.6.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH] fat: don't use custom hex_to_bin()
2011-09-23 11:32 ` [PATCH] fat: " Andy Shevchenko
@ 2011-09-23 12:05 ` Denys Vlasenko
2011-09-23 12:11 ` Andy Shevchenko
2011-09-27 11:48 ` [PATCHv2] " Andy Shevchenko
0 siblings, 2 replies; 21+ messages in thread
From: Denys Vlasenko @ 2011-09-23 12:05 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-kernel, OGAWA Hirofumi
On Fri, Sep 23, 2011 at 1:32 PM, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
> ---
> fs/fat/namei_vfat.c | 22 ++++++----------------
> 1 files changed, 6 insertions(+), 16 deletions(-)
>
> diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
> index bb3f29c..09cec4c 100644
> --- a/fs/fat/namei_vfat.c
> +++ b/fs/fat/namei_vfat.c
> @@ -21,6 +21,8 @@
> #include <linux/slab.h>
> #include <linux/buffer_head.h>
> #include <linux/namei.h>
> +#include <linux/kernel.h>
> +
> #include "fat.h"
>
> /*
> @@ -505,7 +507,6 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
> struct nls_table *nls)
> {
> const unsigned char *ip;
> - unsigned char nc;
> unsigned char *op;
> unsigned int ec;
> int i, k, fill;
> @@ -530,21 +531,10 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
> return -EINVAL;
> ec = 0;
> for (k = 1; k < 5; k++) {
> - nc = ip[k];
> - ec <<= 4;
> - if (nc >= '0' && nc <= '9') {
> - ec |= nc - '0';
> - continue;
> - }
> - if (nc >= 'a' && nc <= 'f') {
> - ec |= nc - ('a' - 10);
> - continue;
> - }
> - if (nc >= 'A' && nc <= 'F') {
> - ec |= nc - ('A' - 10);
> - continue;
> - }
> - return -EINVAL;
> + int val = hex_to_bin(ip[k]);
> + if (val < 0)
> + return -EINVAL;
> + ec = (ec << 4) | val;
> }
> *op++ = ec & 0xFF;
> *op++ = ec >> 8;
Function call per byte? That's expensive!
Can't we have a function which converts many sequential bytes?
--
vda
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] fat: don't use custom hex_to_bin()
2011-09-23 12:05 ` Denys Vlasenko
@ 2011-09-23 12:11 ` Andy Shevchenko
2011-09-27 11:48 ` [PATCHv2] " Andy Shevchenko
1 sibling, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2011-09-23 12:11 UTC (permalink / raw)
To: Denys Vlasenko; +Cc: linux-kernel, OGAWA Hirofumi
On Fri, 2011-09-23 at 14:05 +0200, Denys Vlasenko wrote:
> On Fri, Sep 23, 2011 at 1:32 PM, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
> > ---
> > fs/fat/namei_vfat.c | 22 ++++++----------------
> > 1 files changed, 6 insertions(+), 16 deletions(-)
> >
> > diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
> > index bb3f29c..09cec4c 100644
> > --- a/fs/fat/namei_vfat.c
> > +++ b/fs/fat/namei_vfat.c
> > @@ -21,6 +21,8 @@
> > #include <linux/slab.h>
> > #include <linux/buffer_head.h>
> > #include <linux/namei.h>
> > +#include <linux/kernel.h>
> > +
> > #include "fat.h"
> >
> > /*
> > @@ -505,7 +507,6 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
> > struct nls_table *nls)
> > {
> > const unsigned char *ip;
> > - unsigned char nc;
> > unsigned char *op;
> > unsigned int ec;
> > int i, k, fill;
> > @@ -530,21 +531,10 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
> > return -EINVAL;
> > ec = 0;
> > for (k = 1; k < 5; k++) {
> > - nc = ip[k];
> > - ec <<= 4;
> > - if (nc >= '0' && nc <= '9') {
> > - ec |= nc - '0';
> > - continue;
> > - }
> > - if (nc >= 'a' && nc <= 'f') {
> > - ec |= nc - ('a' - 10);
> > - continue;
> > - }
> > - if (nc >= 'A' && nc <= 'F') {
> > - ec |= nc - ('A' - 10);
> > - continue;
> > - }
> > - return -EINVAL;
> > + int val = hex_to_bin(ip[k]);
> > + if (val < 0)
> > + return -EINVAL;
> > + ec = (ec << 4) | val;
> > }
> > *op++ = ec & 0xFF;
> > *op++ = ec >> 8;
>
> Function call per byte?
4 times in our case per 16 bit.
> That's expensive!
By the way, you can do those optimizations across the kernel. There are
dozens of places where one or few bytes are converted per half-byte.
> Can't we have a function which converts many sequential bytes?
We have one, but it doesn't return any error. We could wait until Mimi
integrates his patch series.
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] alsa: 6fire: don't use custom hex_to_bin()
2011-09-23 11:32 [PATCH] alsa: 6fire: don't use custom hex_to_bin() Andy Shevchenko
2011-09-23 11:32 ` [PATCH] fat: " Andy Shevchenko
@ 2011-09-23 13:22 ` Takashi Iwai
1 sibling, 0 replies; 21+ messages in thread
From: Takashi Iwai @ 2011-09-23 13:22 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-kernel, alsa-devel
At Fri, 23 Sep 2011 14:32:11 +0300,
Andy Shevchenko wrote:
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Takashi Iwai <tiwai@suse.de>
> Cc: alsa-devel@alsa-project.org
Applied now. Thanks.
Takashi
> ---
> sound/usb/6fire/firmware.c | 25 ++++++++++++-------------
> 1 files changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/sound/usb/6fire/firmware.c b/sound/usb/6fire/firmware.c
> index 3ebbdec..3b5f517 100644
> --- a/sound/usb/6fire/firmware.c
> +++ b/sound/usb/6fire/firmware.c
> @@ -17,6 +17,7 @@
> #include <linux/firmware.h>
> #include <linux/module.h>
> #include <linux/bitrev.h>
> +#include <linux/kernel.h>
>
> #include "firmware.h"
> #include "chip.h"
> @@ -60,21 +61,19 @@ struct ihex_record {
> unsigned int txt_offset; /* current position in txt_data */
> };
>
> -static u8 usb6fire_fw_ihex_nibble(const u8 n)
> -{
> - if (n >= '0' && n <= '9')
> - return n - '0';
> - else if (n >= 'A' && n <= 'F')
> - return n - ('A' - 10);
> - else if (n >= 'a' && n <= 'f')
> - return n - ('a' - 10);
> - return 0;
> -}
> -
> static u8 usb6fire_fw_ihex_hex(const u8 *data, u8 *crc)
> {
> - u8 val = (usb6fire_fw_ihex_nibble(data[0]) << 4) |
> - usb6fire_fw_ihex_nibble(data[1]);
> + u8 val = 0;
> + int hval;
> +
> + hval = hex_to_bin(data[0]);
> + if (hval >= 0)
> + val |= (hval << 4);
> +
> + hval = hex_to_bin(data[1]);
> + if (hval >= 0)
> + val |= hval;
> +
> *crc += val;
> return val;
> }
> --
> 1.7.6.3
>
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCHv2] fat: don't use custom hex_to_bin()
2011-09-23 12:05 ` Denys Vlasenko
2011-09-23 12:11 ` Andy Shevchenko
@ 2011-09-27 11:48 ` Andy Shevchenko
2011-09-27 17:19 ` OGAWA Hirofumi
1 sibling, 1 reply; 21+ messages in thread
From: Andy Shevchenko @ 2011-09-27 11:48 UTC (permalink / raw)
To: linux-kernel, Denys Vlasenko; +Cc: Andy Shevchenko, OGAWA Hirofumi
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---
fs/fat/namei_vfat.c | 30 ++++++++----------------------
1 files changed, 8 insertions(+), 22 deletions(-)
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index bb3f29c..cf0fd96 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -21,6 +21,8 @@
#include <linux/slab.h>
#include <linux/buffer_head.h>
#include <linux/namei.h>
+#include <linux/kernel.h>
+
#include "fat.h"
/*
@@ -505,10 +507,8 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
struct nls_table *nls)
{
const unsigned char *ip;
- unsigned char nc;
unsigned char *op;
- unsigned int ec;
- int i, k, fill;
+ int i, rc, fill;
int charlen;
if (utf8) {
@@ -528,26 +528,12 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
if (escape && (*ip == ':')) {
if (i > len - 5)
return -EINVAL;
- ec = 0;
- for (k = 1; k < 5; k++) {
- nc = ip[k];
- ec <<= 4;
- if (nc >= '0' && nc <= '9') {
- ec |= nc - '0';
- continue;
- }
- if (nc >= 'a' && nc <= 'f') {
- ec |= nc - ('a' - 10);
- continue;
- }
- if (nc >= 'A' && nc <= 'F') {
- ec |= nc - ('A' - 10);
- continue;
- }
+
+ rc = hex2bin(op, ip + 1, 2);
+ if (rc < 0)
return -EINVAL;
- }
- *op++ = ec & 0xFF;
- *op++ = ec >> 8;
+
+ op += 2;
ip += 5;
i += 5;
} else {
--
1.7.6.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCHv2] fat: don't use custom hex_to_bin()
2011-09-27 11:48 ` [PATCHv2] " Andy Shevchenko
@ 2011-09-27 17:19 ` OGAWA Hirofumi
2011-09-27 17:52 ` Andy Shevchenko
2011-09-27 18:06 ` Andy Shevchenko
0 siblings, 2 replies; 21+ messages in thread
From: OGAWA Hirofumi @ 2011-09-27 17:19 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-kernel, Denys Vlasenko
Andy Shevchenko <andriy.shevchenko@linux.intel.com> writes:
Looks good to me.
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Or if it's needed, I'll apply this to fat tree.
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
> ---
> fs/fat/namei_vfat.c | 30 ++++++++----------------------
> 1 files changed, 8 insertions(+), 22 deletions(-)
>
> diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
> index bb3f29c..cf0fd96 100644
> --- a/fs/fat/namei_vfat.c
> +++ b/fs/fat/namei_vfat.c
> @@ -21,6 +21,8 @@
> #include <linux/slab.h>
> #include <linux/buffer_head.h>
> #include <linux/namei.h>
> +#include <linux/kernel.h>
> +
> #include "fat.h"
>
> /*
> @@ -505,10 +507,8 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
> struct nls_table *nls)
> {
> const unsigned char *ip;
> - unsigned char nc;
> unsigned char *op;
> - unsigned int ec;
> - int i, k, fill;
> + int i, rc, fill;
> int charlen;
>
> if (utf8) {
> @@ -528,26 +528,12 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
> if (escape && (*ip == ':')) {
> if (i > len - 5)
> return -EINVAL;
> - ec = 0;
> - for (k = 1; k < 5; k++) {
> - nc = ip[k];
> - ec <<= 4;
> - if (nc >= '0' && nc <= '9') {
> - ec |= nc - '0';
> - continue;
> - }
> - if (nc >= 'a' && nc <= 'f') {
> - ec |= nc - ('a' - 10);
> - continue;
> - }
> - if (nc >= 'A' && nc <= 'F') {
> - ec |= nc - ('A' - 10);
> - continue;
> - }
> +
> + rc = hex2bin(op, ip + 1, 2);
> + if (rc < 0)
> return -EINVAL;
> - }
> - *op++ = ec & 0xFF;
> - *op++ = ec >> 8;
> +
> + op += 2;
> ip += 5;
> i += 5;
> } else {
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCHv2] fat: don't use custom hex_to_bin()
2011-09-27 17:19 ` OGAWA Hirofumi
@ 2011-09-27 17:52 ` Andy Shevchenko
2011-09-27 18:06 ` Andy Shevchenko
1 sibling, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2011-09-27 17:52 UTC (permalink / raw)
To: OGAWA Hirofumi; +Cc: Andy Shevchenko, linux-kernel, Denys Vlasenko
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 4284 bytes --]
On Tue, Sep 27, 2011 at 8:19 PM, OGAWA Hirofumi
<hirofumi@mail.parknet.co.jp> wrote:
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> writes:
>
> Looks good to me.
>
> Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
>
> Or if it's needed, I'll apply this to fat tree.
I guess so. Thanks!
>
>> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>> Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
>> ---
>> Â fs/fat/namei_vfat.c | Â 30 ++++++++----------------------
>> Â 1 files changed, 8 insertions(+), 22 deletions(-)
>>
>> diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
>> index bb3f29c..cf0fd96 100644
>> --- a/fs/fat/namei_vfat.c
>> +++ b/fs/fat/namei_vfat.c
>> @@ -21,6 +21,8 @@
>> Â #include <linux/slab.h>
>> Â #include <linux/buffer_head.h>
>> Â #include <linux/namei.h>
>> +#include <linux/kernel.h>
>> +
>> Â #include "fat.h"
>>
>> Â /*
>> @@ -505,10 +507,8 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
>> Â Â Â Â Â Â struct nls_table *nls)
>> Â {
>> Â Â Â const unsigned char *ip;
>> - Â Â unsigned char nc;
>> Â Â Â unsigned char *op;
>> - Â Â unsigned int ec;
>> - Â Â int i, k, fill;
>> + Â Â int i, rc, fill;
>> Â Â Â int charlen;
>>
>> Â Â Â if (utf8) {
>> @@ -528,26 +528,12 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (escape && (*ip == ':')) {
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (i > len - 5)
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return -EINVAL;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ec = 0;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â for (k = 1; k < 5; k++) {
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â nc = ip[k];
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ec <<= 4;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (nc >= '0' && nc <= '9') {
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ec |= nc - '0';
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (nc >= 'a' && nc <= 'f') {
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ec |= nc - ('a' - 10);
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (nc >= 'A' && nc <= 'F') {
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ec |= nc - ('A' - 10);
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rc = hex2bin(op, ip + 1, 2);
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (rc < 0)
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return -EINVAL;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *op++ = ec & 0xFF;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *op++ = ec >> 8;
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â op += 2;
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ip += 5;
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â i += 5;
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } else {
>
> --
> OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>
--
With Best Regards,
Andy Shevchenko
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCHv2] fat: don't use custom hex_to_bin()
2011-09-27 17:19 ` OGAWA Hirofumi
2011-09-27 17:52 ` Andy Shevchenko
@ 2011-09-27 18:06 ` Andy Shevchenko
2011-09-27 23:15 ` OGAWA Hirofumi
1 sibling, 1 reply; 21+ messages in thread
From: Andy Shevchenko @ 2011-09-27 18:06 UTC (permalink / raw)
To: OGAWA Hirofumi; +Cc: Andy Shevchenko, linux-kernel, Denys Vlasenko
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 4622 bytes --]
On Tue, Sep 27, 2011 at 8:19 PM, OGAWA Hirofumi
<hirofumi@mail.parknet.co.jp> wrote:
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> writes:
>
> Looks good to me.
>
> Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
>
> Or if it's needed, I'll apply this to fat tree.
Please, hold on. Read my comments below.
>> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>> Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
>> ---
>> Â fs/fat/namei_vfat.c | Â 30 ++++++++----------------------
>> Â 1 files changed, 8 insertions(+), 22 deletions(-)
>>
>> diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
>> index bb3f29c..cf0fd96 100644
>> --- a/fs/fat/namei_vfat.c
>> +++ b/fs/fat/namei_vfat.c
>> @@ -21,6 +21,8 @@
>> Â #include <linux/slab.h>
>> Â #include <linux/buffer_head.h>
>> Â #include <linux/namei.h>
>> +#include <linux/kernel.h>
>> +
>> Â #include "fat.h"
>>
>> Â /*
>> @@ -505,10 +507,8 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
>> Â Â Â Â Â Â struct nls_table *nls)
>> Â {
>> Â Â Â const unsigned char *ip;
>> - Â Â unsigned char nc;
>> Â Â Â unsigned char *op;
>> - Â Â unsigned int ec;
>> - Â Â int i, k, fill;
>> + Â Â int i, rc, fill;
>> Â Â Â int charlen;
>>
>> Â Â Â if (utf8) {
>> @@ -528,26 +528,12 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (escape && (*ip == ':')) {
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (i > len - 5)
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return -EINVAL;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ec = 0;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â for (k = 1; k < 5; k++) {
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â nc = ip[k];
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ec <<= 4;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (nc >= '0' && nc <= '9') {
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ec |= nc - '0';
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (nc >= 'a' && nc <= 'f') {
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ec |= nc - ('a' - 10);
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (nc >= 'A' && nc <= 'F') {
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ec |= nc - ('A' - 10);
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rc = hex2bin(op, ip + 1, 2);
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (rc < 0)
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return -EINVAL;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *op++ = ec & 0xFF;
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *op++ = ec >> 8;
Actually here we will change endianess.
So, my question is what endianess is right here? If the original code
okay, then patch should be rewritten like this:
rc = hex2bin(op++, ip + 3, 1);
if (rc < 0)
return -EINVAL;
rc = hex2bin(op++, ip + 1, 1);
if (rc < 0)
return -EINVAL;
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â op += 2;
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ip += 5;
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â i += 5;
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } else {
>
> --
> OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>
--
With Best Regards,
Andy Shevchenko
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCHv2] fat: don't use custom hex_to_bin()
2011-09-27 18:06 ` Andy Shevchenko
@ 2011-09-27 23:15 ` OGAWA Hirofumi
2011-09-29 13:07 ` Andy Shevchenko
2011-09-29 13:15 ` [PATCHv3] " Andy Shevchenko
0 siblings, 2 replies; 21+ messages in thread
From: OGAWA Hirofumi @ 2011-09-27 23:15 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Andy Shevchenko, linux-kernel, Denys Vlasenko
Andy Shevchenko <andy.shevchenko@gmail.com> writes:
> Actually here we will change endianess.
> So, my question is what endianess is right here? If the original code
> okay, then patch should be rewritten like this:
>
> rc = hex2bin(op++, ip + 3, 1);
> if (rc < 0)
> return -EINVAL;
>
> rc = hex2bin(op++, ip + 1, 1);
> if (rc < 0)
> return -EINVAL;
Original code may work only for little endian. Well, anyway, the output
should be wchar_t (u16) of native endian.
So, I think it should be something like
u8 uc[2];
if (hex2bin(uc, ip + 1, 2) < 0)
return -EINVAL;
*(wchar_t *)op = uc[0] << 8 | uc[1];
This should be readable more.
Thanks.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCHv2] fat: don't use custom hex_to_bin()
2011-09-27 23:15 ` OGAWA Hirofumi
@ 2011-09-29 13:07 ` Andy Shevchenko
2011-09-29 14:43 ` OGAWA Hirofumi
2011-09-29 13:15 ` [PATCHv3] " Andy Shevchenko
1 sibling, 1 reply; 21+ messages in thread
From: Andy Shevchenko @ 2011-09-29 13:07 UTC (permalink / raw)
To: OGAWA Hirofumi; +Cc: Andy Shevchenko, linux-kernel, Denys Vlasenko
On Wed, 2011-09-28 at 08:15 +0900, OGAWA Hirofumi wrote:
> Andy Shevchenko <andy.shevchenko@gmail.com> writes:
>
> > Actually here we will change endianess.
> > So, my question is what endianess is right here? If the original code
> > okay, then patch should be rewritten like this:
> >
> > rc = hex2bin(op++, ip + 3, 1);
> > if (rc < 0)
> > return -EINVAL;
> >
> > rc = hex2bin(op++, ip + 1, 1);
> > if (rc < 0)
> > return -EINVAL;
>
> Original code may work only for little endian. Well, anyway, the output
> should be wchar_t (u16) of native endian.
> So, I think it should be something like
>
> u8 uc[2];
> if (hex2bin(uc, ip + 1, 2) < 0)
> return -EINVAL;
> *(wchar_t *)op = uc[0] << 8 | uc[1];
> This should be readable more.
It might be so, but it's not okay to do such constructions in C
fs/fat/namei_vfat.c:535:1: warning: ISO C90 forbids mixed declarations
and code [-Wdeclaration-after-statement]
So, I will resend patch as I proposed with additional comments.
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCHv3] fat: don't use custom hex_to_bin()
2011-09-27 23:15 ` OGAWA Hirofumi
2011-09-29 13:07 ` Andy Shevchenko
@ 2011-09-29 13:15 ` Andy Shevchenko
2011-09-29 14:51 ` OGAWA Hirofumi
1 sibling, 1 reply; 21+ messages in thread
From: Andy Shevchenko @ 2011-09-29 13:15 UTC (permalink / raw)
To: linux-kernel; +Cc: Andy Shevchenko, OGAWA Hirofumi
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---
fs/fat/namei_vfat.c | 37 +++++++++++++++----------------------
1 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index bb3f29c..7deb604 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -21,6 +21,8 @@
#include <linux/slab.h>
#include <linux/buffer_head.h>
#include <linux/namei.h>
+#include <linux/kernel.h>
+
#include "fat.h"
/*
@@ -505,10 +507,8 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
struct nls_table *nls)
{
const unsigned char *ip;
- unsigned char nc;
unsigned char *op;
- unsigned int ec;
- int i, k, fill;
+ int i, rc, fill;
int charlen;
if (utf8) {
@@ -528,26 +528,19 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
if (escape && (*ip == ':')) {
if (i > len - 5)
return -EINVAL;
- ec = 0;
- for (k = 1; k < 5; k++) {
- nc = ip[k];
- ec <<= 4;
- if (nc >= '0' && nc <= '9') {
- ec |= nc - '0';
- continue;
- }
- if (nc >= 'a' && nc <= 'f') {
- ec |= nc - ('a' - 10);
- continue;
- }
- if (nc >= 'A' && nc <= 'F') {
- ec |= nc - ('A' - 10);
- continue;
- }
+
+ /* The ip contains 2 bytes in little
+ * endian format. We need to get them
+ * in native endian. */
+
+ rc = hex2bin(op++, ip + 3, 1);
+ if (rc < 0)
+ return -EINVAL;
+
+ rc = hex2bin(op++, ip + 1, 1);
+ if (rc < 0)
return -EINVAL;
- }
- *op++ = ec & 0xFF;
- *op++ = ec >> 8;
+
ip += 5;
i += 5;
} else {
--
1.7.6.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCHv2] fat: don't use custom hex_to_bin()
2011-09-29 13:07 ` Andy Shevchenko
@ 2011-09-29 14:43 ` OGAWA Hirofumi
2011-09-29 14:54 ` Andy Shevchenko
2011-09-29 15:10 ` [PATCHv4] " Andy Shevchenko
0 siblings, 2 replies; 21+ messages in thread
From: OGAWA Hirofumi @ 2011-09-29 14:43 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Andy Shevchenko, linux-kernel, Denys Vlasenko
Andy Shevchenko <andriy.shevchenko@linux.intel.com> writes:
>> So, I think it should be something like
>>
>> u8 uc[2];
>> if (hex2bin(uc, ip + 1, 2) < 0)
>> return -EINVAL;
>> *(wchar_t *)op = uc[0] << 8 | uc[1];
>> This should be readable more.
> It might be so, but it's not okay to do such constructions in C
>
> fs/fat/namei_vfat.c:535:1: warning: ISO C90 forbids mixed declarations
> and code [-Wdeclaration-after-statement]
>
> So, I will resend patch as I proposed with additional comments.
I guess you just did copy&paste. "u8 uc[2];" part should be before
statement as C90.
I.e.
if (escape && (*ip == ':')) {
u8 uc[2];
if (i > len - 5)
return -EINVAL;
if (hex2bin(uc, ip + 1, 2) < 0)
return -EINVAL;
*(wchar_t *)op = uc[0] << 8 | uc[1];
op += 2;
ip += 5;
i += 5;
} else {
This should be work?
Thanks.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCHv3] fat: don't use custom hex_to_bin()
2011-09-29 13:15 ` [PATCHv3] " Andy Shevchenko
@ 2011-09-29 14:51 ` OGAWA Hirofumi
0 siblings, 0 replies; 21+ messages in thread
From: OGAWA Hirofumi @ 2011-09-29 14:51 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-kernel
Andy Shevchenko <andriy.shevchenko@linux.intel.com> writes:
> + /* The ip contains 2 bytes in little
> + * endian format. We need to get them
> + * in native endian. */
> +
> + rc = hex2bin(op++, ip + 3, 1);
> + if (rc < 0)
> + return -EINVAL;
> +
> + rc = hex2bin(op++, ip + 1, 1);
> + if (rc < 0)
> return -EINVAL;
> - }
> - *op++ = ec & 0xFF;
> - *op++ = ec >> 8;
> +
It will not work for big endian arch correctly like original code.
"ip" is made like following,
if (uni_xlate == 1) {
*op++ = ':';
op = pack_hex_byte(op, ec >> 8);
op = pack_hex_byte(op, ec);
len -= 5;
} else {
Maybe, my explanation was not good. Like above, "ip" format is like
":1234" (can say big endian, it's the string though), so, this code made
a unicode char (op) as little endian.
Thanks.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCHv2] fat: don't use custom hex_to_bin()
2011-09-29 14:43 ` OGAWA Hirofumi
@ 2011-09-29 14:54 ` Andy Shevchenko
2011-09-29 15:19 ` OGAWA Hirofumi
2011-09-29 15:10 ` [PATCHv4] " Andy Shevchenko
1 sibling, 1 reply; 21+ messages in thread
From: Andy Shevchenko @ 2011-09-29 14:54 UTC (permalink / raw)
To: OGAWA Hirofumi; +Cc: Andy Shevchenko, linux-kernel, Denys Vlasenko
On Thu, 2011-09-29 at 23:43 +0900, OGAWA Hirofumi wrote:
> I guess you just did copy&paste. "u8 uc[2];" part should be before
> statement as C90.
>
> I.e.
>
> if (escape && (*ip == ':')) {
> u8 uc[2];
>
> if (i > len - 5)
> return -EINVAL;
>
> if (hex2bin(uc, ip + 1, 2) < 0)
> return -EINVAL;
> *(wchar_t *)op = uc[0] << 8 | uc[1];
Actually, why do not use
*(wchar_t *)op++ = ...
instead of additional op+=2?
>
> op += 2;
> ip += 5;
> i += 5;
> } else {
>
> This should be work?
Oh, my bad! So much minor mistakes last time. Really need vacation.
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCHv4] fat: don't use custom hex_to_bin()
2011-09-29 14:43 ` OGAWA Hirofumi
2011-09-29 14:54 ` Andy Shevchenko
@ 2011-09-29 15:10 ` Andy Shevchenko
2011-09-29 15:37 ` Joe Perches
1 sibling, 1 reply; 21+ messages in thread
From: Andy Shevchenko @ 2011-09-29 15:10 UTC (permalink / raw)
To: linux-kernel; +Cc: Andy Shevchenko, OGAWA Hirofumi
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---
fs/fat/namei_vfat.c | 32 ++++++++++----------------------
1 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index bb3f29c..93f7009 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -21,6 +21,8 @@
#include <linux/slab.h>
#include <linux/buffer_head.h>
#include <linux/namei.h>
+#include <linux/kernel.h>
+
#include "fat.h"
/*
@@ -505,10 +507,8 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
struct nls_table *nls)
{
const unsigned char *ip;
- unsigned char nc;
unsigned char *op;
- unsigned int ec;
- int i, k, fill;
+ int i, fill;
int charlen;
if (utf8) {
@@ -526,28 +526,16 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
*outlen += 1)
{
if (escape && (*ip == ':')) {
+ u8 uc[2];
+
if (i > len - 5)
return -EINVAL;
- ec = 0;
- for (k = 1; k < 5; k++) {
- nc = ip[k];
- ec <<= 4;
- if (nc >= '0' && nc <= '9') {
- ec |= nc - '0';
- continue;
- }
- if (nc >= 'a' && nc <= 'f') {
- ec |= nc - ('a' - 10);
- continue;
- }
- if (nc >= 'A' && nc <= 'F') {
- ec |= nc - ('A' - 10);
- continue;
- }
+
+ if (hex2bin(uc, ip + 1, 2) < 0)
return -EINVAL;
- }
- *op++ = ec & 0xFF;
- *op++ = ec >> 8;
+
+ *(wchar_t *)op++ = uc[0] << 8 | uc[1];
+
ip += 5;
i += 5;
} else {
--
1.7.6.3
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCHv2] fat: don't use custom hex_to_bin()
2011-09-29 14:54 ` Andy Shevchenko
@ 2011-09-29 15:19 ` OGAWA Hirofumi
0 siblings, 0 replies; 21+ messages in thread
From: OGAWA Hirofumi @ 2011-09-29 15:19 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Andy Shevchenko, linux-kernel, Denys Vlasenko
Andy Shevchenko <andriy.shevchenko@linux.intel.com> writes:
> On Thu, 2011-09-29 at 23:43 +0900, OGAWA Hirofumi wrote:
>> I guess you just did copy&paste. "u8 uc[2];" part should be before
>> statement as C90.
>>
>> I.e.
>>
>> if (escape && (*ip == ':')) {
>> u8 uc[2];
>>
>> if (i > len - 5)
>> return -EINVAL;
>>
>> if (hex2bin(uc, ip + 1, 2) < 0)
>> return -EINVAL;
>> *(wchar_t *)op = uc[0] << 8 | uc[1];
> Actually, why do not use
> *(wchar_t *)op++ = ...
> instead of additional op+=2?
IMO, the reason would be, complex oneliner is possible to mistake. Well,
anyway, it doesn't work. It actually increments 1 byte as "char *", not
2 bytes as "wchar_t *".
>>
>> op += 2;
>> ip += 5;
>> i += 5;
>> } else {
>>
>> This should be work?
> Oh, my bad! So much minor mistakes last time. Really need vacation.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCHv4] fat: don't use custom hex_to_bin()
2011-09-29 15:10 ` [PATCHv4] " Andy Shevchenko
@ 2011-09-29 15:37 ` Joe Perches
2011-09-29 18:27 ` OGAWA Hirofumi
0 siblings, 1 reply; 21+ messages in thread
From: Joe Perches @ 2011-09-29 15:37 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-kernel, OGAWA Hirofumi
On Thu, 2011-09-29 at 18:10 +0300, Andy Shevchenko wrote:
> diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
[]
> @@ -526,28 +526,16 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
> *outlen += 1)
> {
> if (escape && (*ip == ':')) {
> + u8 uc[2];
> +
> if (i > len - 5)
> return -EINVAL;
> - ec = 0;
> - for (k = 1; k < 5; k++) {
> - nc = ip[k];
> - ec <<= 4;
> - if (nc >= '0' && nc <= '9') {
> - ec |= nc - '0';
> - continue;
> - }
> - if (nc >= 'a' && nc <= 'f') {
> - ec |= nc - ('a' - 10);
> - continue;
> - }
> - if (nc >= 'A' && nc <= 'F') {
> - ec |= nc - ('A' - 10);
> - continue;
> - }
> +
> + if (hex2bin(uc, ip + 1, 2) < 0)
> return -EINVAL;
> - }
> - *op++ = ec & 0xFF;
> - *op++ = ec >> 8;
> +
> + *(wchar_t *)op++ = uc[0] << 8 | uc[1];
perhaps:
__le16 foo;
if (hex2bin((u8 *)&foo, ip + 1, 2) < 0)
return -EINVAL;
*(u16 *)op = le16_to_cpu(foo);
op += 2;
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCHv4] fat: don't use custom hex_to_bin()
2011-09-29 15:37 ` Joe Perches
@ 2011-09-29 18:27 ` OGAWA Hirofumi
2011-09-29 18:41 ` Joe Perches
0 siblings, 1 reply; 21+ messages in thread
From: OGAWA Hirofumi @ 2011-09-29 18:27 UTC (permalink / raw)
To: Joe Perches; +Cc: Andy Shevchenko, linux-kernel
Joe Perches <joe@perches.com> writes:
>> +
>> + if (hex2bin(uc, ip + 1, 2) < 0)
>> return -EINVAL;
>> - }
>> - *op++ = ec & 0xFF;
>> - *op++ = ec >> 8;
>> +
>> + *(wchar_t *)op++ = uc[0] << 8 | uc[1];
>
> perhaps:
>
> __le16 foo;
>
> if (hex2bin((u8 *)&foo, ip + 1, 2) < 0)
> return -EINVAL;
> *(u16 *)op = le16_to_cpu(foo);
>
> op += 2;
I also thought about it. But I think it is not so good, like you had
mistake. It should actually be "__be16 foo" and "be16_to_cpu()".
If we used sscanf() instead of hex2bin(), I might agree to use
"le16_to_cpu()" though.
Thanks.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCHv4] fat: don't use custom hex_to_bin()
2011-09-29 18:27 ` OGAWA Hirofumi
@ 2011-09-29 18:41 ` Joe Perches
2011-09-29 19:35 ` OGAWA Hirofumi
0 siblings, 1 reply; 21+ messages in thread
From: Joe Perches @ 2011-09-29 18:41 UTC (permalink / raw)
To: OGAWA Hirofumi; +Cc: Andy Shevchenko, linux-kernel
On Fri, 2011-09-30 at 03:27 +0900, OGAWA Hirofumi wrote:
> Joe Perches <joe@perches.com> writes:
>
> >> +
> >> + if (hex2bin(uc, ip + 1, 2) < 0)
> >> return -EINVAL;
> >> - }
> >> - *op++ = ec & 0xFF;
> >> - *op++ = ec >> 8;
> >> +
> >> + *(wchar_t *)op++ = uc[0] << 8 | uc[1];
> >
> > perhaps:
> >
> > __le16 foo;
> >
> > if (hex2bin((u8 *)&foo, ip + 1, 2) < 0)
> > return -EINVAL;
> > *(u16 *)op = le16_to_cpu(foo);
> >
> > op += 2;
>
> I also thought about it. But I think it is not so good, like you had
> mistake. It should actually be "__be16 foo" and "be16_to_cpu()".
>
> If we used sscanf() instead of hex2bin(), I might agree to use
> "le16_to_cpu()" though.
>
> Thanks.
Funny.
I guess that's what I get for reading Andy's comment
and coding that readably.
+ /* The ip contains 2 bytes in little
+ * endian format. We need to get them
+ * in native endian. */
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCHv4] fat: don't use custom hex_to_bin()
2011-09-29 18:41 ` Joe Perches
@ 2011-09-29 19:35 ` OGAWA Hirofumi
0 siblings, 0 replies; 21+ messages in thread
From: OGAWA Hirofumi @ 2011-09-29 19:35 UTC (permalink / raw)
To: Joe Perches; +Cc: Andy Shevchenko, linux-kernel
Joe Perches <joe@perches.com> writes:
>> > perhaps:
>> >
>> > __le16 foo;
>> >
>> > if (hex2bin((u8 *)&foo, ip + 1, 2) < 0)
>> > return -EINVAL;
>> > *(u16 *)op = le16_to_cpu(foo);
>> >
>> > op += 2;
>>
>> I also thought about it. But I think it is not so good, like you had
>> mistake. It should actually be "__be16 foo" and "be16_to_cpu()".
>>
>> If we used sscanf() instead of hex2bin(), I might agree to use
>> "le16_to_cpu()" though.
>>
>> Thanks.
>
> Funny.
>
> I guess that's what I get for reading Andy's comment
> and coding that readably.
>
> + /* The ip contains 2 bytes in little
> + * endian format. We need to get them
> + * in native endian. */
In here, simply comment is wrong.
Thanks.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2011-09-29 19:35 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-23 11:32 [PATCH] alsa: 6fire: don't use custom hex_to_bin() Andy Shevchenko
2011-09-23 11:32 ` [PATCH] fat: " Andy Shevchenko
2011-09-23 12:05 ` Denys Vlasenko
2011-09-23 12:11 ` Andy Shevchenko
2011-09-27 11:48 ` [PATCHv2] " Andy Shevchenko
2011-09-27 17:19 ` OGAWA Hirofumi
2011-09-27 17:52 ` Andy Shevchenko
2011-09-27 18:06 ` Andy Shevchenko
2011-09-27 23:15 ` OGAWA Hirofumi
2011-09-29 13:07 ` Andy Shevchenko
2011-09-29 14:43 ` OGAWA Hirofumi
2011-09-29 14:54 ` Andy Shevchenko
2011-09-29 15:19 ` OGAWA Hirofumi
2011-09-29 15:10 ` [PATCHv4] " Andy Shevchenko
2011-09-29 15:37 ` Joe Perches
2011-09-29 18:27 ` OGAWA Hirofumi
2011-09-29 18:41 ` Joe Perches
2011-09-29 19:35 ` OGAWA Hirofumi
2011-09-29 13:15 ` [PATCHv3] " Andy Shevchenko
2011-09-29 14:51 ` OGAWA Hirofumi
2011-09-23 13:22 ` [PATCH] alsa: 6fire: " Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox