Skip to content

Commit

Permalink
HID: microsoft: Convert private data to be a proper struct
Browse files Browse the repository at this point in the history
In order to be able to have more than just an unsigned long worth of
private data, convert the code to allocate and use a dedicated struct.

Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: linux-input@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
Signed-off-by: Juha Kuikka <juha.kuikka@gmail.com>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Andrey Smirnov authored and Jiri Kosina committed Sep 5, 2018
1 parent 7a324b3 commit f2d3b62
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions drivers/hid/hid-microsoft.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@
#define MS_DUPLICATE_USAGES BIT(5)
#define MS_SURFACE_DIAL BIT(6)

struct ms_data {
unsigned long quirks;
};

static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
struct ms_data *ms = hid_get_drvdata(hdev);
unsigned long quirks = ms->quirks;

/*
* Microsoft Wireless Desktop Receiver (Model 1028) has
Expand Down Expand Up @@ -159,7 +164,8 @@ static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi,
struct hid_field *field, struct hid_usage *usage,
unsigned long **bit, int *max)
{
unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
struct ms_data *ms = hid_get_drvdata(hdev);
unsigned long quirks = ms->quirks;

if (quirks & MS_ERGONOMY) {
int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max);
Expand All @@ -185,7 +191,8 @@ static int ms_input_mapped(struct hid_device *hdev, struct hid_input *hi,
struct hid_field *field, struct hid_usage *usage,
unsigned long **bit, int *max)
{
unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
struct ms_data *ms = hid_get_drvdata(hdev);
unsigned long quirks = ms->quirks;

if (quirks & MS_DUPLICATE_USAGES)
clear_bit(usage->code, *bit);
Expand All @@ -196,7 +203,8 @@ static int ms_input_mapped(struct hid_device *hdev, struct hid_input *hi,
static int ms_event(struct hid_device *hdev, struct hid_field *field,
struct hid_usage *usage, __s32 value)
{
unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
struct ms_data *ms = hid_get_drvdata(hdev);
unsigned long quirks = ms->quirks;
struct input_dev *input;

if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
Expand Down Expand Up @@ -254,9 +262,16 @@ static int ms_event(struct hid_device *hdev, struct hid_field *field,
static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
unsigned long quirks = id->driver_data;
struct ms_data *ms;
int ret;

hid_set_drvdata(hdev, (void *)quirks);
ms = devm_kzalloc(&hdev->dev, sizeof(*ms), GFP_KERNEL);
if (ms == NULL)
return -ENOMEM;

ms->quirks = quirks;

hid_set_drvdata(hdev, ms);

if (quirks & MS_NOGET)
hdev->quirks |= HID_QUIRK_NOGET;
Expand Down

0 comments on commit f2d3b62

Please sign in to comment.