Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2391523pxb; Mon, 20 Sep 2021 21:09:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTBeOiuXOf96bpOkfkkAuKTOBbgj2vSLPdh6xV39L14nsdB3FRhtMBUZ5TY3A0RGz0PXh2 X-Received: by 2002:a50:d88d:: with SMTP id p13mr13745185edj.142.1632197356333; Mon, 20 Sep 2021 21:09:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632197356; cv=none; d=google.com; s=arc-20160816; b=t/OKi8szFeVsSUEmdi1SZrfs+oujgxSoMiel52LZJ3Jx+oB1uRAkTIKrqLW4KSHfMu gKGaEfNB0qRIsDCN4wwciFDKyA5u3zrNr9C0ykTWpTTbD8ADTBDXEYVjeWu586pvYB2z v05Lg1yRWFjvwTzfnlxDmXqPf50RnCmiKgWrc5/r/yoibYu9zPeD2uoi3rBbj3va6EAm SfY2pPd7ytLql8bbiefogY438e1ySHvFbnRh/j7HeUz729/PKJiFNmvTN0q4gu4WwY9b nj0PVDaRMYPOtzkiVvdlYgU8Nr8Voqrn/G5C9R6delYzNebkkeKBQgkFC46bQPpk175l qbNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=IC0pg/XX+TI+s5bIXMNwch4sO7j1nEoBLODd5HuH4zo=; b=P4coKpbJG7zFVnsv25BUyy/0f6WcYmQFcV8ej9SgcCau4d5zhj8S+xo9IZ2ypAkX32 GocqdV1yF0/c/lj4upw9wX2uds/gQk4oc+HTpGx2n2dnAsKkre+kZgHd775uLhzLIx1n mFyQJi9ItqNKQOvj6w4XddD0McbYNb8HCXbqBjae5F5KOykzyjvqOuGcokhdLS53AoYs GaPtKAUkT0RLg2sKWbd2eiiqSqealAWZbW5aJvkyeq0IjxOvg7asJaHV+Ne5SmWca/YF DkQghQOk3y9+MCcVk67Q/bgK+7MGFsbz88BFb+bCAXX1aRf7GjkYYG0nkGLGSJV6Cs9D Z0bQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hx18si19448572ejc.60.2021.09.20.21.08.53; Mon, 20 Sep 2021 21:09:16 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231433AbhIUC4U (ORCPT + 99 others); Mon, 20 Sep 2021 22:56:20 -0400 Received: from mail-lf1-f45.google.com ([209.85.167.45]:38566 "EHLO mail-lf1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352791AbhIUCzD (ORCPT ); Mon, 20 Sep 2021 22:55:03 -0400 Received: by mail-lf1-f45.google.com with SMTP id x27so75642318lfu.5; Mon, 20 Sep 2021 19:53:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IC0pg/XX+TI+s5bIXMNwch4sO7j1nEoBLODd5HuH4zo=; b=nA84a7kTHr4gQHJosCqtcn8rA1p1+oJf9gjAblY1sajKurT8QteAyV8qutsAvhQrg+ Sao5l79ccRXA44NvSb4E7qu2zsci+QJyhu7OHc0G+2YoX5R8nVb/5+fXi95w1y75gjjR pLxWBKO8UeOmEpIyDMJgpUUsdrtDY85K+hryRwI44WqVFyS5084SYQBhImmwG58W8YNc 3X7EVfJSFn32LVmmsAIyywY6xtNnjQABDHDFuEv5BqUXa9C0Mx8Sibb4xC2M3nIyhvjG Zxa/H4tGKNrngBbzWQj1HWjty5ivO+81OmHVv/j3SKSGwLVI5Im7SpEMtfLF6UGhMOC+ W5nw== X-Gm-Message-State: AOAM531WFM4ps+OGUdmKG/z5T9XzNX3zNj0YdxINR4NFqtzacb24jHIm 5gxkx7IpzoNJcZSYNSopgPFp7KkY0Shj7zmrrGY= X-Received: by 2002:a2e:a782:: with SMTP id c2mr25735230ljf.388.1632192814113; Mon, 20 Sep 2021 19:53:34 -0700 (PDT) MIME-Version: 1.0 References: <20210920123045.795228-1-arnd@kernel.org> In-Reply-To: <20210920123045.795228-1-arnd@kernel.org> From: Vincent MAILHOL Date: Tue, 21 Sep 2021 11:53:22 +0900 Message-ID: Subject: Re: [PATCH] can: etas_es58x: avoid -Wzero-length-bounds warning To: Arnd Bergmann Cc: Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Jakub Kicinski , Arnd Bergmann , Arunachalam Santhanam , linux-can , netdev , open list , Kees Cook Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Arnd, +CC: Kees Cook On Mon. 20 Sep 2021 at 21:30, Arnd Bergmann wrote: > From: Arnd Bergmann > > gcc complains when writing into a zero-length array: > > drivers/net/can/usb/etas_es58x/es581_4.c: In function 'es581_4_tx_can_msg': > drivers/net/can/usb/etas_es58x/es581_4.c:374:42: warning: array subscript 65535 is outside the bounds of an interior zero-length array 'u8[0]' {aka 'unsigned char[]'} [-Wzero-length-bounds] > 374 | tx_can_msg = (typeof(tx_can_msg))&es581_4_urb_cmd->raw_msg[msg_len]; > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In file included from drivers/net/can/usb/etas_es58x/es58x_core.h:21, > from drivers/net/can/usb/etas_es58x/es581_4.c:15: > drivers/net/can/usb/etas_es58x/es581_4.h:195:20: note: while referencing 'raw_msg' > 195 | u8 raw_msg[0]; > | ^~~~~~~ > CC [M] drivers/net/can/usb/etas_es58x/es58x_fd.o > drivers/net/can/usb/etas_es58x/es58x_fd.c: In function 'es58x_fd_tx_can_msg': > drivers/net/can/usb/etas_es58x/es58x_fd.c:360:42: warning: array subscript 65535 is outside the bounds of an interior zero-length array 'u8[0]' {aka 'unsigned char[]'} [-Wzero-length-bounds] > 360 | tx_can_msg = (typeof(tx_can_msg))&es58x_fd_urb_cmd->raw_msg[msg_len]; > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In file included from drivers/net/can/usb/etas_es58x/es58x_core.h:22, > from drivers/net/can/usb/etas_es58x/es58x_fd.c:17: > drivers/net/can/usb/etas_es58x/es58x_fd.h:222:20: note: while referencing 'raw_msg' > 222 | u8 raw_msg[0]; > | ^~~~~~~ > > The solution is usually to use a flexible-array member the struct, but > we can't directly have that inside of a union, nor can it be the only > member of a struct, so add a dummy struct with another zero-length > member to get the intended behavior. > > If someone has a better workaround, let me know and I can send a new > patch, as this version is rather ugly. Actually, there is one. Kees Cook introduced a new macro, DECLARE_FLEX_ARRAY(), to do this in a more elegant way: https://lkml.org/lkml/2021/8/27/524 The same series also fixes the warning in the etas_es58x driver: https://lkml.org/lkml/2021/8/27/523 So we only need to wait for Kees's series to get merged :) Yours sincerely, Vincent Mailhol