From patchwork Wed May 17 23:38:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 95598 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp136389vqo; Wed, 17 May 2023 17:14:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ67MX+iZOeXJYQ3bS1cGECUHcici2M8t7/45SbcrMAh0P6i8ilXVlPyCofeEIay3llJ8mYo X-Received: by 2002:a05:6a20:d2c3:b0:ff:e4f8:dc3 with SMTP id ir3-20020a056a20d2c300b000ffe4f80dc3mr40215pzb.39.1684368885555; Wed, 17 May 2023 17:14:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684368885; cv=none; d=google.com; s=arc-20160816; b=Vg3wvwk4oEpZ4oCdXw50W14soHc16QMRSREmobXd1MSLxx2fMvWZcbUkD5mNOBLQ4+ B9E+1z0dsNRkOgR8HJIB+/P19EXdkQmCj7aoK7aB6PyPwny2/8QXuL79ouoWI93HuXy9 Q2mK/fsPuXN1bw/1ksnnUJlI8Xgbd/8PfhmaDe/NrWTSI4gKTiCdTHRwvXO+vcvE+Htt 6H7my6YVGQYP7VPswggY1hSjJdpuYIBibU32K4EmBGMVg/bn+6yGREyZAViQHOy16dxQ sZFJ55YwozO0+r01UcGfjdMYvmttJZs0vCUHUfmHUu0M5sLa8HfBX5phmixXGXgku+QS yyeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=SEQHbgJZSxtt4wozMGRwLYHiaggnjj5fAiA+HJB30d4=; b=fIsye45BV5Ok+rGpNyjEOigkFBA60PboQZiG0tQnlzvDpulOdQf4Zxe6c9XI93hDb8 6c1fmu5XscSgfaKYSn2to6U45G0uyM82VzTHfZ8uIZD7QQz1RXctxFnRIi01n2LP3x2C +ecJzz5Zc7B7i6PBN2ReXJI1gf5Vp4XXNoQBUCwqBVMyLrWtEnWsrHaBVTT/3ukqNkLK WjaDDanlTY9JZaxPRbx9s65uvK1aYII9c67fNKn1/WyDpS88mD3oRVZHBLj8ZnrawDRH zpEMKX4eYG2fTIFEb3yCslPWJ/9G7dHFjsytceKIL4YD4kR7JBxfhLooixOaeZeFzrx2 sFkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZR4CEugP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b190-20020a6334c7000000b0053440fe081csi14019pga.643.2023.05.17.17.14.33; Wed, 17 May 2023 17:14:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZR4CEugP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229574AbjEQXhk (ORCPT + 99 others); Wed, 17 May 2023 19:37:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjEQXhj (ORCPT ); Wed, 17 May 2023 19:37:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDA80115; Wed, 17 May 2023 16:37:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5FA6164BDC; Wed, 17 May 2023 23:37:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC9EBC433D2; Wed, 17 May 2023 23:37:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684366656; bh=vuVnTgWxQpmJvzDxdn+D8W/c3eqLsteSK4ZcsNFRCWM=; h=Date:From:To:Cc:Subject:From; b=ZR4CEugP/P7xzTDnDOwqF8irR5Aqly5oOVFgm39EYAr3YxL/mz15CQYmt07ORgnNT mWq5eSMHGxolIF3ruJl/f1MCNIuW1BdMldwb3RqUNpJPXFM5xitC9aPCRZMcP3kR1B n1PoRgntGJfHRH8WY0ktB5Is4aIu9sOruaZlivc1RI3R4Jdzrz8XdGrfDQZ+bgSa/t CBxkcPhaQbK+fhkCS52rm6JIlh2WPixlOyl4ECJQwSBmBXlktkEFsnjuYQzv1SK5d3 6EwoyHO4KIK6EwpsSxdnNgFRuQMsmkZHxGUU0e5Bl7K78qrq8GWSl5EIQr3YhuJjFC yE5isIMMgJW5A== Date: Wed, 17 May 2023 17:38:26 -0600 From: "Gustavo A. R. Silva" To: Jaroslav Kysela , Takashi Iwai Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] ALSA: mixart: Replace one-element arrays with simple object declarations Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766188788351984609?= X-GMAIL-MSGID: =?utf-8?q?1766188788351984609?= One-element arrays are deprecated, and we are replacing them with flexible array members, instead. However, in this case it seems those one-element arrays have never actually been used as fake flexible arrays. See this code that dates from Linux-2.6.12-rc2 initial git repository build (commit 1da177e4c3f4 ("Linux-2.6.12-rc2")): sound/pci/mixart/mixart_core.h: 215 struct mixart_stream_state_req 216 { 217 u32 delayed; 218 u64 scheduler; 219 u32 reserved4np[3]; 220 u32 stream_count; /* set to 1 for instance */ 221 struct mixart_flow_info stream_info; /* could be an array[stream_cou nt] */ 222 } __attribute__((packed)); sound/pci/mixart/mixart.c: 388 389 memset(&stream_state_req, 0, sizeof(stream_state_req)); 390 stream_state_req.stream_count = 1; 391 stream_state_req.stream_info.stream_desc.uid_pipe = stream->pipe->group_uid; 392 stream_state_req.stream_info.stream_desc.stream_idx = stream->substream->number; 393 So, taking the code above as example, replace multiple one-element arrays with simple object declarations, and refactor the rest of the code, accordingly. This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1]. This results in no differences in binary output. Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/KSPP/linux/issues/296 Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] Signed-off-by: Gustavo A. R. Silva --- sound/pci/mixart/mixart.c | 8 ++++---- sound/pci/mixart/mixart_core.h | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c index 1b078b789604..7ceaf6a7a77e 100644 --- a/sound/pci/mixart/mixart.c +++ b/sound/pci/mixart/mixart.c @@ -98,7 +98,7 @@ static int mixart_set_pipe_state(struct mixart_mgr *mgr, memset(&group_state, 0, sizeof(group_state)); group_state.pipe_count = 1; - group_state.pipe_uid[0] = pipe->group_uid; + group_state.pipe_uid = pipe->group_uid; if(start) request.message_id = MSG_STREAM_START_STREAM_GRP_PACKET; @@ -185,7 +185,7 @@ static int mixart_set_clock(struct mixart_mgr *mgr, clock_properties.clock_mode = CM_STANDALONE; clock_properties.frequency = rate; clock_properties.nb_callers = 1; /* only one entry in uid_caller ! */ - clock_properties.uid_caller[0] = pipe->group_uid; + clock_properties.uid_caller = pipe->group_uid; dev_dbg(&mgr->pci->dev, "mixart_set_clock to %d kHz\n", rate); @@ -565,8 +565,8 @@ static int mixart_set_format(struct mixart_stream *stream, snd_pcm_format_t form stream_param.pipe_count = 1; /* set to 1 */ stream_param.stream_count = 1; /* set to 1 */ - stream_param.stream_desc[0].uid_pipe = stream->pipe->group_uid; - stream_param.stream_desc[0].stream_idx = stream->substream->number; + stream_param.stream_desc.uid_pipe = stream->pipe->group_uid; + stream_param.stream_desc.stream_idx = stream->substream->number; request.message_id = MSG_STREAM_SET_INPUT_STAGE_PARAM; request.uid = (struct mixart_uid){0,0}; diff --git a/sound/pci/mixart/mixart_core.h b/sound/pci/mixart/mixart_core.h index 2f0e29ed5d63..ac74b2133c97 100644 --- a/sound/pci/mixart/mixart_core.h +++ b/sound/pci/mixart/mixart_core.h @@ -231,7 +231,7 @@ struct mixart_group_state_req u64 scheduler; u32 reserved4np[2]; u32 pipe_count; /* set to 1 for instance */ - struct mixart_uid pipe_uid[1]; /* could be an array[pipe_count] */ + struct mixart_uid pipe_uid; } __attribute__((packed)); struct mixart_group_state_resp @@ -314,7 +314,7 @@ struct mixart_clock_properties u32 format; u32 board_mask; u32 nb_callers; /* set to 1 (see below) */ - struct mixart_uid uid_caller[1]; + struct mixart_uid uid_caller; } __attribute__((packed)); struct mixart_clock_properties_resp @@ -401,8 +401,7 @@ struct mixart_stream_param_desc u32 reserved4np[3]; u32 pipe_count; /* set to 1 (array size !) */ u32 stream_count; /* set to 1 (array size !) */ - struct mixart_txx_stream_desc stream_desc[1]; /* only one stream per command, but this could be an array */ - + struct mixart_txx_stream_desc stream_desc; } __attribute__((packed));