diff mbox

[4/4] HID: uclogic: name the input nodes based on their tool

Message ID 1424822730-14938-5-git-send-email-benjamin.tissoires@redhat.com (mailing list archive)
State New, archived
Delegated to: Jiri Kosina
Headers show

Commit Message

Benjamin Tissoires Feb. 25, 2015, 12:05 a.m. UTC
We append "Pen", "Pad", "Mouse" or "Keyboard" suffix to the appropriate
input node to match what the Wacom driver does and be more convenient for
the user to know which one is which.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-uclogic.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

Comments

Nikolai Kondrashov Feb. 25, 2015, 9:04 p.m. UTC | #1
On 02/25/2015 02:05 AM, Benjamin Tissoires wrote:
> We append "Pen", "Pad", "Mouse" or "Keyboard" suffix to the appropriate
> input node to match what the Wacom driver does and be more convenient for
> the user to know which one is which.

As I said before, this is a very welcome change. Thanks, Benjamin!
However, I'm not familiar with input_configured hook yet, so cannot give my
Reviewed-by.

> +	if (suffix) {
> +		len = strlen(hdev->name) + 2 + strlen(suffix);
> +		name = devm_kzalloc(&hi->input->dev, len, GFP_KERNEL);
> +		if (name) {
> +			snprintf(name, len, "%s %s", hdev->name, suffix);
> +			hi->input->name = name;
> +		}

I only feel a bit uneasy about duplicating buffer size knowledge here, as I
said before, but the code is short, so it'll probably be OK.

Nick
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Benjamin Tissoires Feb. 25, 2015, 9:36 p.m. UTC | #2
On Feb 25 2015 or thereabouts, Nikolai Kondrashov wrote:
> On 02/25/2015 02:05 AM, Benjamin Tissoires wrote:
> >We append "Pen", "Pad", "Mouse" or "Keyboard" suffix to the appropriate
> >input node to match what the Wacom driver does and be more convenient for
> >the user to know which one is which.
> 
> As I said before, this is a very welcome change. Thanks, Benjamin!
> However, I'm not familiar with input_configured hook yet, so cannot give my
> Reviewed-by.

Well, the hook is called just before we present the input to the user
space. So the input node is already set and its corresponding report
has been parsed (or the whole descriptor has been parsed if
QUIRK_MULTI_INPUT is not set).

> 
> >+	if (suffix) {
> >+		len = strlen(hdev->name) + 2 + strlen(suffix);
> >+		name = devm_kzalloc(&hi->input->dev, len, GFP_KERNEL);
> >+		if (name) {
> >+			snprintf(name, len, "%s %s", hdev->name, suffix);
> >+			hi->input->name = name;
> >+		}
> 
> I only feel a bit uneasy about duplicating buffer size knowledge here, as I
> said before, but the code is short, so it'll probably be OK.

I am not quite sure what you mean with "duplicating buffer size
knowledge"...

Cheers,
Benjamin

> 
> Nick
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Nikolai Kondrashov Feb. 25, 2015, 10:28 p.m. UTC | #3
On 02/25/2015 11:36 PM, Benjamin Tissoires wrote:
> On Feb 25 2015 or thereabouts, Nikolai Kondrashov wrote:
>> On 02/25/2015 02:05 AM, Benjamin Tissoires wrote:
>>> We append "Pen", "Pad", "Mouse" or "Keyboard" suffix to the appropriate
>>> input node to match what the Wacom driver does and be more convenient for
>>> the user to know which one is which.
>>
>> As I said before, this is a very welcome change. Thanks, Benjamin!
>> However, I'm not familiar with input_configured hook yet, so cannot give my
>> Reviewed-by.
>
> Well, the hook is called just before we present the input to the user
> space. So the input node is already set and its corresponding report
> has been parsed (or the whole descriptor has been parsed if
> QUIRK_MULTI_INPUT is not set).

Thanks for the explanation, but basing my Reviewed-by on your explanation
wouldn't be right, even though this seems simple :) I'll read up the kernel
code tomorrow.

>>
>>> +	if (suffix) {
>>> +		len = strlen(hdev->name) + 2 + strlen(suffix);
>>> +		name = devm_kzalloc(&hi->input->dev, len, GFP_KERNEL);
>>> +		if (name) {
>>> +			snprintf(name, len, "%s %s", hdev->name, suffix);
>>> +			hi->input->name = name;
>>> +		}
>>
>> I only feel a bit uneasy about duplicating buffer size knowledge here, as I
>> said before, but the code is short, so it'll probably be OK.
>
> I am not quite sure what you mean with "duplicating buffer size
> knowledge"...

Argh, nevermind, just sleepy me, sorry. You fixed it, thanks, looks fine :)

Nick
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/hid/hid-uclogic.c b/drivers/hid/hid-uclogic.c
index c03e076..7042238 100644
--- a/drivers/hid/hid-uclogic.c
+++ b/drivers/hid/hid-uclogic.c
@@ -713,6 +713,45 @@  static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
 	return rdesc;
 }
 
+static void uclogic_input_configured(struct hid_device *hdev,
+		struct hid_input *hi)
+{
+	char *name;
+	const char *suffix = NULL;
+	struct hid_field *field;
+	size_t len;
+
+	/* no report associated (HID_QUIRK_MULTI_INPUT not set) */
+	if (!hi->report)
+		return;
+
+	field = hi->report->field[0];
+
+	switch (field->application) {
+	case HID_GD_KEYBOARD:
+		suffix = "Keyboard";
+		break;
+	case HID_GD_MOUSE:
+		suffix = "Mouse";
+		break;
+	case HID_GD_KEYPAD:
+		suffix = "Pad";
+		break;
+	case HID_DG_PEN:
+		suffix = "Pen";
+		break;
+	}
+
+	if (suffix) {
+		len = strlen(hdev->name) + 2 + strlen(suffix);
+		name = devm_kzalloc(&hi->input->dev, len, GFP_KERNEL);
+		if (name) {
+			snprintf(name, len, "%s %s", hdev->name, suffix);
+			hi->input->name = name;
+		}
+	}
+}
+
 /**
  * Enable fully-functional tablet mode and determine device parameters.
  *
@@ -906,6 +945,7 @@  static struct hid_driver uclogic_driver = {
 	.probe = uclogic_probe,
 	.report_fixup = uclogic_report_fixup,
 	.raw_event = uclogic_raw_event,
+	.input_configured = uclogic_input_configured,
 };
 module_hid_driver(uclogic_driver);