Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp222386rwo; Fri, 21 Jul 2023 10:49:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlHp5QVJW69pC4cFatI7ufSqV9qK77j4KJQEjCzdDI17+Js48dfWx5cPZ2hVNg2IZ/CxJrv7 X-Received: by 2002:a05:6358:262a:b0:134:cbff:c5a4 with SMTP id l42-20020a056358262a00b00134cbffc5a4mr687137rwc.18.1689961745352; Fri, 21 Jul 2023 10:49:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689961745; cv=none; d=google.com; s=arc-20160816; b=gKt5ntBkzfoV6n8t6m5jKt/6seKP8jnrw4NzuvVbwCOfOxXJvcbMFLiY8UDm0SBfof +ZY12mrnsQzntpFxBvlEvtvopCrACQ7ELE/BURYGbUyovu64bcFueujbP9PUOHv12Z+/ XyiYNUfCRUlxS8B0mnJiZi5WquHowL/ptwd8+XzDvC3PrIbQcSARLyPYAk1oDD1FPaNb kKBws6o3w3C1IsuAWN7RQ17Edx1dEFKffRVWASsqOq0zfv/zUluVICjKATcqIZxa526S 59ajmQZdySYNAwNV2fFjzv7Y5XO1jDvZ9YDcTya3125gOKg0Z21lpMpmhpIJWs1xyjL/ p9tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=I1CEVNTx8ZSWMHKSNDzXZMNpVGxfQIqkDj5nEUnHVGI=; fh=WnGIB8+qyyI8CsWB534PnOURHN5AEKd6xwItIFl1QZY=; b=eBLin7OOBTJBLKtUEtN3+MzOV4C1mnCLu0hTgHMna6yv7WIe8cfj85OTnI0U8/CyKN 0ltlfLaq1xOdtUxKfaQo0Lu21WqYrxZQIrOGit0K+K/pExSszbWWY4bU12hHSr8ycMDe 9TbLdxFKgtFbcKNpbuHaMFB9DojDdxgBoyv7+UVm+D1wFdq5f7Ogvf4fGLwvf/aWnISq i/2Kk9uOGhIOmMK2TUd0FAbWJSqcvkLeU8hptqK442GEWKrTKoU9NDWmAS96WtMfe96J MeiQSiFR/WwR9bTpl6WMrfREQxlbXfw1u/T/01c8aFRq0mYCf6HreeZtdYV2/RzzE2yt a5IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="niR0SG/H"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k3-20020a633d03000000b0055ffed72411si1300255pga.411.2023.07.21.10.48.43; Fri, 21 Jul 2023 10:49:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="niR0SG/H"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229819AbjGUR17 (ORCPT + 99 others); Fri, 21 Jul 2023 13:27:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231539AbjGUR14 (ORCPT ); Fri, 21 Jul 2023 13:27:56 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EFBE2691; Fri, 21 Jul 2023 10:27:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689960474; x=1721496474; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=pj63wD4/DYQgakoYsXMEa/0XH9I2qq7zxenF6w6n6eY=; b=niR0SG/HMtSCG855A5TjhShBe6XgOaLf6ySSmK6sQ9qBxOwrwhVVe1Qg UOIYpUKSjGhQJJezMDxPgNRa4D5T/j8vT7xLTzgV1sNeUXp7RvP47dw+U tloEk/Mn4RIsva0Ypht+OT66nTxfqxSwLY/gRmylRZHn/g5c1XY5Xd7iH 4/rKJcejr5yOlkpLX6xUqELR7CAHh+gPcAzu1d/vJi7NFomdkqg7XIcYv OABkyncrcI9A1zy97tQmfX/RLPPXvJsm/z6AvLxHv5+x+d4LCtteHQ9bc 960LkFEmZ18HmaKrX8mMh+qRuTZL0m4VftC52YTceXSjuKD9S4JyMfguF w==; X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="453453164" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="453453164" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 10:27:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="815036936" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="815036936" Received: from smile.fi.intel.com ([10.237.72.54]) by FMSMGA003.fm.intel.com with ESMTP; 21 Jul 2023 10:27:51 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qMtuw-00EWnk-13; Fri, 21 Jul 2023 20:27:50 +0300 Date: Fri, 21 Jul 2023 20:27:50 +0300 From: Andy Shevchenko To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Nuno Sa Subject: Re: [PATCH v2 1/8] iio: core: Add opaque_struct_size() helper and use it Message-ID: References: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> <20230721170022.3461-2-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 21, 2023 at 08:25:12PM +0300, Andy Shevchenko wrote: > On Fri, Jul 21, 2023 at 08:22:35PM +0300, Andy Shevchenko wrote: > > On Fri, Jul 21, 2023 at 08:00:15PM +0300, Andy Shevchenko wrote: > > > Introduce opaque_struct_size() helper, which may be moved > > > to overflow.h in the future, and use it in the IIO core. ... > > > +#define opaque_struct_size(p, a, s) ({ \ > > > + size_t _psize = sizeof(*(p)); \ > > > + size_t _asize = ALIGN(_psize, (a)); \ > > > + size_t _ssize = s; \ > > > + _ssize ? size_add(_asize, _ssize) : _psize; \ > > > +}) > > > + > > > +#define opaque_struct_data(p, a) \ > > > + ((void *)(p) + ALIGN(sizeof(*(p)), (a))) > > > > Hmm... This can potentially evaluate p twice. > > > > Perhaps this variant is better: > > > > #define opaque_struct_data(p, a) ALIGN((p) + 1, (a))) > > > > Besides, I don't think we should worry about @s evaluation in the main macro > > which may be simplified to > > > > #define opaque_struct_size(p, a, s) \ > > ((s) ? size_add(ALIGN(sizeof(*(p)), (a)), (s)) : sizeof(*(p))) > > > > Thoughts? > > Also we may leave the struct always be aligned which makes the above even > simpler (but might waste bytes if @s = 0). > > #define opaque_struct_size(p, a, s) size_add(ALIGN(sizeof(*(p)), (a)), (s)) > > (with the respective documentation update). Jonathan, this patch can be skipped and if you are okay with the rest, the rest may be (clearly, I have just checked) applied without as there is no dependency. -- With Best Regards, Andy Shevchenko