Skip to content

Commit 7f3d7bc

Browse files
LawstorantJiri Kosina
authored andcommitted
HID: pidff: Better quirk assigment when searching for fields
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> Signed-off-by: Jiri Kosina <jkosina@suse.com>
1 parent c7ad781 commit 7f3d7bc

1 file changed

Lines changed: 18 additions & 41 deletions

File tree

drivers/hid/usbhid/hid-pidff.c

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -943,15 +943,15 @@ static void pidff_set_autocenter(struct input_dev *dev, u16 magnitude)
943943
* Find fields from a report and fill a pidff_usage
944944
*/
945945
static int pidff_find_fields(struct pidff_usage *usage, const u8 *table,
946-
struct hid_report *report, int count, int strict)
946+
struct hid_report *report, int count, int strict,
947+
u32 *quirks)
947948
{
948949
if (!report) {
949950
pr_debug("%s, null report\n", __func__);
950951
return -1;
951952
}
952953

953954
int i, j, k, found;
954-
int return_value = 0;
955955

956956
for (k = 0; k < count; k++) {
957957
found = 0;
@@ -979,17 +979,17 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table,
979979
if (!found && table[k] == pidff_set_effect[PID_START_DELAY]) {
980980
pr_debug("Delay field not found, but that's OK\n");
981981
pr_debug("Setting MISSING_DELAY quirk\n");
982-
return_value |= HID_PIDFF_QUIRK_MISSING_DELAY;
982+
*quirks |= HID_PIDFF_QUIRK_MISSING_DELAY;
983983
} else if (!found && table[k] == pidff_set_condition[PID_PARAM_BLOCK_OFFSET]) {
984984
pr_debug("PBO field not found, but that's OK\n");
985985
pr_debug("Setting MISSING_PBO quirk\n");
986-
return_value |= HID_PIDFF_QUIRK_MISSING_PBO;
986+
*quirks |= HID_PIDFF_QUIRK_MISSING_PBO;
987987
} else if (!found && strict) {
988988
pr_debug("failed to locate %d\n", k);
989989
return -1;
990990
}
991991
}
992-
return return_value;
992+
return 0;
993993
}
994994

995995
/*
@@ -1258,26 +1258,17 @@ static int pidff_find_effects(struct pidff_device *pidff,
12581258
#define PIDFF_FIND_FIELDS(name, report, strict) \
12591259
pidff_find_fields(pidff->name, pidff_ ## name, \
12601260
pidff->reports[report], \
1261-
ARRAY_SIZE(pidff_ ## name), strict)
1261+
ARRAY_SIZE(pidff_ ## name), strict, &pidff->quirks)
12621262

12631263
/*
12641264
* Fill and check the pidff_usages
12651265
*/
12661266
static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
12671267
{
1268-
int status = 0;
1269-
1270-
/* Save info about the device not having the DELAY ffb field. */
1271-
status = PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1);
1272-
if (status == -1) {
1268+
if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) {
12731269
hid_err(pidff->hid, "unknown set_effect report layout\n");
12741270
return -ENODEV;
12751271
}
1276-
pidff->quirks |= status;
1277-
1278-
if (status & HID_PIDFF_QUIRK_MISSING_DELAY)
1279-
hid_dbg(pidff->hid, "Adding MISSING_DELAY quirk\n");
1280-
12811272

12821273
PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0);
12831274
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)
13111302
"has periodic effect but no envelope\n");
13121303
}
13131304

1314-
if (test_bit(FF_CONSTANT, dev->ffbit) &&
1315-
PIDFF_FIND_FIELDS(set_constant, PID_SET_CONSTANT, 1)) {
1305+
if (PIDFF_FIND_FIELDS(set_constant, PID_SET_CONSTANT, 1) &&
1306+
test_and_clear_bit(FF_CONSTANT, dev->ffbit))
13161307
hid_warn(pidff->hid, "unknown constant effect layout\n");
1317-
clear_bit(FF_CONSTANT, dev->ffbit);
1318-
}
13191308

1320-
if (test_bit(FF_RAMP, dev->ffbit) &&
1321-
PIDFF_FIND_FIELDS(set_ramp, PID_SET_RAMP, 1)) {
1309+
if (PIDFF_FIND_FIELDS(set_ramp, PID_SET_RAMP, 1) &&
1310+
test_and_clear_bit(FF_RAMP, dev->ffbit))
13221311
hid_warn(pidff->hid, "unknown ramp effect layout\n");
1323-
clear_bit(FF_RAMP, dev->ffbit);
1324-
}
1325-
1326-
if (test_bit(FF_SPRING, dev->ffbit) ||
1327-
test_bit(FF_DAMPER, dev->ffbit) ||
1328-
test_bit(FF_FRICTION, dev->ffbit) ||
1329-
test_bit(FF_INERTIA, dev->ffbit)) {
1330-
status = PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1);
13311312

1332-
if (status < 0) {
1313+
if (PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) {
1314+
if (test_and_clear_bit(FF_SPRING, dev->ffbit) ||
1315+
test_and_clear_bit(FF_DAMPER, dev->ffbit) ||
1316+
test_and_clear_bit(FF_FRICTION, dev->ffbit) ||
1317+
test_and_clear_bit(FF_INERTIA, dev->ffbit))
13331318
hid_warn(pidff->hid, "unknown condition effect layout\n");
1334-
clear_bit(FF_SPRING, dev->ffbit);
1335-
clear_bit(FF_DAMPER, dev->ffbit);
1336-
clear_bit(FF_FRICTION, dev->ffbit);
1337-
clear_bit(FF_INERTIA, dev->ffbit);
1338-
}
1339-
pidff->quirks |= status;
13401319
}
13411320

1342-
if (test_bit(FF_PERIODIC, dev->ffbit) &&
1343-
PIDFF_FIND_FIELDS(set_periodic, PID_SET_PERIODIC, 1)) {
1321+
if (PIDFF_FIND_FIELDS(set_periodic, PID_SET_PERIODIC, 1) &&
1322+
test_and_clear_bit(FF_PERIODIC, dev->ffbit))
13441323
hid_warn(pidff->hid, "unknown periodic effect layout\n");
1345-
clear_bit(FF_PERIODIC, dev->ffbit);
1346-
}
13471324

13481325
PIDFF_FIND_FIELDS(pool, PID_POOL, 0);
13491326

0 commit comments

Comments
 (0)