Skip to contentSkip to conversation

mfd: wm831x: fix broken wm831x_unique_id_show

PATCH Applied Rasmus Villemoes 3 participants 3 messages Dec 5, 2015 – Dec 9, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mfd: wm831x: fix broken wm831x_unique_id_show

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.

---
 drivers/mfd/wm831x-otp.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/mfd/wm831x-otp.c +2 -8
index b90f3e06b6c9..ebac0027f8e0 100644
@@ -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);
Signature · 1 line
2.6.1
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Rasmus Villemoes

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.

---

Thanks,
Charles

Applied
#2 lore raw
In reply to Rasmus Villemoes
Quoted 5 lines · Rasmus Villemoes

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".

Quoted 7 lines

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

---
 drivers/mfd/wm831x-otp.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

Applied, thanks.

Quoted 27 lines
drivers/mfd/wm831x-otp.c +2 -8
index b90f3e06b6c9..ebac0027f8e0 100644
@@ -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);
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog