Skip to contentSkip to conversation

Input: zinitix: iterate contact slots by finger count

PATCH In review Thanh Nguyen 4 participants 5 messages Apr 8 – Jul 14

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: zinitix: iterate contact slots by finger count

On affected devices (for example Samsung A3 2015), the value in touch_event.finger_mask appears to behave as a count of reported slots rather than a bitmask. Using for_each_set_bit() can then skip valid contacts and break multitouch gestures.

Keep filtering by SUB_BIT_EXIST to avoid reporting shadow contacts, but iterate from slot 0 up to min(finger_mask, MAX_SUPPORTED_FINGER_NUM). This follows the maintainer feedback to treat the field as a possible count while preserving the anti-shadow check.

Fixes e941dc13fd37 ("Input: zinitix - do not report shadow fingers")

---
v2:
- Address maintainer feedback: do not revert e941dc13fd37.
- Keep SUB_BIT_EXIST filtering to avoid shadow contacts.
- Treat finger_mask as a slot-count bound and iterate 0..min(mask, max).

 drivers/input/touchscreen/zinitix.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/input/touchscreen/zinitix.c +2 -1
index 716d6fa60..a2edae7df 100644
@@ -471,7 +471,8 @@ static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler)
 	}
 
 	finger_mask = touch_event.finger_mask;
-	for_each_set_bit(i, &finger_mask, MAX_SUPPORTED_FINGER_NUM) {
+	for (i = 0; i < min_t(unsigned long, finger_mask,
+			MAX_SUPPORTED_FINGER_NUM); i++) {
 		const struct point_coord *p = &touch_event.point_coord[i];
 
 		/* Only process contacts that are actually reported */
Signature · 1 line
2.51.0.windows.2
#1 lore raw

Hi Thanh,

sorry for slow reply!

Quoted 11 lines · Thanh Nguyen

On affected devices (for example Samsung A3 2015), the value in touch_event.finger_mask appears to behave as a count of reported slots rather than a bitmask. Using for_each_set_bit() can then skip valid contacts and break multitouch gestures.

Keep filtering by SUB_BIT_EXIST to avoid reporting shadow contacts, but iterate from slot 0 up to min(finger_mask, MAX_SUPPORTED_FINGER_NUM). This follows the maintainer feedback to treat the field as a possible count while preserving the anti-shadow check.

Quoted 8 lines
Fixes e941dc13fd37 ("Input: zinitix - do not report shadow fingers")

---
v2:
- Address maintainer feedback: do not revert e941dc13fd37.
- Keep SUB_BIT_EXIST filtering to avoid shadow contacts.
- Treat finger_mask as a slot-count bound and iterate 0..min(mask, max).

I can test this if need be, but maybe Nikita want to check it first?

Yours,
Linus Walleij

#2 lore raw

Linus Walleij писал(а) 30.06.2026 14:11:

Quoted 25 lines

Hi Thanh,

sorry for slow reply!

Quoted 11 lines · Thanh Nguyen

On affected devices (for example Samsung A3 2015), the value in touch_event.finger_mask appears to behave as a count of reported slots rather than a bitmask. Using for_each_set_bit() can then skip valid contacts and break multitouch gestures.

Keep filtering by SUB_BIT_EXIST to avoid reporting shadow contacts, but iterate from slot 0 up to min(finger_mask, MAX_SUPPORTED_FINGER_NUM). This follows the maintainer feedback to treat the field as a possible count while preserving the anti-shadow check.

Quoted 8 lines
Fixes e941dc13fd37 ("Input: zinitix - do not report shadow fingers")

---
v2:
- Address maintainer feedback: do not revert e941dc13fd37.
- Keep SUB_BIT_EXIST filtering to avoid shadow contacts.
- Treat finger_mask as a slot-count bound and iterate 0..min(mask, max).

Quoted 3 lines

I can test this if need be, but maybe Nikita want to check it first?

Hi!

I've quickly checked it on my gt58 (bt532) but it made me remember that on this device/chip it seems like only "TOUCH_MODE=0" is supported and reported fingers don't have extra "width"/"angle" fields. (I have a vague recollection that this was somehow related to touchkeys being enabled or not) Otherwise on this chip (firmware? touch_mode?) the finger count is indeed a count and not a mask.

Given we have an EXIST bit IMO it still makes sense to make this change. Maybe also worth adding a short comment why we're treating mask as count if Linus's devices report mask and your/mine report count...

Nikita

Quoted 2 lines

Yours,
Linus Walleij

#3 lore raw

Hi Nikita, Linus, and Dmitry,

Thank you all for the feedback and for confirming the fix on your end, Nikita.

Unfortunately, since it's been a while since I submitted the v2 patch, I recently had to completely wipe my development machine and no longer have the local environment or the original patch files to create a v3.

Since the logic in v2 is sound and the only change needed is a brief comment explaining the dual mask/count nature of finger_mask, would one of you be willing to add that comment and apply the patch on my behalf? I'd really appreciate it.

Thanks again for your time and help with getting this merged!

Best regards,
Thanh Nguyen

#4 lore raw

Sorry for not replying earlier (life), but I don't think the v2 patch will fully work correctly.

At least on my samsung a3 the loop needs to work as it did before e941dc13fd37.

Meaning: iterate over all slots and check the (sub_status & SUB_BIT_EXIST) for whether the finger is active or not.
Because: the active fingers can be in later slots with the earlier slots being inactive.

For example when the user:
1. touches with one finger (1 finger active in slot 0)
2. touches somewhere else with a second finger (2 fingers active in slots 0, 1)
3. lets go with the first finger (1 finger active in slot 1)

In such a case the loop would only iterate over slot 0 and not report any fingers despite slot 1 still being active. In practice this will likely be usable... but afaik and can tell it's still incorrect behaviour.

Best Regards,
Timon

Quoted 17 lines · Thành Nguyễn

Hi Nikita, Linus, and Dmitry,

Thank you all for the feedback and for confirming the fix on your end, Nikita.

Unfortunately, since it's been a while since I submitted the v2 patch, I recently had to completely wipe my development machine and no longer have the local environment or the original patch files to create a v3.

Since the logic in v2 is sound and the only change needed is a brief comment explaining the dual mask/count nature of finger_mask, would one of you be willing to add that comment and apply the patch on my behalf? I'd really appreciate it.

Thanks again for your time and help with getting this merged!

Best regards,
Thanh Nguyen