Skip to contentSkip to conversation

hid-wiimote: print small buffers via %*phC

PATCH In review Andy Shevchenko 2 participants 2 messages Sep 3, 2013

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

PATCH v2 1/1 hid-wiimote: print small buffers via %*phC

Instead of passing each byte through stack let's use %*phC specifier to dump buffer as a hex string.

---
 drivers/hid/hid-wiimote-core.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/hid/hid-wiimote-core.c +6 -11
index 6602098..abb20db 100644
@@ -441,8 +441,7 @@ static __u8 wiimote_cmd_read_ext(struct wiimote_data *wdata, __u8 *rmem)
 	if (ret != 6)
 		return WIIMOTE_EXT_NONE;
 
-	hid_dbg(wdata->hdev, "extension ID: %02x:%02x %02x:%02x %02x:%02x\n",
-		rmem[0], rmem[1], rmem[2], rmem[3], rmem[4], rmem[5]);
+	hid_dbg(wdata->hdev, "extension ID: %6phC\n", rmem);
 
 	if (rmem[0] == 0xff && rmem[1] == 0xff && rmem[2] == 0xff &&
 	    rmem[3] == 0xff && rmem[4] == 0xff && rmem[5] == 0xff)
@@ -512,14 +511,12 @@ static bool wiimote_cmd_read_mp(struct wiimote_data *wdata, __u8 *rmem)
 	if (ret != 6)
 		return false;
 
-	hid_dbg(wdata->hdev, "motion plus ID: %02x:%02x %02x:%02x %02x:%02x\n",
-		rmem[0], rmem[1], rmem[2], rmem[3], rmem[4], rmem[5]);
+	hid_dbg(wdata->hdev, "motion plus ID: %6phC\n", rmem);
 
 	if (rmem[5] == 0x05)
 		return true;
 
-	hid_info(wdata->hdev, "unknown motion plus ID: %02x:%02x %02x:%02x %02x:%02x\n",
-		 rmem[0], rmem[1], rmem[2], rmem[3], rmem[4], rmem[5]);
+	hid_info(wdata->hdev, "unknown motion plus ID: %6phC\n", rmem);
 
 	return false;
 }
@@ -535,8 +532,7 @@ static __u8 wiimote_cmd_read_mp_mapped(struct wiimote_data *wdata)
 	if (ret != 6)
 		return WIIMOTE_MP_NONE;
 
-	hid_dbg(wdata->hdev, "mapped motion plus ID: %02x:%02x %02x:%02x %02x:%02x\n",
-		rmem[0], rmem[1], rmem[2], rmem[3], rmem[4], rmem[5]);
+	hid_dbg(wdata->hdev, "mapped motion plus ID: %6phC\n", rmem);
 
 	if (rmem[0] == 0xff && rmem[1] == 0xff && rmem[2] == 0xff &&
 	    rmem[3] == 0xff && rmem[4] == 0xff && rmem[5] == 0xff)
@@ -1128,9 +1124,8 @@ static void wiimote_init_hotplug(struct wiimote_data *wdata)
 		wiimote_ext_unload(wdata);
 
 		if (exttype == WIIMOTE_EXT_UNKNOWN) {
-			hid_info(wdata->hdev, "cannot detect extension; %02x:%02x %02x:%02x %02x:%02x\n",
-				 extdata[0], extdata[1], extdata[2],
-				 extdata[3], extdata[4], extdata[5]);
+			hid_info(wdata->hdev, "cannot detect extension; %6phC\n",
+				 extdata);
 		} else if (exttype == WIIMOTE_EXT_NONE) {
 			spin_lock_irq(&wdata->state.lock);
 			wdata->state.exttype = WIIMOTE_EXT_NONE;
Signature · 1 line
1.8.4.rc3
Reviewed-by on v2 1/1
#1 lore raw

Hi

Quoted 5 lines · Andy Shevchenko

Instead of passing each byte through stack let's use %*phC specifier to dump buffer as a hex string.

Thanks a lot. Looks much nicer now. Now also:

Thanks
David

Quoted 60 lines
---
 drivers/hid/hid-wiimote-core.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/hid/hid-wiimote-core.c +6 -12
index 6602098..abb20db 100644
@@ -441,8 +441,7 @@ static __u8 wiimote_cmd_read_ext(struct wiimote_data *wdata, __u8 *rmem)
        if (ret != 6)
                return WIIMOTE_EXT_NONE;
 
-       hid_dbg(wdata->hdev, "extension ID: %02x:%02x %02x:%02x %02x:%02x\n",
-               rmem[0], rmem[1], rmem[2], rmem[3], rmem[4], rmem[5]);
+       hid_dbg(wdata->hdev, "extension ID: %6phC\n", rmem);
 
        if (rmem[0] == 0xff && rmem[1] == 0xff && rmem[2] == 0xff &&
            rmem[3] == 0xff && rmem[4] == 0xff && rmem[5] == 0xff)
@@ -512,14 +511,12 @@ static bool wiimote_cmd_read_mp(struct wiimote_data *wdata, __u8 *rmem)
        if (ret != 6)
                return false;
 
-       hid_dbg(wdata->hdev, "motion plus ID: %02x:%02x %02x:%02x %02x:%02x\n",
-               rmem[0], rmem[1], rmem[2], rmem[3], rmem[4], rmem[5]);
+       hid_dbg(wdata->hdev, "motion plus ID: %6phC\n", rmem);
 
        if (rmem[5] == 0x05)
                return true;
 
-       hid_info(wdata->hdev, "unknown motion plus ID: %02x:%02x %02x:%02x %02x:%02x\n",
-                rmem[0], rmem[1], rmem[2], rmem[3], rmem[4], rmem[5]);
+       hid_info(wdata->hdev, "unknown motion plus ID: %6phC\n", rmem);
 
        return false;
 }
@@ -535,8 +532,7 @@ static __u8 wiimote_cmd_read_mp_mapped(struct wiimote_data *wdata)
        if (ret != 6)
                return WIIMOTE_MP_NONE;
 
-       hid_dbg(wdata->hdev, "mapped motion plus ID: %02x:%02x %02x:%02x %02x:%02x\n",
-               rmem[0], rmem[1], rmem[2], rmem[3], rmem[4], rmem[5]);
+       hid_dbg(wdata->hdev, "mapped motion plus ID: %6phC\n", rmem);
 
        if (rmem[0] == 0xff && rmem[1] == 0xff && rmem[2] == 0xff &&
            rmem[3] == 0xff && rmem[4] == 0xff && rmem[5] == 0xff)
@@ -1128,9 +1124,8 @@ static void wiimote_init_hotplug(struct wiimote_data *wdata)
                wiimote_ext_unload(wdata);
 
                if (exttype == WIIMOTE_EXT_UNKNOWN) {
-                       hid_info(wdata->hdev, "cannot detect extension; %02x:%02x %02x:%02x %02x:%02x\n",
-                                extdata[0], extdata[1], extdata[2],
-                                extdata[3], extdata[4], extdata[5]);
+                       hid_info(wdata->hdev, "cannot detect extension; %6phC\n",
+                                extdata);
                } else if (exttype == WIIMOTE_EXT_NONE) {
                        spin_lock_irq(&wdata->state.lock);
                        wdata->state.exttype = WIIMOTE_EXT_NONE;
--

1.8.4.rc3