Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2630726ybv; Mon, 24 Feb 2020 08:41:06 -0800 (PST) X-Google-Smtp-Source: APXvYqw++sgK1FR4xMtedP/3Ni254G6tLy4uCn071/bOojemssNRG2wpbLL2FcgrjsfbXDZpERJQ X-Received: by 2002:a05:6830:1d91:: with SMTP id y17mr39033164oti.276.1582562466802; Mon, 24 Feb 2020 08:41:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582562466; cv=none; d=google.com; s=arc-20160816; b=ZbJnrNjkronqU0rOxX7UxZxwpFlr/FP86eIa/WtNUU0IqjtoH5JSRpTjIfIBZDjnzQ CEfOCx9f19WZZbn6klrCpWvpprhaQPgd49H7q67hcWHui/0CsOh+upDQM5yrEN4E57v6 Tlua3rCrGSfrsMMwpYeY2zUQ+VMCj/tAfhgsBb1hPVozZ3/LRirnEW7F10lM4f9mfP9L fp/d5FvwUv9kdPJ9dInTCrwQJZGrsxxrrKAJhd5dVbYIRAOSCPntflX77K8ls+xN7MIw inNfG47ZEzbRUMEQVGCgX04jPDXRUdH8prwGfY2kZ3gZNH0PWie/NDDUzol22NdyI/sZ 46Pw== 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:autocrypt:from:references:cc:to:subject:dkim-signature; bh=9MaTLdhyE2lqQeKKEie4NEqJq9AQ+rH9XoGJxwhMLV0=; b=jek7PrsjN4ZsU8bAQO2igkp0VoI4ckDuLYJfiGQfEnNDDzoCxAwQNlu967lWVwKScK JDrf5TlyyZIr7WGOEyTYqUG7Sk9latkkVWURv/PHAINQZqJlQ7Z/PXwZlAv+jr4t9yN7 r2qE9qTh6XWxgh/rutgzITb171GkPyB+Jyl0Y8zX94FF7MQ3CpBDnO3eXWa34OKPhiJp ifQpUcYHjIUpY5JIUfDEgkxplI98Y2M6gJ6m4G9dVOhSYKuAheTVwyB6Qn22N5TlB+5e YBJIGa9VbcePTfY1PE41CaO0tKpABJwQEk/eOfx0X92a8gMQf5ix3x34uQ5sLurYHgX4 Nohg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=FdNeV6gs; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j74si7491371otj.246.2020.02.24.08.40.53; Mon, 24 Feb 2020 08:41:06 -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=fail header.i=@embeddedor.com header.s=default header.b=FdNeV6gs; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727862AbgBXQje (ORCPT + 99 others); Mon, 24 Feb 2020 11:39:34 -0500 Received: from gateway22.websitewelcome.com ([192.185.46.225]:26434 "EHLO gateway22.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727486AbgBXQje (ORCPT ); Mon, 24 Feb 2020 11:39:34 -0500 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway22.websitewelcome.com (Postfix) with ESMTP id D5BBBA6B5 for ; Mon, 24 Feb 2020 10:39:32 -0600 (CST) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 6GlYjdrwBAGTX6GlYjnb3W; Mon, 24 Feb 2020 10:39:32 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=9MaTLdhyE2lqQeKKEie4NEqJq9AQ+rH9XoGJxwhMLV0=; b=FdNeV6gsZdQPOoKmEq9XL5aIW1 57t9bacLPIHttu4CgT/3YNYmaHVDKnCZiWFdysBXPGLxBx2atz87M/rLEp0IV+eaYD4Hb/OUI6tSX Kxb0KZ+MPk4TAgJ2J65jtD8qUIm07AUvmo1CwIRioDG06xmIP9X2b2FSGV5HBNPlUXkDuCVxvzPC7 rmO58X2jgu2tQ6wv3nEkaNYoYyoc17SUjds1cqP/wwL5Y9fyfG3dFZdPzT1K3GK7Nefa827fPuECs 1xHqJdhvtqC2eKSNUvVzbNCT1cmo98sl5q268Z3G1Apg1+cjXAUCDDlC6OsBW9JrPi/gEwaFxdTC/ RZ2nZkmA==; Received: from [200.68.140.135] (port=33450 helo=[192.168.43.131]) by gator4166.hostgator.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1j6GlY-002tup-0H; Mon, 24 Feb 2020 10:39:32 -0600 Subject: Re: [PATCH] scsi: Replace zero-length array with flexible-array member To: Lee Duncan , Satish Kharat , Sesidhar Baddela , Karan Tilak Kumar , "James E.J. Bottomley" , "Martin K. Petersen" , Brian King , Intel SCU Linux support , Artur Paszkiewicz , Sathya Prakash , Chaitra P B , Suganath Prabu Subramani , Chris Leech , Bart Van Assche Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, MPT-FusionLinux.pdl@broadcom.com, open-iscsi@googlegroups.com, linux-rdma@vger.kernel.org References: <20200224161406.GA21454@embeddedor> From: "Gustavo A. R. Silva" Autocrypt: addr=gustavo@embeddedor.com; keydata= xsFNBFssHAwBEADIy3Z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Mb+InrHPP16aVDTBTPEGwgxXI38f7SUEn+NpbizWdLNz2hc907DvoPm6HEGCanpcA EQEAAcLBZQQYAQgADwUCWywcDAIbDAUJCWYBgAAKCRBHBbTLRwbbMdsZEACUjmsJx2CAY+QS UMebQRFjKavwXB/xE7fTt2ahuhHT8qQ/lWuRQedg4baInw9nhoPE+VenOzhGeGlsJ0Ys52sd XvUjUocKgUQq6ekOHbcw919nO5L9J2ejMf/VC/quN3r3xijgRtmuuwZjmmi8ct24TpGeoBK4 WrZGh/1hAYw4ieARvKvgjXRstcEqM5thUNkOOIheud/VpY+48QcccPKbngy//zNJWKbRbeVn imua0OpqRXhCrEVm/xomeOvl1WK1BVO7z8DjSdEBGzbV76sPDJb/fw+y+VWrkEiddD/9CSfg fBNOb1p1jVnT2mFgGneIWbU0zdDGhleI9UoQTr0e0b/7TU+Jo6TqwosP9nbk5hXw6uR5k5PF 8ieyHVq3qatJ9K1jPkBr8YWtI5uNwJJjTKIA1jHlj8McROroxMdI6qZ/wZ1ImuylpJuJwCDC ORYf5kW61fcrHEDlIvGc371OOvw6ejF8ksX5+L2zwh43l/pKkSVGFpxtMV6d6J3eqwTafL86 YJWH93PN+ZUh6i6Rd2U/i8jH5WvzR57UeWxE4P8bQc0hNGrUsHQH6bpHV2lbuhDdqo+cM9eh GZEO3+gCDFmKrjspZjkJbB5Gadzvts5fcWGOXEvuT8uQSvl+vEL0g6vczsyPBtqoBLa9SNrS VtSixD1uOgytAP7RWS474w== Message-ID: <026b4947-e38b-6d23-d330-414aebb19735@embeddedor.com> Date: Mon, 24 Feb 2020 10:42:16 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 200.68.140.135 X-Source-L: No X-Exim-ID: 1j6GlY-002tup-0H X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.43.131]) [200.68.140.135]:33450 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 82 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/24/20 10:30, Lee Duncan wrote: > On 2/24/20 8:14 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 >> --- >> ... >> diff --git a/include/scsi/iscsi_if.h b/include/scsi/iscsi_if.h >> index 92b11c7e0b4f..b0e240b10bf9 100644 >> --- a/include/scsi/iscsi_if.h >> +++ b/include/scsi/iscsi_if.h >> @@ -311,7 +311,7 @@ enum iscsi_param_type { >> struct iscsi_param_info { >> uint32_t len; /* Actual length of the param value */ >> uint16_t param; /* iscsi param */ >> - uint8_t value[0]; /* length sized value follows */ >> + uint8_t value[]; /* length sized value follows */ >> } __packed; >> >> struct iscsi_iface_param_info { >> @@ -320,7 +320,7 @@ struct iscsi_iface_param_info { >> uint16_t param; /* iscsi param value */ >> uint8_t iface_type; /* IPv4 or IPv6 */ >> uint8_t param_type; /* iscsi_param_type */ >> - uint8_t value[0]; /* length sized value follows */ >> + uint8_t value[]; /* length sized value follows */ >> } __packed; >> >> /* >> @@ -697,7 +697,7 @@ enum iscsi_flashnode_param { >> struct iscsi_flashnode_param_info { >> uint32_t len; /* Actual length of the param */ >> uint16_t param; /* iscsi param value */ >> - uint8_t value[0]; /* length sized value follows */ >> + uint8_t value[]; /* length sized value follows */ >> } __packed; >> >> enum iscsi_discovery_parent_type { >> @@ -815,7 +815,7 @@ struct iscsi_stats { >> * up to ISCSI_STATS_CUSTOM_MAX >> */ >> uint32_t custom_length; >> - struct iscsi_stats_custom custom[0] >> + struct iscsi_stats_custom custom[] >> __attribute__ ((aligned (sizeof(uint64_t)))); >> }; >> >> @@ -946,7 +946,7 @@ struct iscsi_offload_host_stats { >> * up to ISCSI_HOST_STATS_CUSTOM_MAX >> */ >> uint32_t custom_length; >> - struct iscsi_host_stats_custom custom[0] >> + struct iscsi_host_stats_custom custom[] >> __aligned(sizeof(uint64_t)); >> }; >> >> diff --git a/include/scsi/scsi_bsg_iscsi.h b/include/scsi/scsi_bsg_iscsi.h >> index fa0c820a1663..6b8128005af8 100644 >> --- a/include/scsi/scsi_bsg_iscsi.h >> +++ b/include/scsi/scsi_bsg_iscsi.h >> @@ -52,7 +52,7 @@ struct iscsi_bsg_host_vendor { >> uint64_t vendor_id; >> >> /* start of vendor command area */ >> - uint32_t vendor_cmd[0]; >> + uint32_t vendor_cmd[]; >> }; >> >> /* Response: >> diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h >> index f8312a3e5b42..4dc158cf09b8 100644 >> --- a/include/scsi/scsi_device.h >> +++ b/include/scsi/scsi_device.h >> @@ -231,7 +231,7 @@ struct scsi_device { >> struct mutex state_mutex; >> enum scsi_device_state sdev_state; >> struct task_struct *quiesced_by; >> - unsigned long sdev_data[0]; >> + unsigned long sdev_data[]; >> } __attribute__((aligned(sizeof(unsigned long)))); >> >> #define to_scsi_device(d) \ >> @@ -315,7 +315,7 @@ struct scsi_target { >> char scsi_level; >> enum scsi_target_state state; >> void *hostdata; /* available to low-level driver */ >> - unsigned long starget_data[0]; /* for the transport */ >> + unsigned long starget_data[]; /* for the transport */ >> /* starget_data must be the last element!!!! */ >> } __attribute__((aligned(sizeof(unsigned long)))); >> >> diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h >> index 7a97fb8104cf..e6811ea8f984 100644 >> --- a/include/scsi/scsi_host.h >> +++ b/include/scsi/scsi_host.h >> @@ -682,7 +682,7 @@ struct Scsi_Host { >> * and also because some compilers (m68k) don't automatically force >> * alignment to a long boundary. >> */ >> - unsigned long hostdata[0] /* Used for storage of host specific stuff */ >> + unsigned long hostdata[] /* Used for storage of host specific stuff */ >> __attribute__ ((aligned (sizeof(unsigned long)))); >> }; >> >> diff --git a/include/scsi/scsi_ioctl.h b/include/scsi/scsi_ioctl.h >> index 4fe69d863b5d..b465799f4d2d 100644 >> --- a/include/scsi/scsi_ioctl.h >> +++ b/include/scsi/scsi_ioctl.h >> @@ -27,7 +27,7 @@ struct scsi_device; >> typedef struct scsi_ioctl_command { >> unsigned int inlen; >> unsigned int outlen; >> - unsigned char data[0]; >> + unsigned char data[]; >> } Scsi_Ioctl_Command; >> >> typedef struct scsi_idlun { >> diff --git a/include/scsi/srp.h b/include/scsi/srp.h >> index 9220758d5087..177d8026e96f 100644 >> --- a/include/scsi/srp.h >> +++ b/include/scsi/srp.h >> @@ -109,7 +109,7 @@ struct srp_direct_buf { >> struct srp_indirect_buf { >> struct srp_direct_buf table_desc; >> __be32 len; >> - struct srp_direct_buf desc_list[0]; >> + struct srp_direct_buf desc_list[]; >> } __attribute__((packed)); >> >> /* Immediate data buffer descriptor as defined in SRP2. */ >> @@ -244,7 +244,7 @@ struct srp_cmd { >> u8 reserved4; >> u8 add_cdb_len; >> u8 cdb[16]; >> - u8 add_data[0]; >> + u8 add_data[]; >> }; >> >> enum { >> @@ -274,7 +274,7 @@ struct srp_rsp { >> __be32 data_in_res_cnt; >> __be32 sense_data_len; >> __be32 resp_data_len; >> - u8 data[0]; >> + u8 data[]; >> } __attribute__((packed)); >> >> struct srp_cred_req { >> @@ -306,7 +306,7 @@ struct srp_aer_req { >> struct scsi_lun lun; >> __be32 sense_data_len; >> u32 reserved3; >> - u8 sense_data[0]; >> + u8 sense_data[]; >> } __attribute__((packed)); >> >> struct srp_aer_rsp { >> diff --git a/include/uapi/scsi/scsi_bsg_fc.h b/include/uapi/scsi/scsi_bsg_fc.h >> index 3ae65e93235c..7f5930801f72 100644 >> --- a/include/uapi/scsi/scsi_bsg_fc.h >> +++ b/include/uapi/scsi/scsi_bsg_fc.h >> @@ -209,7 +209,7 @@ struct fc_bsg_host_vendor { >> __u64 vendor_id; >> >> /* start of vendor command area */ >> - __u32 vendor_cmd[0]; >> + __u32 vendor_cmd[]; >> }; >> >> /* Response: >> > > Reviewed-by: Lee Duncan > Thanks, Lee. -- Gustavo