Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp5600699ybf; Thu, 5 Mar 2020 03:41:29 -0800 (PST) X-Google-Smtp-Source: ADFU+vuLdFi1nWc9wn5L/9cK72HLj3Qfl1w2074DB0nRDsaKE8tuueO94YpRCXKRFtA6m6WQHRLq X-Received: by 2002:a9d:4810:: with SMTP id c16mr2710864otf.248.1583408489453; Thu, 05 Mar 2020 03:41:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583408489; cv=none; d=google.com; s=arc-20160816; b=aiLIXabEsuvlP7BcIji12/RoOYK1s3pCyQIYSQ9V8cKMVaJuQmK3sZiVrV63od4MuX wS8GX0O5VHCChN4D5w35yGFuhsw8M3Jmewrssj//Rg2FOpU6brXS5u7wmZNsURgq5Kgk uB37ENLpF+DdXz3BZEyJNYBwcE67q6iLVohLUgGBTear6iQngbMi/Ho3zYjLbWatkzMO Oi8P9KdszyH8kqFuNQjW7R+zX9blMa1dTLtg+h6ohuzKEIiWgXxdUDBN/zNSljaxQ+WA dycZfzuM5EQ6t/gGqfcfd+TqpanczLcXaj3pIa+JKBZILGeb1Uzlr/1Bk0ePf5ExPulu fuHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from; bh=gyJMKP9dXiXt9LN7kLQjwDI5QRhO7cv2oU0ain+qNJg=; b=GmImSKuf/POE6FoDXtBAFmJiXTn2M5EB9I59HurDIVUvH2Lh52EF9uLmIwF7rbCL5F nQh4R1PBvuJ71kd7kHsP8HWLidBSgAfRYnY9DxTQRPzDt/hN9Q70wkWBhJUvvSn8orMk cV2h2LTKPzYNQ8/T4qcieCXH6+vWw5gyje37cB4tGUFWuZ1Jq0u6hR8sbxVo37ug4wfl gZJGnWw0QGreEvwXNhKAGRS9rZ/wK8x3VPckyYssSxvo9AL+HfGb0m19J+1fzsztYaCZ MUSQ0qoaLbGKMGfhk9bBfogsE0e48f+gJpLMMBISqkT96kOQH4TczUupfPeUDCI4jAWs Kg7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w25si2988668otm.223.2020.03.05.03.41.18; Thu, 05 Mar 2020 03:41:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727452AbgCELk5 (ORCPT + 99 others); Thu, 5 Mar 2020 06:40:57 -0500 Received: from mga17.intel.com ([192.55.52.151]:54812 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725912AbgCELk4 (ORCPT ); Thu, 5 Mar 2020 06:40:56 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2020 03:40:56 -0800 X-IronPort-AV: E=Sophos;i="5.70,517,1574150400"; d="scan'208";a="234389164" Received: from jnikula-mobl3.fi.intel.com (HELO localhost) ([10.237.66.161]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2020 03:40:52 -0800 From: Jani Nikula To: "Gustavo A. R. Silva" , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, "Gustavo A. R. Silva" Subject: Re: [PATCH][next] drm/drm_displayid.h: Replace zero-length array with flexible-array member In-Reply-To: <20200305110105.GA21188@embeddedor> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20200305110105.GA21188@embeddedor> Date: Thu, 05 Mar 2020 13:40:49 +0200 Message-ID: <87y2sfni66.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 05 Mar 2020, "Gustavo A. R. Silva" wrote: > The current codebase makes use of the zero-length array language > extension to the C90 standard, but the preferred mechanism to declare > variable-length types such as these ones is a flexible array member[1][2], > introduced in C99: > > struct foo { > int stuff; > struct boo array[]; > }; > > By making use of the mechanism above, we will get a compiler warning > in case the flexible array does not occur last in the structure, which > will help us prevent some kind of undefined behavior bugs from being > inadvertently introduced[3] to the codebase from now on. > > Also, notice that, dynamic memory allocations won't be affected by > this change: > > "Flexible array members have incomplete type, and so the sizeof operator > may not be applied. As a quirk of the original implementation of > zero-length arrays, sizeof evaluates to zero."[1] > > This issue was found with the help of Coccinelle. > > [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html > [2] https://github.com/KSPP/linux/issues/21 > [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") > > Signed-off-by: Gustavo A. R. Silva Reviewed-by: Jani Nikula > --- > include/drm/drm_displayid.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/drm/drm_displayid.h b/include/drm/drm_displayid.h > index 9d3b745c3107..94b4390bf990 100644 > --- a/include/drm/drm_displayid.h > +++ b/include/drm/drm_displayid.h > @@ -89,7 +89,7 @@ struct displayid_detailed_timings_1 { > > struct displayid_detailed_timing_block { > struct displayid_block base; > - struct displayid_detailed_timings_1 timings[0]; > + struct displayid_detailed_timings_1 timings[]; > }; > > #define for_each_displayid_db(displayid, block, idx, length) \ -- Jani Nikula, Intel Open Source Graphics Center