Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4952750ybv; Wed, 26 Feb 2020 05:57:07 -0800 (PST) X-Google-Smtp-Source: APXvYqyRcdksAGwbim+Df1kxS2P59TTMK3x/Hp3kaL20GC5e4PklZZyTkbMbQQcyZsCHvCGuzOAv X-Received: by 2002:aca:484a:: with SMTP id v71mr3210665oia.39.1582725427604; Wed, 26 Feb 2020 05:57:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582725427; cv=none; d=google.com; s=arc-20160816; b=iqIAzXoPNsEZGw+rNME5j8GYWbKQiJ78Ha8dDcnJPhDLEfhJEO8m/u9jmH3JkIbPKL Hj94ZdyIOLyXxFQ1BourP1XKqvgYiWLYtpXSG/fPl3sIEe1g81/w9hC7W9nn5G3ZlKj/ d5ElFnV4AqnB3npF6J27iQirSQd+jOYd9/yFmpraowrui8Y7BWlvA7cerfoRS+iNdhhj iqeOFJOvVFowTC93z6N8pHzQuakQR18i27FT01U44g89UhCJsRQ6qqqoeJee6/1Kau+o FZKxd7olKSex6AgwXUnX/KRvzhBTj1WSUwTgp0mg/1sRPC0WnCp5WmjupdlckaedR44Q jC4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=QGW8A6NvrrWP1yUYNzkuM9Y6DPoFVb9Z8KwBG+QV5Lo=; b=g/XpIDm0jLEXzcdA4xBpyosuj/Z11QabkvTlNQ3Dw5aJKLKCQ5R9UrnO/0tZkycQgd YLzZrMLrWMHmo/p0SsnXuaXSeNv/yAPLe+/+1XK1hQ7UA7i06JPM3dY9AkVnAQGmMA87 l6CiDGxj3sCk143aZTMgYv8XXlNP+YbINNatUyNhrMlGiHtkFxL6WE6wabYlsjTvlY3v kbnvVJVooUfKFnw8bjr7jCp1S6PtlYiaMPfmqRA92tYqXt9oxzp/+VVekj77b1+v5qx1 sm7o9fbVS65PKNk4zJtG9iYdaO6yOaoXGzMaXGAMkg4xPGxk0kgsWi+JkPJLZHHsLuL+ faFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Vk6w/5mZ"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q65si1200471oic.123.2020.02.26.05.56.55; Wed, 26 Feb 2020 05:57:07 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Vk6w/5mZ"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727440AbgBZN4n (ORCPT + 99 others); Wed, 26 Feb 2020 08:56:43 -0500 Received: from mail-io1-f68.google.com ([209.85.166.68]:45506 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726359AbgBZN4n (ORCPT ); Wed, 26 Feb 2020 08:56:43 -0500 Received: by mail-io1-f68.google.com with SMTP id w9so3374067iob.12; Wed, 26 Feb 2020 05:56:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QGW8A6NvrrWP1yUYNzkuM9Y6DPoFVb9Z8KwBG+QV5Lo=; b=Vk6w/5mZAyodQkBHzCqY//wn5JgAJqdcOqxWE9FGbVPOxKDaMY3/jEssR4cW31l0kZ xnSN3PAOStFfPDzSdOz52NHgqlKbdpw6BQpfgi6JeNU6q+vZzJ9Tkr3nMUTOnPY+/1dR SDqZyhx4MtnDSJCwCK4wjBlwI3mj9X5Irm0grREPAE/kYvgtr7NQS4zRSu/B3vUB+wmc L4AIsB6ZODPjVNKF22GGbz7urvzlxneuNfVLJ3Fwy1LZq7kBc5la7CvkLe15B77Zp6OV Y3oi37jhW7MaO1mVwTS3F7Qk3yPKqwfhnYExvZ33NuK5eMZN/W8k8E6K/iSRrtjJOrOG 2qpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QGW8A6NvrrWP1yUYNzkuM9Y6DPoFVb9Z8KwBG+QV5Lo=; b=ogkcCq+dfz8zw160hdav5kQ6Ksgnn7oW7xiBpgYgWchm2gmTNBsFSPTUv/yXHvN4Zx MDt6XnZSc2Aa4bGFH7911NQjjiB4nDiuFjO6CErrFitc88nBFx2fnmZRmIvBPJaJpm6j ECmdCD0+Qd+Hpea9KaDw5hTYYVfjT4A/+gcs6MaHLtVGo1OEJMKRfUCsJdS6Rr44pzf2 D7hG448xuEKll4nNO7cu2cmjS4RUT91+hHfHTvOVd5g24LvoW57VBdzCdJXzGn77GYNj 1mF9Cm/u+WyEy8rc3PsAuRVr44LU1x6Wg6hi5KXEJQ0/H0IgEX61RJdnGjb1zmJj113W tIww== X-Gm-Message-State: APjAAAXQGfkPkCLsaOVhnb5QbQqWm8Q65tCNqFULKEsIpa6Rfm3HRNBy 5eHlE362AmgFvP0wvDn708XW08BG0kvIjrDA1Ck= X-Received: by 2002:a5d:9707:: with SMTP id h7mr4749293iol.112.1582725402510; Wed, 26 Feb 2020 05:56:42 -0800 (PST) MIME-Version: 1.0 References: <20200225234836.GA31741@embeddedor> In-Reply-To: <20200225234836.GA31741@embeddedor> From: Ilya Dryomov Date: Wed, 26 Feb 2020 14:56:34 +0100 Message-ID: Subject: Re: [PATCH][next] block: Replace zero-length array with flexible-array member To: "Gustavo A. R. Silva" Cc: "Richard Russon (FlatCap)" , Jens Axboe , Philipp Reisner , Lars Ellenberg , Sage Weil , Dongsheng Yang , linux-ntfs-dev@lists.sourceforge.net, linux-block , LKML , Lars Ellenberg , Ceph Development Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 26, 2020 at 12:45 AM 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 > --- > block/partitions/ldm.h | 2 +- > drivers/block/drbd/drbd_int.h | 2 +- > drivers/block/drbd/drbd_protocol.h | 8 ++++---- For rbd > drivers/block/rbd_types.h | 2 +- Acked-by: Ilya Dryomov Thanks, Ilya