Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp223098rwo; Fri, 21 Jul 2023 10:49:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlGcpEzWqJKMZDeCmMPCwkPAMsN8XVfqPA72wlCWmTakQ5xGwyohbsPUVY1cUUbCSdgAu8qC X-Received: by 2002:a05:6358:528e:b0:134:c859:d32a with SMTP id g14-20020a056358528e00b00134c859d32amr974526rwa.25.1689961798522; Fri, 21 Jul 2023 10:49:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689961798; cv=none; d=google.com; s=arc-20160816; b=kTK/pn5ROzgM0+1JGh4L2y1K+aZ4GF5aVoQaKiQ0+uBXwtiarOjjamBaxLKQlUTHlv qEGHf8x7oM1Bibc2DQUxZUlGFOPC1lwDsZ8PDbn3BA7ERbSGKxCcEVXTJO03X88Ynua4 HO1IsigQa3/IoDxHP++vEASQXgW34S3o5Ie3LzCHg5lDU99TFkV9HgN3N//8g7lCJZk9 ShgERU4A1jApKj8mQtIHucQVAC7KF9dLpG0pS77Fq4WoFou6UFFoa0lyvm7NNUecOBBC ZGC9Dm46MmGT4xtnhLMMLotQ+ZeVM9vVN4eH/9ZSCQB7kpxKKbwVsZpxSDzv77PaZ+fg a4Bw== 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=6UQv7LoCfNcqEChzqKpVr6bWB18pWUfOhiyUgSg7ouE=; fh=WnGIB8+qyyI8CsWB534PnOURHN5AEKd6xwItIFl1QZY=; b=B6jrtDCn0/IgJdkD+F1Eyly0YyvkAsx6zjWqgoX+BgJMs1w/wDbdVaxz8fusDgDr/P MqA9Iq7p49zeLTN8smBv4m7av6vwfALNS5bkCVp8KJk5s/7P1lC8HQtIQ79dKNUnDP2e /CfdVby6DcNclPwa75ERIA95rw0dcjfKgmVvy2a/9kacvfsGbCIvw2dGHKld7PTsmeQY EllphweoHvij0PSlbdiyzoYcJoW8Q6/bwy3ZUlIIbQst6usBZXr27X1J1enNLQXSTI/E nMSz+laGQp1GzR76gREoTwy6xswdp3JP4FlLNweEPgKnUpZst6RugiLf0nsdr/FljNwA yTiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CaouzBx2; 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.49.46; Fri, 21 Jul 2023 10:49:58 -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=CaouzBx2; 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 S229529AbjGUR0T (ORCPT + 99 others); Fri, 21 Jul 2023 13:26:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231430AbjGURZs (ORCPT ); Fri, 21 Jul 2023 13:25:48 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3714D4201; Fri, 21 Jul 2023 10:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689960321; x=1721496321; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=uIkKjPDawoiFfENQmTtdTBfG12v/OWQvuxstItlhHZQ=; b=CaouzBx2yMOQFqU0TJ217seSK0E3LycMZGVcoe0Xr1FrH8V8k++tgY6l 7BegXuUcwE9WoW7bbX+yFsDrJwngGkOzZpsUJ0UAoMSsKMnE29YxfiaLY G0APKZLkTlCIj5JKtu77ZKtZHXqEYe7uEcqYMXClBkrUvGP3v/4uuWjS3 Gmwyrb/+ekXHiLhq+Y2V1EISsVi99w/HKGOOwXfRn+VqcwKOufhH4tc0y 4XqepSs5Vgt+v8MA3Kq2pwVTY453pCPGSJYCBnlIYVFL2lBQvichaGWBV LZLSpLxmRDEg97dsWZX4tgK16MkRonA7Pb9ZKAfqkRj4Sm6A7RfKYbG9g Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="351959630" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="351959630" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 10:25:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="795031707" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="795031707" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga004.fm.intel.com with ESMTP; 21 Jul 2023 10:25:14 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qMtsO-00ER2L-2D; Fri, 21 Jul 2023 20:25:12 +0300 Date: Fri, 21 Jul 2023 20:25:12 +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: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). -- With Best Regards, Andy Shevchenko