Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1937668ybh; Tue, 14 Jul 2020 11:06:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2b7kInuLFGV31j7akIisSJ1C9SoH2nS26eQQu9Zhfh3Jp9dEsj10a5uHcMtexWRsYfT/A X-Received: by 2002:a17:907:20c4:: with SMTP id qq4mr5500857ejb.85.1594749971916; Tue, 14 Jul 2020 11:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594749971; cv=none; d=google.com; s=arc-20160816; b=YdrpJmyWqfGOy42Nppc353Nk6bzy7B6GHBAxi/SJPV7CnxAngWxns+WNMO+kF5gZbS yUPN+6uU8iHT1xpLjY++Js9GZ5nu+2LwoStgApyZI7RwETzLbiGGK8jL+uVU99etmyOw /BVARxcqFSwKTt+Bm0SYzk4yZWjHgvQBbK/SduJ9nPA/kMEnrTbeAYUI+BxtJuQ5sYC+ RkFwVSxOQ6MJ5RRsHyHUiBVR4aXabrPBXS2lRv6aLQpLAkBMm1BWhSZd/wcy0/rTWLi6 4nkEznnjhttuL6rFlrQI3JhouGSmv41HMmHsdPXLOanvEJu4i9aWqGe2rfYZKbWC91uy kx2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6xS5VjXPTAA06G9+zwmwnO0fPHHEuKtZ0F8MbOTfX68=; b=RrMLRIrJyBQHjrfRLqqPBG/dB3O4s+0Aq5bDzqlNVjVYwQRNDq6pbHtJIfs7vDuDsb RYGXg8qgf7K5kNIGzxxmfqpd5xextMyFUz2J3VyZ6eAI+o9YrO7fM8du8jn0Ov0EZv8c BFDYEW6kzU4VJlD/ngCxLbCXxGnU8MiODliO9nQP6h4GCzVlMRMx7bTEKUVWC0/BTHMT nVx6SVZ3GGdLeRThV7y1lLcw8tpAiYp2PQRDx3nI2JaZuvR+CMidyy+Of3TO2/GPtLx5 DQfmGb4UWFW9SQh3R1z3+u9yjI4Jwxpz9WZ2Pr7ciqWKrcW0AFzu6JG+telGVHlUVhHf sUAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hH8elfPL; 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; 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 lk3si11472744ejb.653.2020.07.14.11.05.48; Tue, 14 Jul 2020 11:06:11 -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; dkim=pass header.i=@kernel.org header.s=default header.b=hH8elfPL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729007AbgGNSDY (ORCPT + 99 others); Tue, 14 Jul 2020 14:03:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:55960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727028AbgGNSDY (ORCPT ); Tue, 14 Jul 2020 14:03:24 -0400 Received: from embeddedor (unknown [201.162.240.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B450F22582; Tue, 14 Jul 2020 18:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594749803; bh=27yz5joe+49D2494fVuVbmM7h/G2j1WWWKnYTtSpw7o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hH8elfPLJqZU4PF+MMAJRQZhsLdzvNUaVZjCRylV24xv4YMR7Q/R2Tz9ZwK2qC915 mXl6OFopoiUl6QIUl98T0Yz13cy7X3Zx68mZgzKYak6Kq7ODLp0g8kKrrrHKzDjMws HOXqxSydOTFJcBvQXegyrM7c/FxaWVF7xRok/ptQ= Date: Tue, 14 Jul 2020 13:08:55 -0500 From: "Gustavo A. R. Silva" To: "Winkler, Tomas" Cc: Arnd Bergmann , Greg Kroah-Hartman , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH][next] mei: Avoid the use of one-element arrays Message-ID: <20200714180855.GA31158@embeddedor> References: <20200714174644.GA30158@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 14, 2020 at 05:54:32PM +0000, Winkler, Tomas wrote: > > > > There is a regular need in the kernel to provide a way to declare having a > > dynamically sized set of trailing elements in a structure. > > Kernel code should always use “flexible array members”[1] for these cases > > or, as in this particular case, replace the one-element array with a simple > > value type u8 reserved once this is just a placeholder for alignment. The older > > style of one-element or zero-length arrays should no longer be used[2]. > > > > Also, while there, use the preferred form for passing a size of a struct. > > The alternative form where struct name is spelled out hurts readability and > > introduces an opportunity for a bug when the variable type is changed but > > the corresponding sizeof that is passed as argument is not. > > > > [1] https://en.wikipedia.org/wiki/Flexible_array_member > > [2] https://github.com/KSPP/linux/issues/79 > > > > Signed-off-by: Gustavo A. R. Silva > I'm okay with the patch but in this case the description is a bit off. > In this case there was no intention for a flexible arrays its just a reserved field. > The reserved field is actually mentioned in the description: "... or, as in this particular case, replace the one-element array with a simple value type u8 reserved once this is just a placeholder for alignment." Thanks -- Gustavo > > --- > > drivers/misc/mei/hbm.c | 4 ++-- > > drivers/misc/mei/hw.h | 6 +++--- > > 2 files changed, 5 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c index > > a44094cdbc36..f020d5594154 100644 > > --- a/drivers/misc/mei/hbm.c > > +++ b/drivers/misc/mei/hbm.c > > @@ -408,14 +408,14 @@ static int mei_hbm_add_cl_resp(struct mei_device > > *dev, u8 addr, u8 status) { > > struct mei_msg_hdr mei_hdr; > > struct hbm_add_client_response resp; > > - const size_t len = sizeof(struct hbm_add_client_response); > > + const size_t len = sizeof(resp); > > int ret; > > > > dev_dbg(dev->dev, "adding client response\n"); > > > > mei_hbm_hdr(&mei_hdr, len); > > > > - memset(&resp, 0, sizeof(struct hbm_add_client_response)); > > + memset(&resp, 0, len); > > resp.hbm_cmd = MEI_HBM_ADD_CLIENT_RES_CMD; > > resp.me_addr = addr; > > resp.status = status; > > diff --git a/drivers/misc/mei/hw.h b/drivers/misc/mei/hw.h index > > b1a8d5ec88b3..8c0297f0e7f3 100644 > > --- a/drivers/misc/mei/hw.h > > +++ b/drivers/misc/mei/hw.h > > @@ -346,13 +346,13 @@ struct hbm_add_client_request { > > * @hbm_cmd: bus message command header > > * @me_addr: address of the client in ME > > * @status: if HBMS_SUCCESS then the client can now accept connections. > > - * @reserved: reserved > > + * @reserved: reserved for alignment. > > */ > > struct hbm_add_client_response { > > u8 hbm_cmd; > > u8 me_addr; > > u8 status; > > - u8 reserved[1]; > > + u8 reserved; > > } __packed; > > > > /** > > @@ -461,7 +461,7 @@ struct hbm_notification { > > u8 hbm_cmd; > > u8 me_addr; > > u8 host_addr; > > - u8 reserved[1]; > > + u8 reserved; > > } __packed; > > > > /** > > -- > > 2.27.0 >