From: Michael Poole <mdpoole@troilus.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Jiri Kosina <jkosina@suse.cz>
Cc: linux-input@vger.kernel.org,
Marcel Holtmann <marcel@holtmann.org>,
linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] hid-magicmouse: Coding style and probe failure fixes.
Date: Thu, 11 Feb 2010 00:32:57 -0500 [thread overview]
Message-ID: <873a18e3qu.fsf_-_@troilus.org> (raw)
In-Reply-To: <20100210182024.GA29610@core.coreip.homeip.net> (Dmitry Torokhov's message of "Wed, 10 Feb 2010 10:20:24 -0800")
>From 04b395dbbd1ad2b836188e6f125940ae8fac6925 Mon Sep 17 00:00:00 2001
As suggested by Dmitry Torokhov on 10 Feb: Use proper values
to initialize bool configuration variables, tabs rather than
spaces, no braces for one-line else clause, __set_bit() when
the operation doesn't have to be atomic, input_set_abs_params()
rather than writing the fields directly, and call hid_hw_stop()
when appropriate to handle failures in the probe.
Signed-off-by: Michael Poole <mdpoole@troilus.org>
---
Dmitry and Jiri,
I haven't had a chance to run-test these changes yet -- hid/for-next
causes corrupt X display on my laptop, whereas v2.6.33-rc6 and -rc7 are
fine; I'm still bisecting to figure out the cause -- but this patch is
not complicated. (It does compile.)
I left the buffers for hdev->hid_output_raw_report() on the stack
because the Bluetooth HIDP code memcpy's the contents into a freshly
allocated skb.
Michael
drivers/hid/hid-magicmouse.c | 100 +++++++++++++++++-------------------------
1 files changed, 40 insertions(+), 60 deletions(-)
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index f94b3e4..4a3a94f 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -18,22 +18,22 @@
#include "hid-ids.h"
-static bool emulate_3button = 1;
+static bool emulate_3button = true;
module_param(emulate_3button, bool, 0644);
MODULE_PARM_DESC(emulate_3button, "Emulate a middle button");
static int middle_button_start = -350;
static int middle_button_stop = +350;
-static bool emulate_scroll_wheel = 1;
+static bool emulate_scroll_wheel = true;
module_param(emulate_scroll_wheel, bool, 0644);
MODULE_PARM_DESC(emulate_scroll_wheel, "Emulate a scroll wheel");
-static bool report_touches = 1;
+static bool report_touches = true;
module_param(report_touches, bool, 0644);
MODULE_PARM_DESC(report_touches, "Emit touch records (otherwise, only use them for emulation)");
-static bool report_undeciphered = 0;
+static bool report_undeciphered;
module_param(report_undeciphered, bool, 0644);
MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event");
@@ -108,9 +108,9 @@ static int magicmouse_firm_touch(struct magicmouse_sc *msc)
static void magicmouse_emit_buttons(struct magicmouse_sc *msc, int state)
{
- int last_state = test_bit(BTN_LEFT, msc->input->key) << 0 |
- test_bit(BTN_RIGHT, msc->input->key) << 1 |
- test_bit(BTN_MIDDLE, msc->input->key) << 2;
+ int last_state = test_bit(BTN_LEFT, msc->input->key) << 0 |
+ test_bit(BTN_RIGHT, msc->input->key) << 1 |
+ test_bit(BTN_MIDDLE, msc->input->key) << 2;
if (emulate_3button) {
int id;
@@ -177,7 +177,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
switch (tdata[7] & TOUCH_STATE_MASK) {
case TOUCH_STATE_START:
msc->touches[id].scroll_y = y;
- msc->scroll_accel = min_t(int, msc->scroll_accel + 1,
+ msc->scroll_accel = min_t(int, msc->scroll_accel + 1,
ARRAY_SIZE(accel_profile) - 1);
break;
case TOUCH_STATE_DRAG:
@@ -193,7 +193,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
/* Generate the input events for this touch. */
if (report_touches) {
- int orientation = (misc >> 10) - 32;
+ int orientation = (misc >> 10) - 32;
input_report_abs(input, ABS_MT_TRACKING_ID, id);
input_report_abs(input, ABS_MT_TOUCH_MAJOR, tdata[3]);
@@ -202,9 +202,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
input_report_abs(input, ABS_MT_POSITION_X, x);
input_report_abs(input, ABS_MT_POSITION_Y, y);
- if (report_undeciphered) {
+ if (report_undeciphered)
input_event(input, EV_MSC, MSC_RAW, tdata[7]);
- }
input_mt_sync(input);
}
@@ -291,62 +290,41 @@ static void magicmouse_setup_input(struct input_dev *input, struct hid_device *h
input->id.version = hdev->version;
input->dev.parent = hdev->dev.parent;
- set_bit(EV_KEY, input->evbit);
- set_bit(BTN_LEFT, input->keybit);
- set_bit(BTN_RIGHT, input->keybit);
+ __set_bit(EV_KEY, input->evbit);
+ __set_bit(BTN_LEFT, input->keybit);
+ __set_bit(BTN_RIGHT, input->keybit);
if (emulate_3button)
- set_bit(BTN_MIDDLE, input->keybit);
- set_bit(BTN_TOOL_FINGER, input->keybit);
+ __set_bit(BTN_MIDDLE, input->keybit);
+ __set_bit(BTN_TOOL_FINGER, input->keybit);
- set_bit(EV_REL, input->evbit);
- set_bit(REL_X, input->relbit);
- set_bit(REL_Y, input->relbit);
+ __set_bit(EV_REL, input->evbit);
+ __set_bit(REL_X, input->relbit);
+ __set_bit(REL_Y, input->relbit);
if (emulate_scroll_wheel)
- set_bit(REL_WHEEL, input->relbit);
+ __set_bit(REL_WHEEL, input->relbit);
if (report_touches) {
- set_bit(EV_ABS, input->evbit);
-
- set_bit(ABS_MT_TRACKING_ID, input->absbit);
- input->absmin[ABS_MT_TRACKING_ID] = 0;
- input->absmax[ABS_MT_TRACKING_ID] = 15;
- input->absfuzz[ABS_MT_TRACKING_ID] = 0;
-
- set_bit(ABS_MT_TOUCH_MAJOR, input->absbit);
- input->absmin[ABS_MT_TOUCH_MAJOR] = 0;
- input->absmax[ABS_MT_TOUCH_MAJOR] = 255;
- input->absfuzz[ABS_MT_TOUCH_MAJOR] = 4;
-
- set_bit(ABS_MT_TOUCH_MINOR, input->absbit);
- input->absmin[ABS_MT_TOUCH_MINOR] = 0;
- input->absmax[ABS_MT_TOUCH_MINOR] = 255;
- input->absfuzz[ABS_MT_TOUCH_MINOR] = 4;
-
- set_bit(ABS_MT_ORIENTATION, input->absbit);
- input->absmin[ABS_MT_ORIENTATION] = -32;
- input->absmax[ABS_MT_ORIENTATION] = 31;
- input->absfuzz[ABS_MT_ORIENTATION] = 1;
-
- set_bit(ABS_MT_POSITION_X, input->absbit);
- input->absmin[ABS_MT_POSITION_X] = -1100;
- input->absmax[ABS_MT_POSITION_X] = 1358;
- input->absfuzz[ABS_MT_POSITION_X] = 4;
-
+ __set_bit(EV_ABS, input->evbit);
+
+ input_set_abs_params(input, ABS_MT_TRACKING_ID, 0, 15, 0, 0);
+ input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 4, 0);
+ input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255, 4, 0);
+ input_set_abs_params(input, ABS_MT_ORIENTATION, -32, 31, 1, 0);
+ input_set_abs_params(input, ABS_MT_POSITION_X, -1100, 1358,
+ 4, 0);
/* Note: Touch Y position from the device is inverted relative
* to how pointer motion is reported (and relative to how USB
* HID recommends the coordinates work). This driver keeps
* the origin at the same position, and just uses the additive
* inverse of the reported Y.
*/
- set_bit(ABS_MT_POSITION_Y, input->absbit);
- input->absmin[ABS_MT_POSITION_Y] = -1589;
- input->absmax[ABS_MT_POSITION_Y] = 2047;
- input->absfuzz[ABS_MT_POSITION_Y] = 4;
+ input_set_abs_params(input, ABS_MT_POSITION_Y, -1589, 2047,
+ 4, 0);
}
if (report_undeciphered) {
- set_bit(EV_MSC, input->evbit);
- set_bit(MSC_RAW, input->mscbit);
+ __set_bit(EV_MSC, input->evbit);
+ __set_bit(MSC_RAW, input->mscbit);
}
}
@@ -385,7 +363,7 @@ static int magicmouse_probe(struct hid_device *hdev,
if (!report) {
dev_err(&hdev->dev, "unable to register touch report\n");
ret = -ENOMEM;
- goto err_free;
+ goto err_stop_hw;
}
report->size = 6;
@@ -394,35 +372,37 @@ static int magicmouse_probe(struct hid_device *hdev,
if (ret != sizeof(feature_1)) {
dev_err(&hdev->dev, "unable to request touch data (1:%d)\n",
ret);
- goto err_free;
+ goto err_stop_hw;
}
ret = hdev->hid_output_raw_report(hdev, feature_2,
sizeof(feature_2), HID_FEATURE_REPORT);
if (ret != sizeof(feature_2)) {
dev_err(&hdev->dev, "unable to request touch data (2:%d)\n",
ret);
- goto err_free;
+ goto err_stop_hw;
}
input = input_allocate_device();
if (!input) {
dev_err(&hdev->dev, "can't alloc input device\n");
ret = -ENOMEM;
- goto err_free;
+ goto err_stop_hw;
}
magicmouse_setup_input(input, hdev);
ret = input_register_device(input);
if (ret) {
dev_err(&hdev->dev, "input device registration failed\n");
- goto err_both;
+ goto err_input;
}
msc->input = input;
return 0;
- err_both:
+err_input:
input_free_device(input);
- err_free:
+err_stop_hw:
+ hid_hw_stop(hdev);
+err_free:
kfree(msc);
return ret;
}
--
1.6.5.6
next prev parent reply other threads:[~2010-02-11 5:33 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-29 14:20 [PATCH 0/3] HID: make raw output callback more flexible Jiri Kosina
2010-01-29 14:20 ` [PATCH 1/3] HID: make raw reports possible for both feature and output reports Jiri Kosina
2010-01-29 14:20 ` [PATCH 2/3] HID: Implement Wacom quirk in the kernel Jiri Kosina
[not found] ` <167e8a331001290914t578ffef7y16d52e40c8c54079@mail.gmail.com>
2010-02-03 14:50 ` Jiri Kosina
2010-01-29 14:21 ` [PATCH 3/3] HID: Enable Sixaxis controller over Bluetooth Jiri Kosina
2010-01-29 16:39 ` [PATCH 0/3] HID: make raw output callback more flexible Bastien Nocera
2010-01-30 0:46 ` Michael Poole
2010-01-30 14:11 ` Bastien Nocera
2010-01-31 3:27 ` Michael Poole
2010-02-03 1:25 ` Michael Poole
2010-02-03 9:47 ` Bastien Nocera
[not found] ` <alpine.LNX.2.00.1002031202040.15395@pobox.suse.cz>
2010-02-03 12:48 ` Jiri Kosina
2010-02-03 12:49 ` [PATCH 1/3] HID: make raw reports possible for both feature and output reports Jiri Kosina
2010-02-03 14:14 ` Marcel Holtmann
2010-02-03 14:37 ` Jiri Kosina
2010-02-03 12:49 ` [PATCH 2/3] HID: Implement Wacom quirk in the kernel Jiri Kosina
2010-02-03 14:19 ` Marcel Holtmann
2010-02-03 14:40 ` Jiri Kosina
2010-02-03 12:50 ` [PATCH 3/3] HID: Enable Sixaxis controller over Bluetooth Jiri Kosina
2010-02-03 14:17 ` Marcel Holtmann
2010-02-03 14:42 ` Jiri Kosina
2010-02-04 12:26 ` [PATCH] Bluetooth: Keep a copy of each HID device's report descriptor Michael Poole
2010-02-04 14:23 ` Marcel Holtmann
2010-02-05 17:23 ` Michael Poole
2010-02-05 17:51 ` Marcel Holtmann
2010-02-09 2:06 ` Ed Tomlinson
2010-02-09 7:22 ` Justin Mattock
2010-02-09 10:14 ` Bastien Nocera
2010-02-09 12:36 ` Ed Tomlinson
2010-02-09 12:40 ` Jiri Kosina
2010-02-09 13:10 ` [PATCH 0/2] Provide a driver for the Apple Magic Mouse Michael Poole
2010-02-09 13:11 ` [PATCH 1/2] " Michael Poole
2010-02-09 13:13 ` [PATCH 2/2] Add a device " Michael Poole
2010-02-10 13:06 ` Jiri Kosina
2010-02-10 13:58 ` Jiri Kosina
2010-02-10 18:20 ` Dmitry Torokhov
2010-02-10 20:31 ` Michael Poole
2010-02-11 5:32 ` Michael Poole [this message]
2010-02-11 6:55 ` [PATCH] hid-magicmouse: Coding style and probe failure fixes Dmitry Torokhov
2010-02-11 10:26 ` Jiri Kosina
2010-02-11 23:10 ` Michael Poole
2010-02-11 3:05 ` [PATCH 2/2] Add a device driver for the Apple Magic Mouse Ed Tomlinson
2010-02-11 3:20 ` Michael Poole
2010-02-11 12:51 ` [PATCH 2/2] Add a device driver for the Apple Magic Mouse (2.6.32.8) Ed Tomlinson
2010-02-09 21:37 ` [PATCH 0/2] Provide a driver for the Apple Magic Mouse Justin P. Mattock
2010-02-10 13:57 ` Jiri Kosina
2010-02-13 19:29 ` [PATCH 0/2] Provide a driver for the Apple Magic Mouse - opps Ed Tomlinson
2010-02-14 8:03 ` Dmitry Torokhov
2010-02-14 14:22 ` Ed Tomlinson
2010-02-15 7:11 ` Dmitry Torokhov
2010-02-15 12:42 ` Ed Tomlinson
2010-02-15 12:44 ` Ed Tomlinson
2010-02-16 12:57 ` Jiri Kosina
2010-02-16 12:34 ` Ed Tomlinson
2010-02-16 12:55 ` Jiri Kosina
2010-02-14 22:24 ` [PATCH 1/1] Enable xy scrolling for Apple Magic Mouse Ed Tomlinson
2010-02-14 22:51 ` Michael Poole
2010-02-14 23:58 ` Ed Tomlinson
2010-02-15 7:18 ` Dmitry Torokhov
2010-02-15 12:50 ` Ed Tomlinson
2010-02-15 0:18 ` Ed Tomlinson
2010-02-09 15:03 ` [PATCH] Bluetooth: Keep a copy of each HID device's report descriptor Justin P. Mattock
2010-02-05 12:49 ` Bastien Nocera
2010-02-05 13:27 ` Marcel Holtmann
2010-01-30 14:13 ` [PATCH 0/3] HID: make raw output callback more flexible Marcel Holtmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=873a18e3qu.fsf_-_@troilus.org \
--to=mdpoole@troilus.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jkosina@suse.cz \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcel@holtmann.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox