Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp186530pxk; Wed, 9 Sep 2020 02:42:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsfXbQP0+Nwkac9wA/NUDywQ0Voj7879NurO0HzxixHDPmXZw23Gn1UP963WqG08V4X2ru X-Received: by 2002:a50:e807:: with SMTP id e7mr3304256edn.84.1599644568162; Wed, 09 Sep 2020 02:42:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599644568; cv=none; d=google.com; s=arc-20160816; b=NuHNTNn2H3Fl06Wf58a2I10GZj8l0XSGO5k3a0RVSWeR+6v0LzpL5j3nOrnUKI07NM 5clhmc8k+itbsPgvQWshFh7O8kBx00AZac6BxC4bljF40e42oOSJiJBw5j10A8a+pX/P MB7Xink438m/bRw/Ya7dxDt9lHflXtwywa3rCkWrhUe2LNObI81fb+R6/wn+rV4k2/UW lfXBPhrKPddngHDtOt0HjNhqiIIpZ2Ka14Og6g0jxN8LyTB09x3oS2Ugk/PLwTTLDeRo Q1tHeO9ZMI/bH2QGcHT4vgo1qmv3Y5DJGkHVS4IdyzrdE95Wp2yCLqavRupuQ29Mx0f5 yFWQ== 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 :in-reply-to:references:mime-version:dkim-signature; bh=T5ZH6tpiwfQ5fkv123INJrXWMFwMdaXrCNUYVgSIWI4=; b=Q1a7ZR9PYp1nA7rLxDlnC4r+DDTNVi7Z3MW3ZMe0mmx4A8nWLVI3G3WrB7kSa9sytw nrPOu6mVQ8aRyeYlT8aWE6aBa79xvnIHvQM1mcm19Ch+8H74kqk6Ei4LQ9+plTLXa6gT r55N89ay1i7tg9mxTI6LjCwfDOTZL5dG+OgMbC8HDDVuP+YyWrC2iHe4hNvc9tD4VoRQ PKRn3yWbN50sCHvhQhZaeY0xT/hpIEiDLRN9MKsxiUJKJ/Nyfetlwg7H79GvwQ7sbYw5 bm8uBqkoCpm9kt0wRsVuCs7Y/reD3jCFdQk1YZ88S1NOSTGkneXrKspY5RQTT52njH2i /fMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=xLBTyw9a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e3si1217213edj.131.2020.09.09.02.42.25; Wed, 09 Sep 2020 02:42:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=xLBTyw9a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726169AbgIIJlt (ORCPT + 99 others); Wed, 9 Sep 2020 05:41:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726060AbgIIJlr (ORCPT ); Wed, 9 Sep 2020 05:41:47 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E237C061573 for ; Wed, 9 Sep 2020 02:41:47 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id c8so1973230edv.5 for ; Wed, 09 Sep 2020 02:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=T5ZH6tpiwfQ5fkv123INJrXWMFwMdaXrCNUYVgSIWI4=; b=xLBTyw9anFQR+Kd7rhXDv95SHUeqRvsrFyIPWyC7lK4IT43ttofu28gInL/oBJiZHG zY0xcKEvl/VlNT2DvH8wR+R1NvWnawwteul+afp80y/DIXoj7Pg+m+Dk5S9NRGQZQxJS e3InbabcRiDRO0ykYIFEHeVHlRRsaB6EVELbndvv/AbXHqDGczyL3wbT3c0DjtochAGD WPKU4F9e//wlu2KdPwBkspVAGF31KAgd28zIx9sY3MgctFYl1wLfgwpxzyUBUz9Avkwc nCg7/9jvn+LPUzuKp30mDjgcu9Vy1qVz1sbXBBdhkpamrbRszAwwQQ008ompPs/NYAh3 Lsyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=T5ZH6tpiwfQ5fkv123INJrXWMFwMdaXrCNUYVgSIWI4=; b=goQl1DKK+CNIksdji4BEqrfTWc6XLPIABrInPDFntSla8EHJmoenVHyhSYmH8HOY5r /yxZRYd9OFN0AueX7IMqqm5Rcy9qqyrxyZ4gjHAX+lFa2qAId63lyMddBOsFd21/7L+b 6FZqxN12jd30JQU2iwJJ5+0b+chuTnSfxcbvPlV/auN2FHbhYxZS7BlsNccOR9kvxxMF G8o9hm1JkZZN/SGVfWYruWwIV0H4uhJ4EG/NKhesDBWOVa/ki3+3s9qG+m/PP+/zfkGK LXa5TEqqFsOXKxqq9jwWNdzD6Arl6Uanfzyp+wpUU0SIELO+K+Rqu7xaK/kX7s0sX0Y0 7rqQ== X-Gm-Message-State: AOAM530Ebr5BWRto6RBY3/5OhIgxnJmJhGYENsg2n3Rld+SGNVJJWVTe eoceb65ixY3U4LkQWGY8nys1SZkieiGBYLb+wlbkVA== X-Received: by 2002:a50:99d5:: with SMTP id n21mr3214899edb.88.1599644506197; Wed, 09 Sep 2020 02:41:46 -0700 (PDT) MIME-Version: 1.0 References: <20200905133549.24606-1-warthog618@gmail.com> <20200905133549.24606-8-warthog618@gmail.com> <20200909092401.GA1431678@sol> <20200909093523.GA1506132@sol> In-Reply-To: <20200909093523.GA1506132@sol> From: Bartosz Golaszewski Date: Wed, 9 Sep 2020 11:41:35 +0200 Message-ID: Subject: Re: [PATCH v7 07/20] gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL To: Kent Gibson Cc: LKML , linux-gpio , Linus Walleij 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, Sep 9, 2020 at 11:35 AM Kent Gibson wrote: > > On Wed, Sep 09, 2020 at 11:26:00AM +0200, Bartosz Golaszewski wrote: > > On Wed, Sep 9, 2020 at 11:24 AM Kent Gibson wrote: > > > > > > On Sat, Sep 05, 2020 at 09:35:36PM +0800, Kent Gibson wrote: > > > > Add support for requesting lines using the GPIO_V2_GET_LINE_IOCTL, and > > > > returning their current values using GPIO_V2_LINE_GET_VALUES_IOCTL. > > > > > > > > The struct linereq implementation is based on the v1 struct linehandle > > > > implementation. > > > > > > > > Signed-off-by: Kent Gibson > > > > --- > > > > > > > > > > [snip] > > > > > > > if (copy_from_user(&offset, ip, sizeof(offset))) > > > > return -EFAULT; > > > > @@ -1104,6 +1505,25 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt) > > > > MAJOR(devt), gdev->id); > > > > > > > > return 0; > > > > + /* > > > > + * array sizes must ensure 64-bit alignment and not create holes in > > > > + * the struct packing. > > > > + */ > > > > + BUILD_BUG_ON(IS_ALIGNED(GPIO_V2_LINES_MAX, 2)); > > > > + BUILD_BUG_ON(IS_ALIGNED(GPIO_MAX_NAME_SIZE, 8)); > > > > + > > > > + /* > > > > + * check that uAPI structs are 64-bit aligned for 32/64-bit > > > > + * compatibility > > > > + */ > > > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_attribute), 8)); > > > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_config_attribute), 8)); > > > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_config), 8)); > > > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_request), 8)); > > > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_info), 8)); > > > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_info_changed), 8)); > > > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_event), 8)); > > > > + BUILD_BUG_ON(IS_ALIGNED(sizeof(struct gpio_v2_line_values), 8)); > > > > } > > > > > > > > > > A couple of things here - these should all be !IS_ALIGNED. > > > And the BUILD_BUG_ON gets compiled out, and so doesn't fail, if they are > > > after the return. > > > > > > How would you like that fixed - v8 or a patch once v7 is in? > > > > > > Cheers, > > > Kent. > > > > v8 please. Why is it compiled out though? Does it need some config option? > > > > Not sure - haven't looked into it. I only noticed the condition was > inverted in passing, and when I flipped it it still compiled. > Moving the return to the end of the function made them all fail, > as they should if IS_ALIGNED is true. > > Having BUILD_BUG_ON being able to compile out quietly is a problem in > itself. Nothing special in my setup that I am aware of. > > Cheers, > Kent. From include/linux/compiler_types.h: 295 #ifdef __OPTIMIZE__ 296 # define __compiletime_assert(condition, msg, prefix, suffix) \ 297 do { \ 298 extern void prefix ## suffix(void) __compiletime_error(msg); \ 299 if (!(condition)) \ 300 prefix ## suffix(); \ 301 } while (0) 302 #else 303 # define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0) 304 #endif __OPTIMIZE__ is a predefined macro. I'm not sure about your setup but it it's defined for me in all my yocto SDK builds and BUILD_BUG_ON(1) fails as expected. Bartosz