Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1583332imm; Wed, 13 Jun 2018 23:59:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJlm2uXq62tpDihrqKytKOFS7mFj2MOULhq9HMvU4cHf0W9Etg8eHMe97BZ56IMmFkaHPrQ X-Received: by 2002:a63:2a11:: with SMTP id q17-v6mr1245656pgq.60.1528959585461; Wed, 13 Jun 2018 23:59:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528959585; cv=none; d=google.com; s=arc-20160816; b=uPMatiKrssJbn10VWSjzJaO6qLvokED0vCDAoI+wLWEbQ/le9XVpxRB8YsiexpDwLh 2dnFu9dRBiR9MSKSuvggQ88rXNrqR96svpLTaF12zfa9tySp1Ui5idNuVlK8dK9julRd I/y/bIFyCfYm4U/7sWIfDhYr+JDmF+JDTtwnno6Ays4IfaTxJgPjnMSWKffYOgGHPi9p VHbNUdXGkdCQ6vN0PRVjUDrnzMsEItMTieil5irqAeMGdIdANEy3Y/EemjrXh0HRcfdt bGlYZe6SIJi/59+4TESGHUEuo/CaRUvMVKouWT6aarpipBFxewFzpp6fHKerAjHPWX3N zQ5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=xBMwJhu6BldoGoDpCKd46TdJwvpW/X8pGVB9bURSh78=; b=wQjyqK4jHfjwS+GQQ5GVVfz2Rw0DtcG3TTmvLYkpWbKPpQKy6gbYLEJB8BKaGuOLie a4JjsIlZ7ga4DK1Mn1jRqnAoNSIEcdR/nqfVek8FjPXFxMCjjWt3mvrem4ooINlvP5eF F0+ynTrVYPkGYPOmLNYEDf9zkS6f96U1mgzi7MJeVGrEA2pXxC4LoFfvmDRUNhTpoaKY lENeeyWXcz+1opmADYYbqBuCD0fII+29VqYfTmRyfTwmwRH0Ac7ZU58V/902/nIiP6Tu a0kzky1SdkV8yILmnKSrlSkr7L+lfQzlGUVjISHpY2q4RzfOWJ4vIIz7uqcrGKPQu2ha q4Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@endlessm-com.20150623.gappssmtp.com header.s=20150623 header.b="rr65p/f0"; 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 l12-v6si4563486pfb.69.2018.06.13.23.59.30; Wed, 13 Jun 2018 23:59:45 -0700 (PDT) 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; dkim=pass header.i=@endlessm-com.20150623.gappssmtp.com header.s=20150623 header.b="rr65p/f0"; 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 S1752933AbeFNG6R (ORCPT + 99 others); Thu, 14 Jun 2018 02:58:17 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:54286 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752781AbeFNG6P (ORCPT ); Thu, 14 Jun 2018 02:58:15 -0400 Received: by mail-wm0-f65.google.com with SMTP id o13-v6so8554366wmf.4 for ; Wed, 13 Jun 2018 23:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=endlessm-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=xBMwJhu6BldoGoDpCKd46TdJwvpW/X8pGVB9bURSh78=; b=rr65p/f0hZ1baqmICBMAqIj3w6+l3fF6sazcn4a/j6FhEYvFfPNuQSDJnUG5ORZgHp a04dwpe8aYGqFgMh5IEknEoLbTn530KstLrq4hEEqzR+MlSpRte4ri99lFWZz/PiBusl joXg8ySCgr3PwdphshbOxDv7YWI3K4shy0xgYTsdvA5PFIUstu/ineQAOUTcGdejiwn8 8Fab4EK9i7I1TX2GXUGO0qMFQasLUmEBOBbNbvS/i/wJwlxWObQx+FQSfnSvRanrkV5G rHtVMhbC+OcPC1N2O8YmZxX6tSUO25+0ErU2vOnAt7sIOfbCAv4PwuYBno48D1DmlzXs eaQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=xBMwJhu6BldoGoDpCKd46TdJwvpW/X8pGVB9bURSh78=; b=NIj2j6hHHvxjnbxEzih4iBreWuepJi8Asn5TLvPWMbKVRotoSAW5XsIhhBdue+XR/p JdofjjF84Mk3aWf0untC6LjarCea01EuMNSECUSYgSr7nEJ4jxdDOFuHtY8e+LPNymqp CC45gIWLUb5ffW3jj+n08E2XA1KCB6xZLv/l1Lazt/rGN0uDq2CdXUkyjq4jNirzXcLi 4yAwtpkds4RoTNAOz+0B9PqnFAlHJjvvRFIMU/Ulklc2Gn7AB5ebIMxGYQ5HUvx3iVTh YsK2fMu4grxyOgAPxssVFIIOFJFhUwt53cmw5bu+pEjRwIn+Duj4Psls2Yxx90ycwIey jQ/g== X-Gm-Message-State: APt69E3u3UNa6aRK3eJ/6k/BVhCu/4e44aAUauINpaHDek+T24oICuTn ObFsTC7gF7/aWn/b5p5qhDSX7vJxbxGQaqIiGIcpPw== X-Received: by 2002:aa7:d58d:: with SMTP id r13-v6mr1435456edq.176.1528959494548; Wed, 13 Jun 2018 23:58:14 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:90d3:0:0:0:0:0 with HTTP; Wed, 13 Jun 2018 23:58:13 -0700 (PDT) In-Reply-To: References: <20180611071838.47945-1-chiu@endlessm.com> From: Chris Chiu Date: Thu, 14 Jun 2018 14:58:13 +0800 Message-ID: Subject: Re: [PATCH v2 1/2] platform/x86: asus-wmi: Call led hw_changed API on kbd brightness change To: Andy Shevchenko Cc: Corentin Chary , Darren Hart , Linux Kernel Mailing List , Platform Driver , acpi4asus-user , Hans de Goede , Linux Upstreaming Team Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 13, 2018 at 8:49 PM, Andy Shevchenko wrote: > On Mon, Jun 11, 2018 at 10:18 AM, Chris Chiu wrote: >> Make asus-wmi notify on hotkey kbd brightness changes, listen for >> brightness events and update the brightness directly in the driver. > >> For this purpose, bound check on brightness in kbd_led_set must be >> based on the same data type to prevent illegal value been set. > >> @@ -497,9 +498,9 @@ static void kbd_led_set(struct led_classdev *led_cdev, >> >> asus = container_of(led_cdev, struct asus_wmi, kbd_led); >> >> - if (value > asus->kbd_led.max_brightness) >> + if ((int)value > (int)asus->kbd_led.max_brightness) >> value = asus->kbd_led.max_brightness; >> - else if (value < 0) >> + else if ((int)value < 0) >> value = 0; > > I didn't quite understand this part of the problem. > Does it exist in the current code? Can it be split to a separate change? > > Can we avoid those ugly castings? > I'd like to remove the ugly castings but there's a concern I may need some advices. I don't know whether if the bound check logic ever verified before. Maybe the value passed via sysfs is already correctly bounded? When the kbd_led_wk comes to -1, `if (value > asus->kbd_led.max_brightness)` returns true and `if (value < 0)` return false which confused me. It should relate to the 2nd argument type is enum led_brightness which I consider it as integer. The unexpected return value cause the KBD_BRTDWN cyclic, 3->2->0->-1 (3 again in kbd_led_set)->2->1. After applying the casting on both operands `if ((int)value > (int)asus->kbd_led.max_brightness)`, the other unexpected false returned by `if (value < 0)` makes each KBD_BRTDOWN to be 3 -> 2 -> 1 -> 0 -> -1 -> -2 -> -3 ->..... That's what the ugly casting for. I used to tend to do boundary limit before calling kbd_led_set as follows kbd_led_set(&asus->kbd_led, MIN(asus->kbd_led_wk + 1, asus->kbd_led.max_brightness); and kbd_led_set(&asus->kbd_led, MAX(asus->kbd_led_wk - 1, 0)); If so, the boundary limit logic would be totally redundant but I think it may be still useful to check the value passed from sysfs? Any suggestion which one would be better? Chris > -- > With Best Regards, > Andy Shevchenko