HID: wiimote: lock DRM mode during debugfs overwrite
authorDavid Herrmann <dh.herrmann@gmail.com>
Sun, 5 May 2013 21:13:03 +0000 (23:13 +0200)
committerJiri Kosina <jkosina@suse.cz>
Mon, 3 Jun 2013 09:07:04 +0000 (11:07 +0200)
If we write a DRM mode via debugfs, we shouldn't allow normal operations
to overwrite this DRM mode. This is important if we want to debug
3rd-party devices and we want to see what data is sent on each mode.

If we write NULL/0 as DRM, the lock is removed again so the best matching
DRM is chosen by wiimote core.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-wiimote-core.c
drivers/hid/hid-wiimote-debug.c
drivers/hid/hid-wiimote.h

index f6c4773fac568a6602713e7075b57baf68bb45a0..13963b4c8801f3c8afafd14a8759f6ab9464f1a7 100644 (file)
@@ -242,7 +242,9 @@ void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm)
 {
        __u8 cmd[3];
 
-       if (drm == WIIPROTO_REQ_NULL)
+       if (wdata->state.flags & WIIPROTO_FLAG_DRM_LOCKED)
+               drm = wdata->state.drm;
+       else if (drm == WIIPROTO_REQ_NULL)
                drm = select_drm(wdata);
 
        cmd[0] = WIIPROTO_REQ_DRM;
index 0c0deaa23774d513aee7ba810bf5db06a63f4aa2..6e76a2c3b00ab9418b602905342d2d7c853b2885 100644 (file)
@@ -154,7 +154,10 @@ static ssize_t wiidebug_drm_write(struct file *f, const char __user *u,
                i = simple_strtoul(buf, NULL, 10);
 
        spin_lock_irqsave(&dbg->wdata->state.lock, flags);
+       dbg->wdata->state.flags &= ~WIIPROTO_FLAG_DRM_LOCKED;
        wiiproto_req_drm(dbg->wdata, (__u8) i);
+       if (i != WIIPROTO_REQ_NULL)
+               dbg->wdata->state.flags |= WIIPROTO_FLAG_DRM_LOCKED;
        spin_unlock_irqrestore(&dbg->wdata->state.lock, flags);
 
        return len;
index 3a8bdb94152a308818083f1223fdaaef6b74bf23..9f857c1cd84a29e98282884bce48ad73d5740135 100644 (file)
@@ -43,6 +43,7 @@
 #define WIIPROTO_FLAG_MP_USED          0x1000
 #define WIIPROTO_FLAG_MP_ACTIVE                0x2000
 #define WIIPROTO_FLAG_EXITING          0x4000
+#define WIIPROTO_FLAG_DRM_LOCKED       0x8000
 
 #define WIIPROTO_FLAGS_LEDS (WIIPROTO_FLAG_LED1 | WIIPROTO_FLAG_LED2 | \
                                        WIIPROTO_FLAG_LED3 | WIIPROTO_FLAG_LED4)