From patchwork Mon Sep 20 12:30:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 514311 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp2004068jao; Mon, 20 Sep 2021 05:30:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+80MVJEfJXJlXLV2Y0AyHlwe8jmlobNRi/MsZxfqxIxwWLUDq7whoisSdSbXgkGrTaMX/ X-Received: by 2002:a17:906:4544:: with SMTP id s4mr28187768ejq.102.1632141057527; Mon, 20 Sep 2021 05:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632141057; cv=none; d=google.com; s=arc-20160816; b=g/X0WZ338tpqZ7zzcEv7Nhn1CtJInBtEa+WAniE5//ILZAuDxfyr+OP2Bk8cxYV5g/ E8RT1iKQ2ggDLgthCVvH6+Tf/hvLVYQprH6UDuIdbece16HfrZACb9VjDqHtfOVJAdWB qg2yVzk839PRFMNRJjTuLsN2/K3+43p/QPx2zSrf0wfdbOk88IOl8FpGqEiGLuqMQjF1 oPnyHhJJVgu+9S7sxM1IEKHLel0rmrLRpoWs7cLqyegL88CJKFb6HJHUBd2GuRbc3/bH 7KTsMRMOf1F0I6ZvD7itNCAiFd7wvGdUgKeqd4tW1v1SA+cd5oaWYBNgOkqt+s6agIe4 zHvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=7laWJwKw0ZbrvQOK0q9nYuRU1f2pbZzA51JuzXtYVB4=; b=iUEvqzNBNuX6sVtETfqRTNdpgyjTlcgg6cdafaDqshC+5NEcCj8NKiFYJGIFM+7OwM mpniteCKwD82f51+CTXsW96hvhf0TG1RoESG3WlrNs0Fqpip7p6mw6kgeIFgNW27Cw4a GsulAj8eKtQ6HtJB9ZW0uIYV0LR2d6QTRESbbc5FOgvXgqR/j0f1njNI8tiFay59mTDk NgIhNsS/1mCulPdp3tuXjRPJ1nZUuNDyXNxBPDoDihTvnp0N/cIkJi8TmVZO9QYUDJKZ joiOJJHXfadP78NNOHQoD65eXATs2VwHDxeoxTHBenRBxDhql9Q4n6UB1qz2jMNNOKZS O5Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=umVoqvb4; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o1si11403285ejy.319.2021.09.20.05.30.57; Mon, 20 Sep 2021 05:30:57 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=umVoqvb4; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238247AbhITMcV (ORCPT + 8 others); Mon, 20 Sep 2021 08:32:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:54968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238306AbhITMcQ (ORCPT ); Mon, 20 Sep 2021 08:32:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7FA0760F58; Mon, 20 Sep 2021 12:30:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632141049; bh=fiiOgJh7EqR6CDg1SraGUGYNQfeg02MhMllonKVAqBY=; h=From:To:Cc:Subject:Date:From; b=umVoqvb4jL6F3VLNlC6Vd7QpKwQd0cY6wW5Y7UMHVx0D9oazhIJMcFdxa/B3IB3IH mGvZHcjHbVg2UxtTiFvu6/uaDpsJjTL7gt+NxLBzuQY3QdvMiVOSRCU9WE1qo3j9iv D5n+F6c5rtaRmznaqW4q1A+srU65Ryf1O+DDTbmbkqEhe+q8evejrZUj/fYXc94gbI hIMpv/ptgwfw+V7QmSUFrcZj44lGnwFygzY1cwa7zCFkkaY58ep410F3A7AMwOHvkw BASk+iKcQX8/EZCiMIE720UrcMjls101kA+XNvHlED3nFI8flpj4R7tLRS+6wyOLwh KgVHAVGFa0VjQ== From: Arnd Bergmann To: Vincent Mailhol , Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Jakub Kicinski Cc: Arnd Bergmann , Arunachalam Santhanam , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] can: etas_es58x: avoid -Wzero-length-bounds warning Date: Mon, 20 Sep 2021 14:30:29 +0200 Message-Id: <20210920123045.795228-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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. Fixes: f4f5247daa45 ("can: etas_es58x: rewrite the message cast in es58{1,_fd}_tx_can_msg to increase readability") Signed-off-by: Arnd Bergmann --- drivers/net/can/usb/etas_es58x/es581_4.h | 5 ++++- drivers/net/can/usb/etas_es58x/es58x_fd.h | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) -- 2.29.2 diff --git a/drivers/net/can/usb/etas_es58x/es581_4.h b/drivers/net/can/usb/etas_es58x/es581_4.h index 4bc60a6df697..ac5ef88db565 100644 --- a/drivers/net/can/usb/etas_es58x/es581_4.h +++ b/drivers/net/can/usb/etas_es58x/es581_4.h @@ -192,7 +192,10 @@ struct es581_4_urb_cmd { struct es581_4_rx_cmd_ret rx_cmd_ret; __le64 timestamp; u8 rx_cmd_ret_u8; - u8 raw_msg[0]; + struct { + u8 __pad[0]; + u8 raw_msg[]; + }; } __packed; __le16 reserved_for_crc16_do_not_use; diff --git a/drivers/net/can/usb/etas_es58x/es58x_fd.h b/drivers/net/can/usb/etas_es58x/es58x_fd.h index a191891b8777..253e7bafd0b6 100644 --- a/drivers/net/can/usb/etas_es58x/es58x_fd.h +++ b/drivers/net/can/usb/etas_es58x/es58x_fd.h @@ -219,7 +219,10 @@ struct es58x_fd_urb_cmd { struct es58x_fd_tx_ack_msg tx_ack_msg; __le64 timestamp; __le32 rx_cmd_ret_le32; - u8 raw_msg[0]; + struct { + u8 __pad[0]; + u8 raw_msg[]; + }; } __packed; __le16 reserved_for_crc16_do_not_use;