Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1016548ybj; Thu, 7 May 2020 12:47:07 -0700 (PDT) X-Google-Smtp-Source: APiQypKQ5Ad45kVot/0BYfyehZLM2w/16T6StaOsnw3eQdr0EVped3i0P9L7lo7WGHxMIRuiH+Yb X-Received: by 2002:a17:906:5004:: with SMTP id s4mr14111308ejj.13.1588880827180; Thu, 07 May 2020 12:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588880827; cv=none; d=google.com; s=arc-20160816; b=dWHSp7/2iz1QxHJBhj/6svubmtTL8rn5wLc2LVeSBfcgmSkCC3OGCpoezBLnjju3o0 UkKhAPzZauw/ZcXwBtu9A848BWpK+35KFb75aMGgT5s9FSsxCk3JdkmDr9RWxY7Vi/IX owjEEBnTIBxtjy2te051NR8iyyvUFmhcYrGTU/Zci9rQUqrmXYBajbOSkKBYjR66ub7v 9Xe0jgfOvWKWRqD70nqJCDKeJ/VxbmHTapbYAEyCkD89OHT0KURVSmM+xmgQxogNLw4I 5l4EHomzMPWrcShnmDpRxKTFBcurOIY6eaN6H7JcvugPoBGIufzYK7a6r2WkiaG6AKwd rskQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=qoD2bZDUs9J4Y+pRwsgjWSZscZZ8lr8WrrU2ArQm1+E=; b=TmnXKtke2HQmbHg9AQ0zzW1KPmcGCt2zcPiWs61pos4LB5QMEPuZlP6243bZ760Lop YSbc7yTS5q7Yym4vWAscy12dXNOiKewLB85AFtH/YYs43d1ePkIpofZSTl45dqWwyYCV ChgI5qU582Zv98MEn1zlcRkfZgh3BeXg4j15hWrOr5DdMYL5ggggN1y49kmqn+nnjEU7 +7ElD2gO4g607eZ3XsKGuOa3ISxcEyuMcVG3mPocV/5UiXyEjJaANKwufBDgILIjEBTf 2FlTzYS8J1k/8oso+JNCcLVWWDJViL8JF0iF07nt9QDa6a8cPcRv9ZpianfLa9ql/ygY Yx0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qEXnogpv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q24si3068373eja.278.2020.05.07.12.46.43; Thu, 07 May 2020 12:47:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qEXnogpv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728385AbgEGTpA (ORCPT + 99 others); Thu, 7 May 2020 15:45:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726326AbgEGTo7 (ORCPT ); Thu, 7 May 2020 15:44:59 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25950C05BD43; Thu, 7 May 2020 12:44:58 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id w29so5900201qtv.3; Thu, 07 May 2020 12:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=qoD2bZDUs9J4Y+pRwsgjWSZscZZ8lr8WrrU2ArQm1+E=; b=qEXnogpvMgfAUsWLQ7qJDwyJu6KxBTy6I7hkk0GyXjbtogPeqETsPqiehRQ2tUx5xG tTgg0FoFdT4IxC79TAkz7OMiUOunwNyx3PjSb69ThWT/70cJ+c19OKU8ZDpa3UHf4TL1 pz/Eo28TV9RyMzmfhbuWaGw6wQYi7//E76EQnGhNw8Dqr1yak0SAys9qp4SRwRgFmH4t B/5nuA0H+eMO/BRrcG5uAFl7AFTdphJXcQPN83KXSFa8WSkLtfsDEv+8L2MZaF/T/lr7 33iLWtJ2WMyTuGfWwgghtfUgwG3tB6vRfVJVUpN+7xLcj6+bgz+iwaDJmPlppn0AixSJ Ew3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=qoD2bZDUs9J4Y+pRwsgjWSZscZZ8lr8WrrU2ArQm1+E=; b=ZGHpWu3ng8uIfNPrZSt4iESqktfXotE7mMw+ZuK2cD/4ytva6eMEc1rhIAoRyuqP4O NC9l7I4/w9hbCxBjrqP+X582N3wbyriCMaEPlrBytzkbfqvU2cOL+hjlaG2tuCz9mviw ZPp27XpqC4YIAVBAFjMM3r6Ea3F+ZxyyqkzBJEQ/M2RlfJRqJmQoHjzpQyBIcf2m4TuI mzcjkLxULdQD0L2L5DNSRqrpxJAwmasJlm3XueyMCb/xXDy8DYD9TV/YEUB/x2RgvioO 67wx5BU99firJ+hjqL0Hg6OMI15TPqfmpujRaCdbAiYqqurq6ShR63v06tHILQQUNIev emyA== X-Gm-Message-State: AGi0PuaDiL7RC5CL5MjLKeZJjKXoqw+7WgmQsx32wPOnPAOMasCi82vr 1knN1hfLJLN02p0nw++47E4= X-Received: by 2002:ac8:1628:: with SMTP id p37mr15930726qtj.179.1588880697291; Thu, 07 May 2020 12:44:57 -0700 (PDT) Received: from localhost.localdomain ([168.181.48.228]) by smtp.gmail.com with ESMTPSA id z65sm5196436qka.60.2020.05.07.12.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 12:44:56 -0700 (PDT) Received: by localhost.localdomain (Postfix, from userid 1000) id 08D8DC1614; Thu, 7 May 2020 16:44:53 -0300 (-03) Date: Thu, 7 May 2020 16:44:53 -0300 From: Marcelo Ricardo Leitner To: "Gustavo A. R. Silva" Cc: Vlad Yasevich , Neil Horman , linux-sctp@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] sctp: Replace zero-length array with flexible-array Message-ID: <20200507194453.GD2470@localhost.localdomain> References: <20200507192152.GA16230@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200507192152.GA16230@embeddedor> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 07, 2020 at 02:21:52PM -0500, 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] > > sizeof(flexible-array-member) triggers a warning because flexible array > members have incomplete type[1]. There are some instances of code in > which the sizeof operator is being incorrectly/erroneously applied to > zero-length arrays and the result is zero. Such instances may be hiding > some bugs. So, this work (flexible-array member conversions) will also > help to get completely rid of those sorts of issues. > > 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 Acked-by: Marcelo Ricardo Leitner