Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4600346imu; Sun, 25 Nov 2018 06:45:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/ULMl2ofoiR6tvLhMAbhIrsFEbD/ko5uivWkrNmTlaoQoiga27jchb8zNA1D6vkucyOHOiE X-Received: by 2002:a62:59c9:: with SMTP id k70mr8970695pfj.243.1543157132825; Sun, 25 Nov 2018 06:45:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543157132; cv=none; d=google.com; s=arc-20160816; b=nkT/vNAKyhOvWvwldVi6zD4nwU0yeSVVhriYjl5ya6NsApoiONpWizOZD89v6opcQ7 yi0ib9ZeO6LVndVoNs0Mra5R6kq5XAAvYLsZtGvC7eL23QenpAdK8gpErFQmk38zs9Ma jZuuEOaEfyd+n3brv1A7T9iQYMOKeEwnU0ijOyuyx56442cYvfbMw9bn8LhIRO6Mkohp KNuDpmq95VSW1ORcNCx7tQnul4DVidi8Eakx8ODtf1qDY08I+JzoEK+iAh51J8LpfrW6 baz8Anu3yDtn09bsjNFFxch51ONlKIzXzE88CsgrO3S74i9HvvIvFLB2aOei87mkUM0z i3Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=0GZdmldzSj3kcYzR/4clMraY/umXZY6P8C8dus4Yil8=; b=Gjtyft9olFm/1DkJtLHk4N22oCcx1LlVRYUTUrDcntNnzg2JUlCj5tjMDtMLhtNTPT EKDp6Gbvf4gE3ZDw0gGdivWC77pAKs3PXHki5OKwxfflG4iHNVySCvbpZTzEGzRhqJG/ l/5FH/NlQmeLcj7Gdp0lzbUoUrhA0QjIuMNSXFd3eKlANVYkWYFIs4kgrgM0Hrh7hiZf XMXgBCjyoieE9Pq68gzwaP89dmJTqM19fcqVS5wMFoKYO14Pnwr8D2Fu84R9B/7rbcIb 0E63k5UVYLeHI3/GyQwwaHNy563DcEpHPhujVONxy7vXXC+n91kLKYYoUR5PG29owFxL AYuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m1si20433201pgi.218.2018.11.25.06.45.17; Sun, 25 Nov 2018 06:45:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726317AbeKZBfz (ORCPT + 99 others); Sun, 25 Nov 2018 20:35:55 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:41664 "EHLO dcvr.yhbt.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726083AbeKZBfz (ORCPT ); Sun, 25 Nov 2018 20:35:55 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 125A21F97E; Sun, 25 Nov 2018 14:44:42 +0000 (UTC) Date: Sun, 25 Nov 2018 14:44:41 +0000 From: Eric Wong To: =?utf-8?B?QmrDuHJu?= Mork Cc: Henrique de Moraes Holschuh , Shuduo Sang , Darren Hart , Andy Shevchenko , linux-kernel@vger.kernel.org, ibm-acpi-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org Subject: Re: [PATCH] platform/x86: thinkpad_acpi: add adaptive_kbd_modes parameter Message-ID: <20181125144441.xpwuov2i7lab3agh@dcvr> References: <20181115073429.z44czywrf7f65ndb@dcvr> <20181124232327.t3awc6dnjqdtvzwu@dcvr> <87in0l31b9.fsf@miraculix.mork.no> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87in0l31b9.fsf@miraculix.mork.no> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Bjørn Mork wrote: > Eric Wong writes: > > Eric Wong wrote: > >> The above setting with this change and the following keymap > >> preserves my sanity on the atrocious adaptive keyboard on > >> the 2nd-gen X1 Carbon: > > > > Any comments on this patch? The Esc and F-keys on the keyboard > > are still numb and I'll be getting rid of the laptop in a few > > days; but maybe my patch can still be useful to others... > > I've read through and I like it, FWIW. A brilliant idea. I don't have > the hardare to test the patch, though.... Thanks for checking it out. > But I do wonder if you aren't missing an empty mask protection > somewhere? If I read this right, then there is nothing preventing you > from writing 0 here: > > > +static ssize_t adaptive_kbd_modes_store(struct device *dev, > > + struct device_attribute *attr, > > + const char *buf, size_t count) > > +{ > > + unsigned long t; > > + > > + if (parse_strtoul(buf, (1 << LAYFLAT_MODE) - 1, &t)) > > + return -EINVAL; > > + > > + adaptive_kbd_modes = (unsigned int)t; > > + return count; > > +} Right, 0 is allowed; and it will lock the current mode into place... > And then I believe you have a busy loop here: > > > @@ -3815,20 +3838,20 @@ static int adaptive_keyboard_set_mode(int new_mode) > > > > static int adaptive_keyboard_get_next_mode(int mode) > > { > > - size_t i; > > - size_t max_mode = ARRAY_SIZE(adaptive_keyboard_modes) - 1; > > - > > - for (i = 0; i <= max_mode; i++) { > > - if (adaptive_keyboard_modes[i] == mode) > > - break; > > - } > > + int max_mode = fls(adaptive_kbd_modes); > > + int new_mode = mode >= max_mode ? HOME_MODE : mode + 1; > > > > - if (i >= max_mode) > > - i = 0; > > - else > > - i++; > > + /* make sure the new mode is allowed by the user */ > > + while (!(adaptive_kbd_modes & (1 << new_mode))) { > > + new_mode++; > > + if (new_mode > max_mode) > > + new_mode = HOME_MODE; > > > > - return adaptive_keyboard_modes[i]; > > + /* maybe the user disabled all other modes: */ > > + if (new_mode == mode) > > + return mode; > > + } > > + return new_mode; > > } Not a busy loop, since new_mode will reset at HOME_MODE (0) and then it'll hit "new_mode == mode" and remain locked in to the current mode. > Or am I reading this wrong? It seems that way. My initial iteration of this patch did have a busy loop, but I fixed it before publishing :) Thanks again for the review.