Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp129189ybb; Thu, 19 Mar 2020 12:57:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsROTBsv3WMB1COwzfn2G6O/gkAlx8krA6unf06vWXP6tgLpnceJyUOe4rnfMSVcrcrSK0P X-Received: by 2002:a9d:340b:: with SMTP id v11mr3846875otb.14.1584647845127; Thu, 19 Mar 2020 12:57:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584647845; cv=none; d=google.com; s=arc-20160816; b=tLe3/s9ouNbG4+LhlUbCXEYLIzTZkWtaCWoep7FGAnA/n2Cik52HJd1nbv9AxgoSTC G/IyIKIe8lUG9A7886/uJlXwDKItIdvg036YpEESthCQOzM4ESF6wmfw35gJHilHINI8 ZVr/Az1GOEeWMxj8YFNGEdHIsQHijyNHAv1CqPfkYKXQjIEXlGvOoyYzuXxdQfQVWJoN QPbpuy8nIP6hNU4JjcDMyMgtBEnSI7Z/AxE/JWwuQhid+hbd7fwQpl+EeI1IXlXhN/D/ 9MphZNG9zVdns7yL98Mi208AnDOuHcOJJjBccPm8Jw/B5oYFJYVYceO+o2wnTsV0WUcR iRRQ== 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=DLBNTBHIjEyXTiw55gKa/omvhkGIw8WPWOA9rE0GXXs=; b=duFgE4LWqQl1Ihz51Yj9ojglp6fg7LxAGCL/C9on22vp8QJPyuHUt+o56I2rrcS1Se fdXCBJOE8XQcI1I89iF6JD1HqahnGNANDo5DHB4mCHwZLAldY1PtcYBtNG5NpjbPnkQg APWxFcUE6xKq8iTd2ME8jCgvdDbg9Ilm73z6TeYHSs2sew5lkXcUcdSEJCp/iMMxMFT+ jorj/6IeZ1Sr0oLoKK7A5GvoGwFz0b1zS5Gusl2fxkTfiDZE39T/5BzHsUUzYU+yqFUw Mz/G9CwPx3C7rNK/5JYEmOl1y09pKOPL1L31zfspWXYkBTJwRK8YG1Q4EXoBUWlLMKPA XGcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n2qP4Xqt; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x26si1617649otq.220.2020.03.19.12.57.12; Thu, 19 Mar 2020 12:57:25 -0700 (PDT) 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=@linaro.org header.s=google header.b=n2qP4Xqt; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726974AbgCST4X (ORCPT + 99 others); Thu, 19 Mar 2020 15:56:23 -0400 Received: from mail-vk1-f196.google.com ([209.85.221.196]:43565 "EHLO mail-vk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725817AbgCST4X (ORCPT ); Thu, 19 Mar 2020 15:56:23 -0400 Received: by mail-vk1-f196.google.com with SMTP id t3so1093500vkm.10 for ; Thu, 19 Mar 2020 12:56:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DLBNTBHIjEyXTiw55gKa/omvhkGIw8WPWOA9rE0GXXs=; b=n2qP4XqtmbRkwTffuQFwXJ8Kyni1t5QKf1wQ8bKFluTixABW8LclzLmeroCG6blV/l awphaC3e1tqOhhxG8oIRoFCgEHirN44udIlHn+jv7e/H0fLrNxw2T9El9mTkJTlcv2RH kaN8TRp+3RuLDIfeopbdNQOj1rMzW0u0soesEQnHj/Q2gMVVlWsC6l51kX3+W5spG3/M tSNiUojk//lSCskPzJvYQXr6JAidCMkL64aYox05L2ttTMQf7wFZIVJiuVZHwgdFPkWJ 5sFDbFx/h68TUjJujkzCTnqXHGiDDOZe0V5D/GioJ4LrIYoyAsPTvsoQLMLVns2QxzHQ /L5g== 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=DLBNTBHIjEyXTiw55gKa/omvhkGIw8WPWOA9rE0GXXs=; b=heIY5qyL5aALSCFepoKyTQ4wv7itaPPTK6+Ji2U8/kK5w/qw+KKwTHhq8EOC1FqQrw Ddc4O5GKYVJUQ7XP/2XEdfIkookcBIOZf9EqtnykM2KJNKbARBDhxXkBbZABXWV+nHw1 0ajjRaSVGv+fuzPJKRdi1D1tCUq/ibPQvBu+TMqzY3CK1A7UY9seMUj/MQXR2l2RXysA zxqeM61mjTni+b8RZqHkDQ1hTDlsvN8LdKuYuK1fUS27ZrOkYYj5tB1f4bJHQKK/J2Cy JcpRvJH7rbJDy9VC2dDHcWWraZlyJBPgTRPxYilQghfsztNQU2U5LMTlDwI00Vq3MpKd 9UQQ== X-Gm-Message-State: ANhLgQ2yOGj3J5iBwi8pGd0SWe/PVFdZBFDkeLVWXm8C4fV9aWzSY6Lt 5RiQncfbu/pK15YY2E1Gyl25wK+qK8sbtBJFLryY/b2L X-Received: by 2002:a1f:e004:: with SMTP id x4mr3982623vkg.79.1584647781469; Thu, 19 Mar 2020 12:56:21 -0700 (PDT) MIME-Version: 1.0 References: <20200319184838.GA25767@embeddedor.com> In-Reply-To: <20200319184838.GA25767@embeddedor.com> From: Amit Kucheria Date: Fri, 20 Mar 2020 01:26:10 +0530 Message-ID: Subject: Re: [PATCH] thermal: qcom: tsens.h: Replace zero-length array with flexible-array member To: "Gustavo A. R. Silva" Cc: Andy Gross , Bjorn Andersson , Zhang Rui , Daniel Lezcano , linux-arm-msm , Linux PM list , 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 On Fri, Mar 20, 2020 at 12:18 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 Reviewed-by: Amit Kucheria > --- > drivers/thermal/qcom/tsens.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h > index e24a865fbc34..92503712596a 100644 > --- a/drivers/thermal/qcom/tsens.h > +++ b/drivers/thermal/qcom/tsens.h > @@ -488,7 +488,7 @@ struct tsens_priv { > struct dentry *debug_root; > struct dentry *debug; > > - struct tsens_sensor sensor[0]; > + struct tsens_sensor sensor[]; > }; > > char *qfprom_read(struct device *dev, const char *cname); > -- > 2.23.0 >