Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966692AbbBCTa1 (ORCPT ); Tue, 3 Feb 2015 14:30:27 -0500 Received: from mailrelay2.public.one.com ([91.198.169.125]:54683 "EHLO mailrelay2.public.one.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756188AbbBCTaW (ORCPT ); Tue, 3 Feb 2015 14:30:22 -0500 X-HalOne-Cookie: 76a80ee801885a06eff4b2a7c37fc1bd16119dfe X-HalOne-ID: 15eccb9e-abdb-11e4-919b-b82a72d03b9b Message-ID: <54D121C8.80206@bitmath.org> Date: Tue, 03 Feb 2015 20:30:16 +0100 From: Henrik Rydberg User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Benjamin Tissoires , Dmitry Torokhov CC: Hans de Goede , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Input - mt: Fix input_mt_get_slot_by_key References: <1422982530-4906-1-git-send-email-benjamin.tissoires@redhat.com> In-Reply-To: <1422982530-4906-1-git-send-email-benjamin.tissoires@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1496 Lines: 40 Hi Benjamin, > Slot 0 is released correclty, but when we look for Contact ID 2, the slot > 0 is then picked up again because it is marked as inactive (trackingID < 0). > > This is wrong, and we should not reuse a slot in the same frame. > The test should also check for input_mt_is_used(). Good catch! However... > @@ -453,7 +456,7 @@ int input_mt_get_slot_by_key(struct input_dev *dev, int key) > return s - mt->slots; > > for (s = mt->slots; s != mt->slots + mt->num_slots; s++) > - if (!input_mt_is_active(s)) { > + if (!input_mt_is_active(s) && !input_mt_is_used(mt, s)) { > s->key = key; > return s - mt->slots; > } > Here, you are changing the preconditions of the function without explicit reference to all its users. For one, it is now assumed that input_mt_is_used() is up-to-date, which requires either input_mt_drop_unused() or input_mt_sync_frame(), which does not seem to be true for all users of input_mt_get_slot_by_key(). After a couple of iterations with input_mt_report_slot_state() in those drivers, input_mt_is_used() will be true for all slots, and the driver will stop working. How about defering the deassignments until the end of the loop instead? That would remove possible reuse. Thanks, Henrik -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/