lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z9PmC4lExxDMusf3@google.com>
Date: Fri, 14 Mar 2025 08:17:15 +0000
From: Tzung-Bi Shih <tzungbi@...nel.org>
To: "Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc: Alexandre Belloni <alexandre.belloni@...tlin.com>,
	Benson Leung <bleung@...omium.org>,
	Guenter Roeck <groeck@...omium.org>, linux-rtc@...r.kernel.org,
	chrome-platform@...ts.linux.dev, linux-kernel@...r.kernel.org,
	linux-hardening@...r.kernel.org
Subject: Re: [PATCH][next] rtc: Avoid a couple of
 -Wflex-array-member-not-at-end warnings

On Fri, Mar 14, 2025 at 11:14:54AM +1030, Gustavo A. R. Silva wrote:
>  static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
>  			   u32 *response)
>  {
> +	DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
> +			sizeof(struct ec_response_rtc));
>  	int ret;
> -	struct {
> -		struct cros_ec_command msg;
> -		struct ec_response_rtc data;
> -	} __packed msg;
>  
> -	memset(&msg, 0, sizeof(msg));
> -	msg.msg.command = command;
> -	msg.msg.insize = sizeof(msg.data);
> +	msg->command = command;
> +	msg->insize = sizeof(struct ec_response_rtc);
>  
> -	ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
> +	ret = cros_ec_cmd_xfer_status(cros_ec, msg);
>  	if (ret < 0)
>  		return ret;
>  
> -	*response = msg.data.time;
> +	memcpy(response, msg->data, sizeof(*response));

Technically they are the same as `struct ec_response_rtc` only has an
u32 member.  Any reason to not translate it something similar to:

*response = ((struct ec_response_rtc *)msg->data)->time;

>  
>  	return 0;
>  }
> @@ -57,18 +54,15 @@ static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
>  static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command,
>  			   u32 param)
>  {
> +	DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
> +			sizeof(struct ec_response_rtc));
>  	int ret;
> -	struct {
> -		struct cros_ec_command msg;
> -		struct ec_response_rtc data;
> -	} __packed msg;
>  
> -	memset(&msg, 0, sizeof(msg));
> -	msg.msg.command = command;
> -	msg.msg.outsize = sizeof(msg.data);
> -	msg.data.time = param;
> +	msg->command = command;
> +	msg->outsize = sizeof(struct ec_response_rtc);
> +	memcpy(msg->data, &param, sizeof(param));

Same here, how about:

((struct ec_response_rtc *)msg->data)->time = param;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ