Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1284661 > unrolled thread

[PATCH] mfd: wm831x: fix broken wm831x_unique_id_show

Started byRasmus Villemoes <linux@rasmusvillemoes.dk>
First post2015-12-06 00:50 +0100
Last post2015-12-09 10:00 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] mfd: wm831x: fix broken wm831x_unique_id_show Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-06 00:50 +0100
    Re: [PATCH] mfd: wm831x: fix broken wm831x_unique_id_show Charles Keepax <ckeepax@opensource.wolfsonmicro.com> - 2015-12-08 17:40 +0100
    Re: [PATCH] mfd: wm831x: fix broken wm831x_unique_id_show Lee Jones <lee.jones@linaro.org> - 2015-12-09 10:00 +0100

#1284661 — [PATCH] mfd: wm831x: fix broken wm831x_unique_id_show

FromRasmus Villemoes <linux@rasmusvillemoes.dk>
Date2015-12-06 00:50 +0100
Subject[PATCH] mfd: wm831x: fix broken wm831x_unique_id_show
Message-ID<qCuKu-7Bt-21@gated-at.bofh.it>
wm831x_unique_id_show currently displays an interesting pattern of '0'
and '3' characters which isn't very useful (figuring out why is left
as an exercise for the reader). Presumably "buf[i]" should have been
"id[i] & 0xff".

But while there, it is much simpler to simply use %phN and do all the
formatting at once.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/mfd/wm831x-otp.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/mfd/wm831x-otp.c b/drivers/mfd/wm831x-otp.c
index b90f3e06b6c9..ebac0027f8e0 100644
--- a/drivers/mfd/wm831x-otp.c
+++ b/drivers/mfd/wm831x-otp.c
@@ -47,20 +47,14 @@ static ssize_t wm831x_unique_id_show(struct device *dev,
 				     struct device_attribute *attr, char *buf)
 {
 	struct wm831x *wm831x = dev_get_drvdata(dev);
-	int i, rval;
+	int rval;
 	char id[WM831X_UNIQUE_ID_LEN];
-	ssize_t ret = 0;
 
 	rval = wm831x_unique_id_read(wm831x, id);
 	if (rval < 0)
 		return 0;
 
-	for (i = 0; i < WM831X_UNIQUE_ID_LEN; i++)
-		ret += sprintf(&buf[ret], "%02x", buf[i]);
-
-	ret += sprintf(&buf[ret], "\n");
-
-	return ret;
+	return sprintf(buf, "%*phN\n", WM831X_UNIQUE_ID_LEN, id);
 }
 
 static DEVICE_ATTR(unique_id, 0444, wm831x_unique_id_show, NULL);
-- 
2.6.1

--
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/

[toc] | [next] | [standalone]


#1286667

FromCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Date2015-12-08 17:40 +0100
Message-ID<qDtt0-4J4-15@gated-at.bofh.it>
In reply to#1284661
On Sun, Dec 06, 2015 at 12:39:39AM +0100, Rasmus Villemoes wrote:
> wm831x_unique_id_show currently displays an interesting pattern of '0'
> and '3' characters which isn't very useful (figuring out why is left
> as an exercise for the reader). Presumably "buf[i]" should have been
> "id[i] & 0xff".
> 
> But while there, it is much simpler to simply use %phN and do all the
> formatting at once.
> 
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---

Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>

Thanks,
Charles
--
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/

[toc] | [prev] | [next] | [standalone]


#1287200

FromLee Jones <lee.jones@linaro.org>
Date2015-12-09 10:00 +0100
Message-ID<qDILo-65j-7@gated-at.bofh.it>
In reply to#1284661
On Sun, 06 Dec 2015, Rasmus Villemoes wrote:

> wm831x_unique_id_show currently displays an interesting pattern of '0'
> and '3' characters which isn't very useful (figuring out why is left
> as an exercise for the reader). Presumably "buf[i]" should have been
> "id[i] & 0xff".
> 
> But while there, it is much simpler to simply use %phN and do all the
> formatting at once.
> 
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
>  drivers/mfd/wm831x-otp.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)

Applied, thanks.

> diff --git a/drivers/mfd/wm831x-otp.c b/drivers/mfd/wm831x-otp.c
> index b90f3e06b6c9..ebac0027f8e0 100644
> --- a/drivers/mfd/wm831x-otp.c
> +++ b/drivers/mfd/wm831x-otp.c
> @@ -47,20 +47,14 @@ static ssize_t wm831x_unique_id_show(struct device *dev,
>  				     struct device_attribute *attr, char *buf)
>  {
>  	struct wm831x *wm831x = dev_get_drvdata(dev);
> -	int i, rval;
> +	int rval;
>  	char id[WM831X_UNIQUE_ID_LEN];
> -	ssize_t ret = 0;
>  
>  	rval = wm831x_unique_id_read(wm831x, id);
>  	if (rval < 0)
>  		return 0;
>  
> -	for (i = 0; i < WM831X_UNIQUE_ID_LEN; i++)
> -		ret += sprintf(&buf[ret], "%02x", buf[i]);
> -
> -	ret += sprintf(&buf[ret], "\n");
> -
> -	return ret;
> +	return sprintf(buf, "%*phN\n", WM831X_UNIQUE_ID_LEN, id);
>  }
>  
>  static DEVICE_ATTR(unique_id, 0444, wm831x_unique_id_show, NULL);

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
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/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web