Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp233467ybv; Wed, 12 Feb 2020 23:06:52 -0800 (PST) X-Google-Smtp-Source: APXvYqzLCjRjPQblIQ8eRbBAMUyZ5cVJs6wOsTYoFmluiDuINiSfxuw4fQdPYFb4qLaiS2LzMEjI X-Received: by 2002:a9d:53c4:: with SMTP id i4mr12925391oth.48.1581577611948; Wed, 12 Feb 2020 23:06:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581577611; cv=none; d=google.com; s=arc-20160816; b=bgObCjXfrRZFGlUb4PHKZrKD6Liyj139P3LBjRo8F0XX1fNsXrN167JV+2wjowq9yH Kc0u12F18d2Pgo5UwfeuYWYAQm68tpbtCmuzMBEj6QUbHcHUzCcp5dcyxk6+YJOyK+2o RkDvlueQLjLGLKhKMf/zPdILkY0lJLltN4pzzxS8qhzsk/RHN+Hp/ioVrIR1OnP0YYrX ylbV8/3NGlVoAm0EzumfzrgpeX3zU6JQ9K/Ao7VvrEqwe6eP+pwhG5PYdKh42l3f8s0i FBFAHOoDb5PCQ2LAIIrZt/zk1y4RXvkRboFeWPNUZyh2QUk5nu1jobv1ttnWRYvh8diF OgnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=JvGh8yuZ5yfeCuRWHM/H0X4BZ2PEVJYss8hEjyaIsbw=; b=HeLupQpIzv0SN3YPNur24ubx4ap7YOqZU0eaqRX+Ef+naO+z1IUQNgYwNUlT+T0TMU 20JkhqlPySUwNQ5MrSUH0G4ZPNlMvOaB8jvY92HnqNSTSCqgBJ5vZLLSFz/8nr1+aM9j 1QFBPgbOWYLly5cvIgYHD+E5e8vLC/3rF0Kv/O5kKbscPRj6HU42F47KnF7HnMD6EQw5 /W+bA/VTxSeWQnz1EzmDoIvk28R5VUrj6Rki3A/B+9je8GziM9WFuYIGYCUeuBbXvb+/ chORMk+VLcBbXBULB5hMO7qN1B6d36Z0v1m5uUBTmz2IS4DUCHXpNUD9O/+iY3ZUK79C dg2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=qRtxswxI; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d17si731978oij.136.2020.02.12.23.06.38; Wed, 12 Feb 2020 23:06:51 -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=@ti.com header.s=ti-com-17Q1 header.b=qRtxswxI; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729702AbgBMHGa (ORCPT + 99 others); Thu, 13 Feb 2020 02:06:30 -0500 Received: from lelv0142.ext.ti.com ([198.47.23.249]:41978 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726657AbgBMHGa (ORCPT ); Thu, 13 Feb 2020 02:06:30 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 01D76Gx6051841; Thu, 13 Feb 2020 01:06:16 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1581577576; bh=JvGh8yuZ5yfeCuRWHM/H0X4BZ2PEVJYss8hEjyaIsbw=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=qRtxswxI+TK+ZGQIMmRS5Bg9GwxRqy2NgsudI7j3Zvp5CfA1oinDf0n5QzWZSngKC S/4BqrN4Zmf9TDeneMzJdjGViV7pjWKgmZpt6q5608IxCQL2mbr9qYUaENKlOV/1ZK Lp8dZkZCi0jWcr7FDOhDRLAdj1JEFSyFCetAERMQ= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 01D76GAU127982 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 13 Feb 2020 01:06:16 -0600 Received: from DFLE108.ent.ti.com (10.64.6.29) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Thu, 13 Feb 2020 01:06:16 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Thu, 13 Feb 2020 01:06:16 -0600 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 01D76EVm128557; Thu, 13 Feb 2020 01:06:14 -0600 Subject: Re: [PATCH] dmaengine: ti: omap-dma: Replace zero-length array with flexible-array member To: "Gustavo A. R. Silva" , Vinod Koul , Dan Williams CC: , References: <20200213003925.GA6906@embeddedor.com> From: Peter Ujfalusi Message-ID: <2affea92-6748-76f1-6fe4-025fa7053a4f@ti.com> Date: Thu, 13 Feb 2020 09:06:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200213003925.GA6906@embeddedor.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/02/2020 2.39, 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") Acked-by: Peter Ujfalusi > > Signed-off-by: Gustavo A. R. Silva > --- > drivers/dma/ti/omap-dma.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/dma/ti/omap-dma.c b/drivers/dma/ti/omap-dma.c > index a014ab96e673..918301e17552 100644 > --- a/drivers/dma/ti/omap-dma.c > +++ b/drivers/dma/ti/omap-dma.c > @@ -124,7 +124,7 @@ struct omap_desc { > uint32_t csdp; /* CSDP value */ > > unsigned sglen; > - struct omap_sg sg[0]; > + struct omap_sg sg[]; > }; > > enum { > - Péter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki