mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
udev-builtin-input_ic: simplify loop in test_key()
We would update 'found' using bit operations, but studiously ignore the actual value and treat it as boolean. So just use a boolean variable instead. Because there is a double loop, we would break the inner loop, but repeat the outer loop, even though the boolean was already set. Add '&& !found' in the loop conditions to break iteration immediately.
This commit is contained in:
parent
169d980bc8
commit
8b06c72969
@ -285,10 +285,8 @@ static bool test_key(sd_device *dev,
|
||||
const unsigned long* bitmask_ev,
|
||||
const unsigned long* bitmask_key,
|
||||
bool test) {
|
||||
unsigned i;
|
||||
unsigned long found;
|
||||
unsigned long mask;
|
||||
bool ret = false;
|
||||
|
||||
bool found = false;
|
||||
|
||||
/* do we have any KEY_* capability? */
|
||||
if (!test_bit(EV_KEY, bitmask_ev)) {
|
||||
@ -297,39 +295,32 @@ static bool test_key(sd_device *dev,
|
||||
}
|
||||
|
||||
/* only consider KEY_* here, not BTN_* */
|
||||
found = 0;
|
||||
for (i = 0; i < BTN_MISC/BITS_PER_LONG; ++i) {
|
||||
found |= bitmask_key[i];
|
||||
log_device_debug(dev, "test_key: checking bit block %lu for any keys; found=%i", (unsigned long)i*BITS_PER_LONG, found > 0);
|
||||
for (size_t i = 0; i < BTN_MISC/BITS_PER_LONG && !found; i++) {
|
||||
if (bitmask_key[i])
|
||||
found = true;
|
||||
|
||||
log_device_debug(dev, "test_key: checking bit block %zu for any keys; found=%s",
|
||||
i * BITS_PER_LONG, yes_no(found));
|
||||
}
|
||||
/* If there are no keys in the lower block, check the higher blocks */
|
||||
if (!found) {
|
||||
unsigned block;
|
||||
for (block = 0; block < (sizeof(high_key_blocks) / sizeof(struct range)); ++block) {
|
||||
for (i = high_key_blocks[block].start; i < high_key_blocks[block].end; ++i) {
|
||||
if (test_bit(i, bitmask_key)) {
|
||||
log_device_debug(dev, "test_key: Found key %x in high block", i);
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
for (size_t block = 0; block < sizeof(high_key_blocks) / sizeof(struct range) && !found; block++)
|
||||
for (unsigned i = high_key_blocks[block].start; i < high_key_blocks[block].end && !found; i++)
|
||||
if (test_bit(i, bitmask_key)) {
|
||||
log_device_debug(dev, "test_key: Found key %x in high block", i);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (found > 0) {
|
||||
if (found)
|
||||
udev_builtin_add_property(dev, test, "ID_INPUT_KEY", "1");
|
||||
ret = true;
|
||||
}
|
||||
|
||||
/* the first 32 bits are ESC, numbers, and Q to D; if we have all of
|
||||
* those, consider it a full keyboard; do not test KEY_RESERVED, though */
|
||||
mask = 0xFFFFFFFE;
|
||||
if (FLAGS_SET(bitmask_key[0], mask)) {
|
||||
if (FLAGS_SET(bitmask_key[0], 0xFFFFFFFE)) {
|
||||
udev_builtin_add_property(dev, test, "ID_INPUT_KEYBOARD", "1");
|
||||
ret = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return found;
|
||||
}
|
||||
|
||||
static int builtin_input_id(sd_device *dev, int argc, char *argv[], bool test) {
|
||||
|
Loading…
Reference in New Issue
Block a user