Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp193379pxk; Wed, 9 Sep 2020 02:57:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxI7rGYFNDQZ9lxdPiWJ+MoqAnrMrIQiGbabawtd5LJOnllzMEfwnTpm+Mi0AU7V7OXoYsV X-Received: by 2002:a50:cbc7:: with SMTP id l7mr3251858edi.148.1599645440995; Wed, 09 Sep 2020 02:57:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599645440; cv=none; d=google.com; s=arc-20160816; b=mdzv/rPe/B7S1QRlFzEEIhbqH6ztb8XdDVa4zDJ393qQ+3jSYltEHLw0vfJAxlGm6f 5KIS51s/rub3BYIY21R2N9yuX2tuuvcCRmr4ruMsgdX5aqf35JQT9Vvb2Sj8l1gHB2li rwBQsSsYl3hDC8ktcXjA+ozKogtTv2IEsF7hyR7FXqw533emKFUjNWTXUxzxJt5tNXYc K3WZnIujN8r34rfbJt9qiH0a1hx1M6fPKegQ7VN+3Gt1ytuyD6Kp3f8xIA8k1XGR9pDa vHBLNiPbZHPHPNN12E/yMtQYPq6IgErmIBBh5dG+ctH74ez9piSzxsznqOQX2fGegpcx xpfA== 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=GLnm6fS50/hG4SKqNnvGF+6eSY1pTc2O9uX9RZ49myk=; b=jV5RmJRXKm/yC68QE/YCmpT2TwNv1KsqzTMJQ0W5fyhAMvcyB8FkO/LQCNTzn2Lf50 R7hp1mGmfjtxsOQDa9nurBU+pWz/+ikdld4nffh5FC9/SNTsGrkw8Y+hbDXkPHJzVwUH 6P7pl3VbhcEueDSkB2UAUimNUqzpUd6wIXOCfhYsSDFF2YVtl8u+OU/vgCeCrOsTq2re xr2UwiHvcOh8tsyttWGUoVBkYFXxCf336AF1nkFU6rvS/eySWolebDgoG09vwzTgn9Xe p63aZZknoFDxa9irQg/5nypxeadyKBw/MlFDvBUOE6FIbn17uFOTyvbv6rtf9Zr8XBGX rq4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=K0Bpd4sM; 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 bc11si1104459edb.532.2020.09.09.02.56.57; Wed, 09 Sep 2020 02:57:20 -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=K0Bpd4sM; 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 S1728325AbgIIJzI (ORCPT + 99 others); Wed, 9 Sep 2020 05:55:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725975AbgIIJzD (ORCPT ); Wed, 9 Sep 2020 05:55:03 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73274C061573 for ; Wed, 9 Sep 2020 02:55:03 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id z23so2590140ejr.13 for ; Wed, 09 Sep 2020 02:55:03 -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=GLnm6fS50/hG4SKqNnvGF+6eSY1pTc2O9uX9RZ49myk=; b=K0Bpd4sMj+C4pc3ZDNHmKtT83kJehH18+rcC+ENWJR7Oxn2a667as6qJrWgwW946bR Xg3jo8zS+WwbSp6UuDDzcGfAVPoO3/zzXOv+WIGcGP5p+vcsmovO933p+uslYiCCzkty +Trq8Kvp8WBhDgBwCwn0hYLR1iUCxXqu5LK10r900FFtFa/0seNDIG1T3rCCUSsaDVaf Vetd2+oj7M1izcXeBAc6kHf8GjeqlMNMxEk2DEHto7Rf3ckMKKdbG99GAIxxGHrqPTyE ELluZvF5z11vZqkF3aneOd537ITjr4bn9dJA9jwJ7Y+DpHwq6kbReij7/S31SLhSXWul huVQ== 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=GLnm6fS50/hG4SKqNnvGF+6eSY1pTc2O9uX9RZ49myk=; b=R041ybswMDd6zFypV6zR8LesJMJhYLpVe+oKxB6IU3gItHiiTDeGy+pwcCRaQpgQPb EiepZW+FJhiXoi+mnjIQGn2axFmWb+plPfzpxm7Nf5L/FI3P7vDfct4U6KoOSzbeH4QZ hTVGPgXGsoOpjUgnsfPUsntaA7GGBqdKFcxvv9IYt0cgUeyn5X0nQ63+CNdo4aEDQN+X BHdEDTIfENBiXrxHumEdx+S26xxcZ4AhcRgaExaIDRhO5OfKYLF3cCGv1AyacY6R8Mdy geDiIW9jp57ICO8GDrDo3HQVLAR4jbUZBjIfrQgCux7znlikcw4ToLoTHZFw3+tJLNX5 0Nng== X-Gm-Message-State: AOAM5304/CNLMC49PzHuCrtmcg3qseqZpfbavhZwcRvlLtMUbygku6Q9 B2zngkpgBA0nmVsRtLVmHsR5PDzKDKsHhDLuvnBZ2Q== X-Received: by 2002:a17:906:c1c3:: with SMTP id bw3mr2741235ejb.516.1599645302156; Wed, 09 Sep 2020 02:55:02 -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> <20200909094906.GA1550063@sol> In-Reply-To: <20200909094906.GA1550063@sol> From: Bartosz Golaszewski Date: Wed, 9 Sep 2020 11:54:51 +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:49 AM Kent Gibson wrote: > > On Wed, Sep 09, 2020 at 11:41:35AM +0200, Bartosz Golaszewski wrote: > > 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. > > > > Even when placed after the return, as was the case here? > > Kent. No of course not, I put it into a void function. Sorry for the noise. I'm not sure how to disable optimizations for a macro. For now putting it before return should be fine. Bart