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=-8.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable 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 DA531C35E03 for ; Tue, 25 Feb 2020 14:17:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BBCA720732 for ; Tue, 25 Feb 2020 14:17:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730588AbgBYORu (ORCPT ); Tue, 25 Feb 2020 09:17:50 -0500 Received: from mga03.intel.com ([134.134.136.65]:39891 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730389AbgBYORu (ORCPT ); Tue, 25 Feb 2020 09:17:50 -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 orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Feb 2020 06:17:49 -0800 X-IronPort-AV: E=Sophos;i="5.70,484,1574150400"; d="scan'208";a="231032368" 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; 25 Feb 2020 06:17:38 -0800 From: Jani Nikula To: "Gustavo A. R. Silva" , Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Patrik Jakobsson , Joonas Lahtinen , Rodrigo Vivi , Rob Clark , Sean Paul , Dave Airlie , Gerd Hoffmann , Hans de Goede , Eric Anholt , VMware Graphics , Thomas Hellstrom , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, virtualization@lists.linux-foundation.org, spice-devel@lists.freedesktop.org, "Gustavo A. R. Silva" Subject: Re: [PATCH][next] drm: Replace zero-length array with flexible-array member In-Reply-To: <20200225140347.GA22864@embeddedor> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20200225140347.GA22864@embeddedor> Date: Tue, 25 Feb 2020 16:17:35 +0200 Message-ID: <87a756sqdc.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On Tue, 25 Feb 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 > --- > drivers/gpu/drm/etnaviv/etnaviv_gem.h | 2 +- > drivers/gpu/drm/gma500/intel_bios.h | 2 +- > drivers/gpu/drm/i915/display/intel_vbt_defs.h | 4 ++-- > drivers/gpu/drm/i915/gt/intel_lrc.c | 2 +- > drivers/gpu/drm/i915/i915_gpu_error.h | 2 +- Please split out the i915 changes to a separate patch. > drivers/gpu/drm/msm/msm_gem.h | 2 +- > drivers/gpu/drm/qxl/qxl_cmd.c | 2 +- > drivers/gpu/drm/vboxvideo/vboxvideo.h | 2 +- > drivers/gpu/drm/vc4/vc4_drv.h | 2 +- > drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c | 2 +- > drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 2 +- > include/drm/bridge/mhl.h | 4 ++-- > include/drm/drm_displayid.h | 2 +- > include/uapi/drm/i915_drm.h | 4 ++-- Not sure it's worth touching uapi headers. They're full of both [0] and []. Again, please at least split it to a separate patch to be decided separately. BR, Jani. -- Jani Nikula, Intel Open Source Graphics Center From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jani Nikula Subject: Re: [PATCH][next] drm: Replace zero-length array with flexible-array member Date: Tue, 25 Feb 2020 16:17:35 +0200 Message-ID: <87a756sqdc.fsf@intel.com> References: <20200225140347.GA22864@embeddedor> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <20200225140347.GA22864@embeddedor> Sender: linux-arm-msm-owner@vger.kernel.org To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Patrik Jakobsson , Joonas Lahtinen , Rodrigo Vivi , Rob Clark , Sean Paul , Dave Airlie , Gerd Hoffmann , Hans de Goede , Eric Anholt , VMware Graphics , Thomas Hellstrom , Maarten Lankhorst , Maxime Ripard Cc: etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, virtualization@lists.linux-foundation.org, spice-devel@lists.freedesktop.org, "Gustavo A. R. Silva" List-Id: virtualization@lists.linuxfoundation.org On Tue, 25 Feb 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 > --- > drivers/gpu/drm/etnaviv/etnaviv_gem.h | 2 +- > drivers/gpu/drm/gma500/intel_bios.h | 2 +- > drivers/gpu/drm/i915/display/intel_vbt_defs.h | 4 ++-- > drivers/gpu/drm/i915/gt/intel_lrc.c | 2 +- > drivers/gpu/drm/i915/i915_gpu_error.h | 2 +- Please split out the i915 changes to a separate patch. > drivers/gpu/drm/msm/msm_gem.h | 2 +- > drivers/gpu/drm/qxl/qxl_cmd.c | 2 +- > drivers/gpu/drm/vboxvideo/vboxvideo.h | 2 +- > drivers/gpu/drm/vc4/vc4_drv.h | 2 +- > drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c | 2 +- > drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 2 +- > include/drm/bridge/mhl.h | 4 ++-- > include/drm/drm_displayid.h | 2 +- > include/uapi/drm/i915_drm.h | 4 ++-- Not sure it's worth touching uapi headers. They're full of both [0] and []. Again, please at least split it to a separate patch to be decided separately. BR, Jani. -- Jani Nikula, Intel Open Source Graphics Center 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=-8.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham 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 63270C35E01 for ; Tue, 25 Feb 2020 14:17:51 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 44AA420732 for ; Tue, 25 Feb 2020 14:17:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44AA420732 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CF6EB6EAEB; Tue, 25 Feb 2020 14:17:50 +0000 (UTC) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 38F736EAEB; Tue, 25 Feb 2020 14:17:50 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Feb 2020 06:17:49 -0800 X-IronPort-AV: E=Sophos;i="5.70,484,1574150400"; d="scan'208";a="231032368" 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; 25 Feb 2020 06:17:38 -0800 From: Jani Nikula To: "Gustavo A. R. Silva" , Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Patrik Jakobsson , Joonas Lahtinen , Rodrigo Vivi , Rob Clark , Sean Paul , Dave Airlie , Gerd Hoffmann , Hans de Goede , Eric Anholt , VMware Graphics , Thomas Hellstrom , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Subject: Re: [PATCH][next] drm: Replace zero-length array with flexible-array member In-Reply-To: <20200225140347.GA22864@embeddedor> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20200225140347.GA22864@embeddedor> Date: Tue, 25 Feb 2020 16:17:35 +0200 Message-ID: <87a756sqdc.fsf@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Gustavo A. R. Silva" , linux-arm-msm@vger.kernel.org, intel-gfx@lists.freedesktop.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, spice-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, freedreno@lists.freedesktop.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Tue, 25 Feb 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 > --- > drivers/gpu/drm/etnaviv/etnaviv_gem.h | 2 +- > drivers/gpu/drm/gma500/intel_bios.h | 2 +- > drivers/gpu/drm/i915/display/intel_vbt_defs.h | 4 ++-- > drivers/gpu/drm/i915/gt/intel_lrc.c | 2 +- > drivers/gpu/drm/i915/i915_gpu_error.h | 2 +- Please split out the i915 changes to a separate patch. > drivers/gpu/drm/msm/msm_gem.h | 2 +- > drivers/gpu/drm/qxl/qxl_cmd.c | 2 +- > drivers/gpu/drm/vboxvideo/vboxvideo.h | 2 +- > drivers/gpu/drm/vc4/vc4_drv.h | 2 +- > drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c | 2 +- > drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 2 +- > include/drm/bridge/mhl.h | 4 ++-- > include/drm/drm_displayid.h | 2 +- > include/uapi/drm/i915_drm.h | 4 ++-- Not sure it's worth touching uapi headers. They're full of both [0] and []. Again, please at least split it to a separate patch to be decided separately. BR, Jani. -- Jani Nikula, Intel Open Source Graphics Center _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel 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=-8.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable 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 9C025C35E01 for ; Tue, 25 Feb 2020 14:17:53 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 78BDE218AC for ; Tue, 25 Feb 2020 14:17:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 78BDE218AC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 379A76EAEC; Tue, 25 Feb 2020 14:17:52 +0000 (UTC) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 38F736EAEB; Tue, 25 Feb 2020 14:17:50 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Feb 2020 06:17:49 -0800 X-IronPort-AV: E=Sophos;i="5.70,484,1574150400"; d="scan'208";a="231032368" 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; 25 Feb 2020 06:17:38 -0800 From: Jani Nikula To: "Gustavo A. R. Silva" , Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Patrik Jakobsson , Joonas Lahtinen , Rodrigo Vivi , Rob Clark , Sean Paul , Dave Airlie , Gerd Hoffmann , Hans de Goede , Eric Anholt , VMware Graphics , Thomas Hellstrom , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann In-Reply-To: <20200225140347.GA22864@embeddedor> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20200225140347.GA22864@embeddedor> Date: Tue, 25 Feb 2020 16:17:35 +0200 Message-ID: <87a756sqdc.fsf@intel.com> MIME-Version: 1.0 Subject: Re: [Intel-gfx] [PATCH][next] drm: Replace zero-length array with flexible-array member X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Gustavo A. R. Silva" , linux-arm-msm@vger.kernel.org, intel-gfx@lists.freedesktop.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, spice-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, freedreno@lists.freedesktop.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On Tue, 25 Feb 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 > --- > drivers/gpu/drm/etnaviv/etnaviv_gem.h | 2 +- > drivers/gpu/drm/gma500/intel_bios.h | 2 +- > drivers/gpu/drm/i915/display/intel_vbt_defs.h | 4 ++-- > drivers/gpu/drm/i915/gt/intel_lrc.c | 2 +- > drivers/gpu/drm/i915/i915_gpu_error.h | 2 +- Please split out the i915 changes to a separate patch. > drivers/gpu/drm/msm/msm_gem.h | 2 +- > drivers/gpu/drm/qxl/qxl_cmd.c | 2 +- > drivers/gpu/drm/vboxvideo/vboxvideo.h | 2 +- > drivers/gpu/drm/vc4/vc4_drv.h | 2 +- > drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c | 2 +- > drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 2 +- > include/drm/bridge/mhl.h | 4 ++-- > include/drm/drm_displayid.h | 2 +- > include/uapi/drm/i915_drm.h | 4 ++-- Not sure it's worth touching uapi headers. They're full of both [0] and []. Again, please at least split it to a separate patch to be decided separately. BR, Jani. -- Jani Nikula, Intel Open Source Graphics Center _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx