From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45454C388F9 for ; Fri, 23 Oct 2020 14:17:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3E2E2168B for ; Fri, 23 Oct 2020 14:17:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750414AbgJWORE (ORCPT ); Fri, 23 Oct 2020 10:17:04 -0400 Received: from mga05.intel.com ([192.55.52.43]:10641 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750401AbgJWORB (ORCPT ); Fri, 23 Oct 2020 10:17:01 -0400 IronPort-SDR: sD4HPy5LJzeZIebs9M6qxzNTkJvPSUrYPLynj9CsGWIh9RxK5u40YLRmksfORd8fZZpVP4h0hQ OqUQSgxbLmBA== X-IronPort-AV: E=McAfee;i="6000,8403,9782"; a="252379486" X-IronPort-AV: E=Sophos;i="5.77,408,1596524400"; d="scan'208";a="252379486" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2020 07:16:55 -0700 IronPort-SDR: fZkhYQcPT9lU1nvcYX6BQ91UPb6h4pCbwcob9qL3m+WjAQ49Qmsvr44p5Zcz/0I2wqwf/wN5NH 0sNnPyXYK8vw== X-IronPort-AV: E=Sophos;i="5.77,408,1596524400"; d="scan'208";a="349215562" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2020 07:16:51 -0700 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1kVxsr-00E8Fw-6G; Fri, 23 Oct 2020 17:17:33 +0300 Date: Fri, 23 Oct 2020 17:17:33 +0300 From: Andy Shevchenko To: Bartosz Golaszewski Cc: Bartosz Golaszewski , Kent Gibson , Geert Uytterhoeven , Jack Winch , Helmut Grohne , "open list:GPIO SUBSYSTEM" Subject: Re: [libgpiod][PATCH] treewide: rework struct gpiod_line_bulk Message-ID: <20201023141733.GV4077@smile.fi.intel.com> References: <20201023092831.5842-1-brgl@bgdev.pl> 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 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On Fri, Oct 23, 2020 at 02:44:06PM +0200, Bartosz Golaszewski wrote: > On Fri, Oct 23, 2020 at 2:08 PM Andy Shevchenko > wrote: > > > > On Fri, Oct 23, 2020 at 3:06 PM Andy Shevchenko > > wrote: > > > On Fri, Oct 23, 2020 at 2:39 PM Bartosz Golaszewski wrote: > > > > On Fri, Oct 23, 2020 at 12:24 PM Andy Shevchenko > > > > wrote: > > > > ... > > > > > > Nope because gcc will scream: > > > > > > > > error: flexible array member in union > > > > > > Ah, of course. Should be > > > struct ... **lines; > > > > But it is not gonna work... we need an array here. or just one member > > > > struct *lines; > > > > bulk: > > lines = malloc(num_lines * sizeof(lines)); > > xxx->lines = lines; > > > > single: > > xxx->lines = line; > > The definition I used is clearer - it's explicit about using an array > with a single member by default and can be extended as needed when > allocating. According to [1] it makes harder to avoid sizeof() type of calculation mistakes for such struct. >From my point of view extending something that has been already predefined is not cool. But it's up to you to decide. [1]: https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-length-and-one-element-arrays -- With Best Regards, Andy Shevchenko