Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1923035ybh; Tue, 14 Jul 2020 10:44:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztmQA7Hq5wmuWnkVqsAXWucX3+/80GHiicYExfSjpPYedrmjZH7lS4ejTdGUylZfhCz12x X-Received: by 2002:aa7:d4d2:: with SMTP id t18mr5589444edr.166.1594748642080; Tue, 14 Jul 2020 10:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594748642; cv=none; d=google.com; s=arc-20160816; b=KfmB4lg4rz1+kFQBM47yacdooN5BITj5C2Z/Q+HXGEMXZtsYZ9jVF8Ho3XTwCNIvdj 1dQ0zxu/KBB2KANoK5gUF3T42s35o3zQcB9kLIDwugS3SYejkt9NRgCYzFKX61BFvbXz 5E9lkYGnvqMNUu9COa4Y8oItWOnlGEdgYOyg5eVzZN2xfSMTxKGNbCaFkjqSlu7+ciVV 9cCbxAxJ+9JxHti6Rn8+iRyccf2hrwdVs+S7EALX0rveOTflE01jtcsu/rlX4QnjuoFX q6nQSx/FWg4HkwJuoKPSGGa+Dp7kDta9kubHTQ0eJjRt6k7g3og2kdWch1xcceXliJWC UXcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-transfer-encoding :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=UD0Khswai/4ukKErSJ9xd8UKHk9C2E9+48PAdmxULqE=; b=k6pu5WhrLSr+Rme/A4MZdlxxe8TLvwfTQnnc5Z+rPBbxon0Paj+ytzafGdyjujQaxX aJu67kJ+sfS6ObKXYFsixKlZFa3QiwXevPeQR13Vsm/hzUMl0jEIXHBUz+wsPanVjViZ ozSxUa1yDcLwR/TJ2TZtOXucWg1SvW/OFOmpLqgV5w9TPJuAg/4lnATbsRhddI8xQ82G LoTfrTsZSwr+HuVsliaNlUN7Vyjb/gK8jlsgw2djK42glmkGkdJlx9v+QsmszX/79W8t ZmwPi4dYAC+tf/KWoth4cTxyKSXAnoPLiyTHQDkhzA5KfSpxcVKI40cZZzyIC8AfOf7C RR4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K97paYti; 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 z4si10879951ejw.122.2020.07.14.10.43.38; Tue, 14 Jul 2020 10:44:02 -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=K97paYti; 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 S1728186AbgGNRlO (ORCPT + 99 others); Tue, 14 Jul 2020 13:41:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:48994 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726817AbgGNRlO (ORCPT ); Tue, 14 Jul 2020 13:41:14 -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 0EAF822518; Tue, 14 Jul 2020 17:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594748473; bh=vM7p8L7u7/uyCT4xL0z7JnamaY49/SNemiuMcAsgCHM=; h=Date:From:To:Cc:Subject:From; b=K97paYtiO5JswQ/SFsEKZgQumy6W6G3Fj7bzGFJvTbIWayONSCA0T5U8Cn407Y8cv YO6Dt1dVp1InaT8Qcuo1GU5O+7k5NEJdibWJpW2+/165Yy/cN2ZGobW6ll/S1zWSm9 /q5I6p3+c9Neu6InWyvFtqpWkP8vVD8i2R782PQI= Date: Tue, 14 Jul 2020 12:46:44 -0500 From: "Gustavo A. R. Silva" To: Tomas Winkler , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH][next] mei: Avoid the use of one-element arrays Message-ID: <20200714174644.GA30158@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 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 --- 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