Skip to content

Commit

Permalink
Move mutex and completion event for feature reports into context struct
Browse files Browse the repository at this point in the history
  • Loading branch information
StollD committed Dec 11, 2022
1 parent e39c67b commit 5ca2625
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
#ifndef IPTS_CONTEXT_H
#define IPTS_CONTEXT_H

#include <linux/completion.h>
#include <linux/device.h>
#include <linux/hid.h>
#include <linux/mei_cl_bus.h>
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/types.h>

Expand All @@ -24,6 +26,9 @@ struct ipts_context {

enum ipts_mode mode;

struct mutex feature_lock;
struct completion feature_event;

u8 *get_feature_report;
size_t get_feature_size;

Expand Down
13 changes: 5 additions & 8 deletions src/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#include "spec-device.h"
#include "spec-hid.h"

DECLARE_COMPLETION(on_feature);
DEFINE_MUTEX(lock_feature);

static int ipts_hid_start(struct hid_device *hid)
{
return 0;
Expand Down Expand Up @@ -125,22 +122,22 @@ static int ipts_hid_get_feature(struct ipts_context *ipts, unsigned char reportn
{
int ret;

mutex_lock(&lock_feature);
mutex_lock(&ipts->feature_lock);

memset(buf, 0, size);
buf[0] = reportnum;

ipts->get_feature_report = NULL;
ipts->get_feature_size = 0;
reinit_completion(&on_feature);
reinit_completion(&ipts->feature_event);

ret = ipts_hid_hid2me_feedback(ipts, type, buf, size);
if (ret) {
dev_err(ipts->dev, "Failed to send hid2me feedback: %d\n", ret);
goto out;
}

ret = wait_for_completion_timeout(&on_feature, msecs_to_jiffies(5000));
ret = wait_for_completion_timeout(&ipts->feature_event, msecs_to_jiffies(5000));
if (ret == 0) {
dev_warn(ipts->dev, "GET_FEATURES timed out!\n");
ret = -EIO;
Expand All @@ -161,7 +158,7 @@ static int ipts_hid_get_feature(struct ipts_context *ipts, unsigned char reportn
memcpy(buf, ipts->get_feature_report, ipts->get_feature_size);

out:
mutex_unlock(&lock_feature);
mutex_unlock(&ipts->feature_lock);
return ret;
}

Expand Down Expand Up @@ -274,7 +271,7 @@ int ipts_hid_input_data(struct ipts_context *ipts, int buffer)
ipts->get_feature_report = header->data;
ipts->get_feature_size = header->size;

complete_all(&on_feature);
complete_all(&ipts->feature_event);
return 0;
}

Expand Down
4 changes: 4 additions & 0 deletions src/mei.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/mei_cl_bus.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/stddef.h>
#include <linux/types.h>
Expand Down Expand Up @@ -63,6 +64,9 @@ static int ipts_mei_probe(struct mei_cl_device *cldev, const struct mei_cl_devic
ipts->dev = &cldev->dev;
ipts->mode = IPTS_MODE_EVENT;

mutex_init(&ipts->feature_lock);
init_completion(&ipts->feature_event);

mei_cldev_set_drvdata(cldev, ipts);

ret = ipts_control_start(ipts);
Expand Down

0 comments on commit 5ca2625

Please sign in to comment.