Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3151835yba; Tue, 16 Apr 2019 05:57:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxfxF4mvKWEEGiS0+ExFfZ8Z4TDCICE+AFEo2KotanERjGFdMk069bs5aTHEmuhr7BtxsBH X-Received: by 2002:a62:3849:: with SMTP id f70mr83342017pfa.46.1555419425187; Tue, 16 Apr 2019 05:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555419425; cv=none; d=google.com; s=arc-20160816; b=MOnt/qz9Lyw9aCoETqNTU/sKESrd5ocId9r4lfHIMTOQRIb9dtu+PGIjZx4LGdHPk5 gvFvlLmy/TUqqXpV5v53qGAxzW/9v0Vda/Y7O8aIwstsuwVfJtZ+lC1/G6clHS4xVdxx TWQwpS0upssCfU7a7mK19O5++YAqzh8NiAdMfOmYgZoGMewTYo76kpz+X3/5Vt6OW/y6 zuDrcBax65efdGAMdJ5cvpVuyyNMajddaVCTmXNwVgaYvWtvPxDsYHgR0mImzmpygCc1 ENGfyqbS1fT1WpyDAald46CvLmTvzooZW6eC95DZA9hMGFffVWDgqDc8wM0l1xcT2yYc Q/4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=ClZxaIHTxKRPDxkJBLb5KU3Tspcqer+BDthAIA3tZjI=; b=VzHLZgB5n0qJq/S4cZ6E740ze3Vwfff9vj16PKYy6M3tPxxWnGo4kB6McFPZ3gxxlS 2TgOC1DlQ/WBlQQ2+U8HlQgVZ82+JVqFZAUzg3nKCO13KBOK0QSygeNH3S6G/7AMM8x5 FRG04kZ3nSXoFue6ImLFeQAQTMFDdHM0uRjTZ1ZSba5Ie54LERL9Joa8t7MEy4ZXZggv 1ae11uP6qUaB1/hX59qImq13WCTZUf70E5fX0jsASO/c9gm6ttfFmizA7KGWsOvTAFuq QDpiIzlw0FlWRccoHXFjncBkv21B8UCUU6znksu5JSvIrsGZrqC8F4awc5cnCvb6wSZo znEg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c26si27171415pgw.251.2019.04.16.05.56.48; Tue, 16 Apr 2019 05:57:05 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729143AbfDPMzl (ORCPT + 99 others); Tue, 16 Apr 2019 08:55:41 -0400 Received: from mga06.intel.com ([134.134.136.31]:4944 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727821AbfDPMzl (ORCPT ); Tue, 16 Apr 2019 08:55:41 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Apr 2019 05:52:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,357,1549958400"; d="scan'208";a="162363516" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.86]) by fmsmga004.fm.intel.com with ESMTP; 16 Apr 2019 05:52:36 -0700 Received: from andy by smile with local (Exim 4.92) (envelope-from ) id 1hGNZi-00037H-Hs; Tue, 16 Apr 2019 15:52:34 +0300 Date: Tue, 16 Apr 2019 15:52:34 +0300 From: Andy Shevchenko To: "Life is hard, and then you die" Cc: Dmitry Torokhov , Henrik Rydberg , Andrzej Hajda , Inki Dae , Greg Kroah-Hartman , Lukas Wunner , Federico Lorenzi , Laurent Pinchart , linux-input@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 2/2] Input: add Apple SPI keyboard and trackpad driver. Message-ID: <20190416125234.GD9224@smile.fi.intel.com> References: <20190415081300.24831-1-ronald@innovation.ch> <20190415081300.24831-3-ronald@innovation.ch> <20190415090346.GL9224@smile.fi.intel.com> <20190415230955.GA13033@innovation.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190415230955.GA13033@innovation.ch> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 15, 2019 at 04:09:55PM -0700, Life is hard, and then you die wrote: > On Mon, Apr 15, 2019 at 12:03:46PM +0300, Andy Shevchenko wrote: > > On Mon, Apr 15, 2019 at 01:13:00AM -0700, Ronald Tschal?r wrote: > > > +static void > > > +applespi_remap_fn_key(struct keyboard_protocol *keyboard_protocol) > > > +{ > > > + unsigned char tmp; > > > > > + u8 bit = BIT(fnremap - 1); > > > > The above is UB and I'm sorry I didn't find this earlier. > > > > So, something like this would work > > > > u8 bit = BIT((fnremap - 1) & 0x07); > > fnremap is already constrained by the following: "already" is a wrong word here. Compiler checks in the order of appearing, so, for it it is UB and we need to limit bits to allowed range, up to 31 for unsigned int. > > > > + > > > + if (!fnremap || fnremap > ARRAY_SIZE(applespi_controlcodes) || > > > + !applespi_controlcodes[fnremap - 1]) > > > + return; > > and the array-size of applespi_controlcodes is constrained to the > number of bits in u8 according to this assertion > > > > + compiletime_assert(ARRAY_SIZE(applespi_controlcodes) == > > > + sizeof_field(struct keyboard_protocol, modifiers) * 8, > > > + "applespi_controlcodes has wrong number of entries"); > > So I don't see that the masking buys anything new. It buys us the follow to the standard. But gcc is clever enough to strip number to allowed one. -- With Best Regards, Andy Shevchenko