From: "Tomasz Pakuła" <tomasz.pakula.oficjalny@gmail.com>
To: jikos@kernel.org, bentiss@kernel.org
Cc: oleg@makarenk.ooo, linux-input@vger.kernel.org
Subject: [PATCH v2 06/17] HID: pidff: Better quirk assigment when searching for fields
Date: Wed, 13 Aug 2025 22:09:54 +0200 [thread overview]
Message-ID: <20250813201005.17819-7-tomasz.pakula.oficjalny@gmail.com> (raw)
In-Reply-To: <20250813201005.17819-1-tomasz.pakula.oficjalny@gmail.com>
Assign quirks directly when they're discovered. Way easier to understand
without relying on return values.
Signed-off-by: Tomasz Pakuła <tomasz.pakula.oficjalny@gmail.com>
---
drivers/hid/usbhid/hid-pidff.c | 59 +++++++++++-----------------------
1 file changed, 18 insertions(+), 41 deletions(-)
diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c
index cff79e76c211..c88442a087f1 100644
--- a/drivers/hid/usbhid/hid-pidff.c
+++ b/drivers/hid/usbhid/hid-pidff.c
@@ -943,7 +943,8 @@ static void pidff_set_autocenter(struct input_dev *dev, u16 magnitude)
* Find fields from a report and fill a pidff_usage
*/
static int pidff_find_fields(struct pidff_usage *usage, const u8 *table,
- struct hid_report *report, int count, int strict)
+ struct hid_report *report, int count, int strict,
+ u32 *quirks)
{
if (!report) {
pr_debug("%s, null report\n", __func__);
@@ -951,7 +952,6 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table,
}
int i, j, k, found;
- int return_value = 0;
for (k = 0; k < count; k++) {
found = 0;
@@ -979,17 +979,17 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table,
if (!found && table[k] == pidff_set_effect[PID_START_DELAY]) {
pr_debug("Delay field not found, but that's OK\n");
pr_debug("Setting MISSING_DELAY quirk\n");
- return_value |= HID_PIDFF_QUIRK_MISSING_DELAY;
+ *quirks |= HID_PIDFF_QUIRK_MISSING_DELAY;
} else if (!found && table[k] == pidff_set_condition[PID_PARAM_BLOCK_OFFSET]) {
pr_debug("PBO field not found, but that's OK\n");
pr_debug("Setting MISSING_PBO quirk\n");
- return_value |= HID_PIDFF_QUIRK_MISSING_PBO;
+ *quirks |= HID_PIDFF_QUIRK_MISSING_PBO;
} else if (!found && strict) {
pr_debug("failed to locate %d\n", k);
return -1;
}
}
- return return_value;
+ return 0;
}
/*
@@ -1258,26 +1258,17 @@ static int pidff_find_effects(struct pidff_device *pidff,
#define PIDFF_FIND_FIELDS(name, report, strict) \
pidff_find_fields(pidff->name, pidff_ ## name, \
pidff->reports[report], \
- ARRAY_SIZE(pidff_ ## name), strict)
+ ARRAY_SIZE(pidff_ ## name), strict, &pidff->quirks)
/*
* Fill and check the pidff_usages
*/
static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
{
- int status = 0;
-
- /* Save info about the device not having the DELAY ffb field. */
- status = PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1);
- if (status == -1) {
+ if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) {
hid_err(pidff->hid, "unknown set_effect report layout\n");
return -ENODEV;
}
- pidff->quirks |= status;
-
- if (status & HID_PIDFF_QUIRK_MISSING_DELAY)
- hid_dbg(pidff->hid, "Adding MISSING_DELAY quirk\n");
-
PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0);
if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) {
@@ -1311,39 +1302,25 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
"has periodic effect but no envelope\n");
}
- if (test_bit(FF_CONSTANT, dev->ffbit) &&
- PIDFF_FIND_FIELDS(set_constant, PID_SET_CONSTANT, 1)) {
+ if (PIDFF_FIND_FIELDS(set_constant, PID_SET_CONSTANT, 1) &&
+ test_and_clear_bit(FF_CONSTANT, dev->ffbit))
hid_warn(pidff->hid, "unknown constant effect layout\n");
- clear_bit(FF_CONSTANT, dev->ffbit);
- }
- if (test_bit(FF_RAMP, dev->ffbit) &&
- PIDFF_FIND_FIELDS(set_ramp, PID_SET_RAMP, 1)) {
+ if (PIDFF_FIND_FIELDS(set_ramp, PID_SET_RAMP, 1) &&
+ test_and_clear_bit(FF_RAMP, dev->ffbit))
hid_warn(pidff->hid, "unknown ramp effect layout\n");
- clear_bit(FF_RAMP, dev->ffbit);
- }
-
- if (test_bit(FF_SPRING, dev->ffbit) ||
- test_bit(FF_DAMPER, dev->ffbit) ||
- test_bit(FF_FRICTION, dev->ffbit) ||
- test_bit(FF_INERTIA, dev->ffbit)) {
- status = PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1);
- if (status < 0) {
+ if (PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) {
+ if (test_and_clear_bit(FF_SPRING, dev->ffbit) ||
+ test_and_clear_bit(FF_DAMPER, dev->ffbit) ||
+ test_and_clear_bit(FF_FRICTION, dev->ffbit) ||
+ test_and_clear_bit(FF_INERTIA, dev->ffbit))
hid_warn(pidff->hid, "unknown condition effect layout\n");
- clear_bit(FF_SPRING, dev->ffbit);
- clear_bit(FF_DAMPER, dev->ffbit);
- clear_bit(FF_FRICTION, dev->ffbit);
- clear_bit(FF_INERTIA, dev->ffbit);
- }
- pidff->quirks |= status;
}
- if (test_bit(FF_PERIODIC, dev->ffbit) &&
- PIDFF_FIND_FIELDS(set_periodic, PID_SET_PERIODIC, 1)) {
+ if (PIDFF_FIND_FIELDS(set_periodic, PID_SET_PERIODIC, 1) &&
+ test_and_clear_bit(FF_PERIODIC, dev->ffbit))
hid_warn(pidff->hid, "unknown periodic effect layout\n");
- clear_bit(FF_PERIODIC, dev->ffbit);
- }
PIDFF_FIND_FIELDS(pool, PID_POOL, 0);
--
2.50.1
next prev parent reply other threads:[~2025-08-13 20:10 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 20:09 [PATCH v2 00/17] Further hid-pidff improvements and fixes Tomasz Pakuła
2025-08-13 20:09 ` [PATCH v2 01/17] HID: pidff: Use direction fix only for conditional effects Tomasz Pakuła
2025-08-13 20:09 ` [PATCH v2 02/17] HID: pidff: Remove unhelpful pidff_set_actuators helper Tomasz Pakuła
2025-08-13 20:09 ` [PATCH v2 03/17] HID: pidff: Remove unneeded debug Tomasz Pakuła
2025-08-13 20:09 ` [PATCH v2 04/17] HID: pidff: Use ARRAY_SIZE macro instead of sizeof Tomasz Pakuła
2025-08-13 20:09 ` [PATCH v2 05/17] HID: pidff: Treat PID_REQUIRED_REPORTS as count, not max Tomasz Pakuła
2025-08-13 20:09 ` Tomasz Pakuła [this message]
2025-08-13 20:09 ` [PATCH v2 07/17] HID: pidff: Simplify HID field/usage searching logic Tomasz Pakuła
2025-08-13 20:09 ` [PATCH v2 08/17] HID: pidff: Add support for AXES_ENABLE field Tomasz Pakuła
2025-08-13 20:09 ` [PATCH v2 09/17] HID: pidff: Update debug messages Tomasz Pakuła
2025-08-13 20:09 ` [PATCH v2 10/17] HID: pidff: Rework pidff_upload_effect Tomasz Pakuła
2025-08-13 20:09 ` [PATCH v2 11/17] HID: pidff: Separate check for infinite duration Tomasz Pakuła
2025-08-13 20:10 ` [PATCH v2 12/17] HID: pidff: PERMISSIVE_CONTROL quirk autodetection Tomasz Pakuła
2025-08-13 20:10 ` [PATCH v2 13/17] HID: pidff: Remove Anssi's email address from info msg Tomasz Pakuła
2025-08-13 20:10 ` [PATCH v2 14/17] HID: pidff: Define all cardinal directions Tomasz Pakuła
2025-08-13 20:10 ` [PATCH v2 15/17] HID: pidff: clang-format pass Tomasz Pakuła
2025-08-13 20:10 ` [PATCH v2 16/17] HID: universal-pidff: " Tomasz Pakuła
2025-08-13 20:10 ` [PATCH v2 17/17] HID: pidff: Reduce PID_EFFECT_OPERATION spam Tomasz Pakuła
2025-08-15 14:01 ` [PATCH v2 00/17] Further hid-pidff improvements and fixes Jiri Kosina
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=20250813201005.17819-7-tomasz.pakula.oficjalny@gmail.com \
--to=tomasz.pakula.oficjalny@gmail.com \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=oleg@makarenk.ooo \
/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;
as well as URLs for NNTP newsgroup(s).