struct completion send_cmd_complete;
struct led_classdev *led_cdev;
struct hid_device *hdev;
+ bool orphan_ack_pending;
struct mutex cfg_mutex; /*ensure single synchronous output report*/
bool gp_registered;
bool rgb_registered;
return -EINVAL;
guard(mutex)(&drvdata.cfg_mutex);
+
+ /*
+ * A reply to the previous command may still be in flight. Give it a
+ * short window to arrive and be consumed before this call reinits the
+ * completion, so a late reply can't be mistaken for this command's.
+ */
+ if (drvdata.orphan_ack_pending) {
+ wait_for_completion_timeout(&drvdata.send_cmd_complete, msecs_to_jiffies(25));
+ drvdata.orphan_ack_pending = false;
+ drvdata.cmd_status = -ETIMEDOUT;
+ }
+ reinit_completion(&drvdata.send_cmd_complete);
+
/* We can't use a devm_alloc reusable buffer without side effects during suspend */
dmabuf = kzalloc(GO_S_PACKET_SIZE, GFP_KERNEL);
if (!dmabuf)
msecs_to_jiffies(timeout));
ret = ret > 0 ? drvdata.cmd_status : ret ?: -EBUSY;
- reinit_completion(&drvdata.send_cmd_complete);
+ if (ret)
+ drvdata.orphan_ack_pending = true;
+
return ret;
}