Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4261219ybv; Sun, 16 Feb 2020 17:58:04 -0800 (PST) X-Google-Smtp-Source: APXvYqxgfzk62Qj/vOHFhrjIykcmML+W3g4RCKm4pz+NwmK/4XR/T0hF4E8ZVwcQ7GVsqUPKUaEj X-Received: by 2002:a9d:7842:: with SMTP id c2mr9797046otm.252.1581904684494; Sun, 16 Feb 2020 17:58:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581904684; cv=none; d=google.com; s=arc-20160816; b=aDEJnF4tQRQMhiFlwa1eGj6Qz4Ag/pTQ2OE5He/HC2oBHzR9F5kQ8tM6hXEdRfqWrO vXlqv+7PqqZ3u8ieGd1TWgFRqE61hRwU+pB8d5cFhdnGJijEGhohRudZ73jc+2LojBKI zHky4FBhdlCoiNJu6qEoJGh4pfGYp+/J71zMLXfKh1i7QlifqOLy2BIkEI4VUJn4VEZj V3rPWlbxToOXpOlDJBOTjwJhqpXaKpVo8sffWRL4Xy7Yi/qHowNfGoK8Wk83uiIW0omu fdK47kGWj938UoHS0ZvHENux3yuPHMhxLhYQnn6e6UKk4YuWF7to8Vf0o4H7zG8yK+u+ 6R/w== 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=/qDOmCXFTgruSYsln27jvW69b87aN/svbpuiBXSYyss=; b=CamJuCH0tpPFtSNZAmecSkE8JFF6nOxd+8J7scp7s0dccMwlG3ZZ8GRkQJmENkm0QX xdmxVaCTsqWwPp/N+ea1EC2ncJYD82eqIG5aKgPPsS4qFVIYnsD4pmdmb5ksJwwnHw/P bJuO3mU+I+YIz9WscQoOM5iHke4vJs1mix26MGCUgmbainUQEANKmFDnT2SIMNJdIvEl 0gCgYB8oRbohJTg3L4DYWvz+3K0h0jKOyLyuPk0bnwe3SI1YDdUb4XvBTARx7ikug3fC FKtoHwVhTUOE1/QPB2/SkG4YMa2xCLiMvR/6+4Z3XZJr0LB5XBzwlHrgMtn5jEPRVKoO hRaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fGMnmElS; 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 l4si6024689oib.170.2020.02.16.17.57.52; Sun, 16 Feb 2020 17:58:04 -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=fGMnmElS; 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 S1726754AbgBQBza (ORCPT + 99 others); Sun, 16 Feb 2020 20:55:30 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:34605 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726551AbgBQBza (ORCPT ); Sun, 16 Feb 2020 20:55:30 -0500 Received: by mail-qt1-f195.google.com with SMTP id l16so6388772qtq.1; Sun, 16 Feb 2020 17:55:29 -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=/qDOmCXFTgruSYsln27jvW69b87aN/svbpuiBXSYyss=; b=fGMnmElS8wotL0yxqURfAcjh9g48StpNQichZx9J6ytEfLAWg+yn2Ps/V9HpduoOPM fEY7USeLncQDj4SAvHyhCrHSxuqHPM3qBHpZ2VHXYdPqPJDgsQp+NBHSJw9PsVfWzeUI JkHl4xnILKYj3qKt0Br6v2WHKlFWrtGrxxuC6ZfwhfPJB2N1RUPY82uCGjoAr6OAVsO7 SGOaE02pKi57j7Rv9/FDX2vCg5pLFYYMi/4jGDiwHZywLZf3rbzUPmrs3T+wI87XNK12 RF41cHCDGjB60WxIsWPbcRrWnETTIoM5cU0fxM/JriptNyujA6NsjUOmF/kIB6A5T2R4 3OAw== 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=/qDOmCXFTgruSYsln27jvW69b87aN/svbpuiBXSYyss=; b=kavsNIzLC8IwyPRyH8azIAuZpcr9mUbgFXv2Yw6jyU6zi/Pryz0f/JOeS7Tbd87dWM wffPETGDVKygkbOcTc1IhmYdYH+CsasEUm1Mt6DTLwdRuKpgAsHiHdZpY6bMDothyfYm /J5q02Tx4qJ3fQkjgOLPnplJyVIq1ZqU2j6GhKD8tyO1ifRQuZ9z/L74j+EbAb/XSNCx u0pV68Tvs/eyUR4dPwWChBQJtbvnFJcmy92dIjtcQgiY28p2wdizSiGQnQpXRVXBObG6 l/YBrQB2FGfZdgc2OcAYTiFKVIlDL81VhT5It0v8q43gLmk2RQK4qIsOvqSPEwkJ+6s+ QBRw== X-Gm-Message-State: APjAAAV+pid8DDfrWIMmjLVxqwa01Jn77u2vblq1MlvUZBY/xi1obGnX Yp/rCoTbzOu/q27ev35vbcaoUONqnTKun0YR5qrwKn4+ X-Received: by 2002:aed:2202:: with SMTP id n2mr11926482qtc.4.1581904529345; Sun, 16 Feb 2020 17:55:29 -0800 (PST) MIME-Version: 1.0 References: <20200214171536.GA24077@embeddedor> In-Reply-To: <20200214171536.GA24077@embeddedor> From: Baolin Wang Date: Mon, 17 Feb 2020 09:55:17 +0800 Message-ID: Subject: Re: [PATCH] dmaengine: sprd: Replace zero-length array with flexible-array member To: "Gustavo A. R. Silva" Cc: Vinod Koul , Dan Williams , Orson Zhai , Chunyan Zhang , dmaengine@vger.kernel.org, LKML 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 Hi, On Sat, Feb 15, 2020 at 2:04 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") Looks good to me. Thanks. Reviewed-by: Baolin Wang > Signed-off-by: Gustavo A. R. Silva > --- > drivers/dma/sprd-dma.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c > index 9a31a315dbef..954eff32cc05 100644 > --- a/drivers/dma/sprd-dma.c > +++ b/drivers/dma/sprd-dma.c > @@ -212,7 +212,7 @@ struct sprd_dma_dev { > struct clk *ashb_clk; > int irq; > u32 total_chns; > - struct sprd_dma_chn channels[0]; > + struct sprd_dma_chn channels[]; > }; > > static void sprd_dma_free_desc(struct virt_dma_desc *vd); > -- > 2.25.0 >