Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5155600pxb; Mon, 15 Feb 2021 11:00:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJyVIII4P/NIii/RsLXXg3TzYCxWQWuPz3569Bp7EgFYyazHY049FQHGQC7nS+wK6QpEX9lr X-Received: by 2002:a17:906:2358:: with SMTP id m24mr11358024eja.333.1613415612792; Mon, 15 Feb 2021 11:00:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613415612; cv=none; d=google.com; s=arc-20160816; b=UjRk0SkMwsE8+QUJECzll6ZJtzDDSLaGmPjCImsJG1QAQquwBMiYLquj6UuH1chLLt dfIrsMm5GkkrS1U0xGVJxzWkYR1IDdP2XF499BHr9YoVQyUaoflsFusWmmiZiPdRqHb2 6LiYWWsqC+uFEb2HtOVQqrCLfeLFG9FHbWFUPGJ1EH+rqedw9BDzd/sao0xtluKGf2J2 O1feAETZhWALgTTx3o/yOvagxHVZB2goM8CO5bByxiE+dowPhFS5t0IQZvWmHaNRXINr sRot3gxzN0jMgYAVmmCDqkifPGdTqm6fb3Is6kbYOR/rkQD528n/bsptymNzNI6SmFo1 YR5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=fXBT4xpZ44BWopiCzA5BdkSekv48SAWYnj4iW61mQF0=; b=hWPkazwj44z9MdpG+y560Eg0MgA/f1UPhtXNtxoIlnATF98TPFp79k1JYEh3uXRPf4 /m+FQRidRb1qNNuKG0DporK+LtYkH68nlep9VXKK4eLPwzzvuiXdBJCOFsYgdXf0hgtM esReBQbMLVFZFxE+7CsFrByDkpNXMLWnoQS44DWmIeBhNacw2e+mta9MJcf1h32F9FRr 2FiENqlDyYbZdJWiP63NnllisQ76vDziouEa/mYrtlsz2fhLa9EQQ4HntBYJdM5cHQcb gCdgK6zzio7Uby3Hj6kpHK+SrkYvPtf8XF2nwOME0hqBgJQiqsSGCwxqnws3keqfw28d KD0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eJgS51jU; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q10si12842230edd.316.2021.02.15.10.59.48; Mon, 15 Feb 2021 11:00:12 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=eJgS51jU; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230427AbhBOS5D (ORCPT + 99 others); Mon, 15 Feb 2021 13:57:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230080AbhBOS5C (ORCPT ); Mon, 15 Feb 2021 13:57:02 -0500 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF3AFC061756; Mon, 15 Feb 2021 10:56:21 -0800 (PST) Received: by mail-oi1-x22b.google.com with SMTP id y199so8759034oia.4; Mon, 15 Feb 2021 10:56:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=fXBT4xpZ44BWopiCzA5BdkSekv48SAWYnj4iW61mQF0=; b=eJgS51jUdUles8PvvEPpAYZzFmm/tLLusqrLPgnqRR727XPOAnyZ25rbFljT37+k+Y +opKtAStkmGcOEosBRVvZzmSvwyvemfAQKfML4f6nkxk2Jr96gxGMDCZSmraPyotkvzL wP3DDtt2lqMEnbn6A5OxJU9+UlR0vQ80SdXhlgdf9JCTWbEyRqClHQRXPLlEocqKsx+O s7Jakamssj57+2F88MTAg3o5KZ/faw8Y2uZLuhlszC3IvCpNclSIVckrqv3xu2gzgSBg FZjWDEcaikSN4IAkOJrJfCJ5mB06lrUi/5sma/WFO9Ns46IMtygHDuZbraqxj4mCSlMI UAaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=fXBT4xpZ44BWopiCzA5BdkSekv48SAWYnj4iW61mQF0=; b=CtYrtyoYQ3HUnV7BesiGGKedmWHJeG9tjtTmBraTNmDzyXXsfyQMlJ/+8x+yTsCYNo clOzzojOuKW+9tyrgFNO0r4ZST9h4VL7stbhgp1hOzUX7pi08kmO3azrnYQi8v7QvOTQ +5hw6zxyKCAbw7ByhOYgmqdEEG1YBNqhZBLGLnsuwgeaUTqFasQNR8a98aNWzSDuPSd8 uGK16SovtEzfX3C3MuKnMKx+CJaeimvcEGc4odF7lbwDhX7F+1abLQymBtp+oo0Cwfpq UV64U+LU37txsffo86Cl2Ns+JXq+zi4Mp/3PFQjHjJ3L2XGqmlRIoPtN68LXtZE5PP0w efow== X-Gm-Message-State: AOAM531yQ5ke30rGc14MV9rdgWeQhI1qBGrwi/CSZwLsXvUooKzgxyAe ZcvnyhKq1qN0fVr4JmFPyHkaMr5/3PFIx8/DauFydhFP X-Received: by 2002:aca:fc0c:: with SMTP id a12mr200788oii.5.1613415381226; Mon, 15 Feb 2021 10:56:21 -0800 (PST) MIME-Version: 1.0 References: <20210210224031.GA8795@embeddedor> In-Reply-To: <20210210224031.GA8795@embeddedor> From: Alex Deucher Date: Mon, 15 Feb 2021 13:56:10 -0500 Message-ID: Subject: Re: [PATCH][next] drm/amd/pm: Replace one-element array with flexible-array in struct SISLANDS_SMC_SWSTATE To: "Gustavo A. R. Silva" Cc: Evan Quan , Alex Deucher , =?UTF-8?Q?Christian_K=C3=B6nig?= , David Airlie , Daniel Vetter , linux-hardening@vger.kernel.org, Maling list - DRI developers , amd-gfx list , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 10, 2021 at 5:40 PM Gustavo A. R. Silva 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 =E2=80=9Cflexible array members=E2=80=9D[1] for these c= ases. The older > style of one-element or zero-length arrays should no longer be used[2]. > > Refactor the code according to the use of a flexible-array member in > struct SISLANDS_SMC_SWSTATE, instead of a one-element array, and use > the struct_size() helper to calculate the size for the allocation. > > Also, this helps with the ongoing efforts to enable -Warray-bounds and > fix the following warnings: > > drivers/gpu/drm/amd/amdgpu/../pm/powerplay/si_dpm.c:2448:20: warning: arr= ay > subscript 1 is above array bounds of =E2=80=98SISLANDS_SMC_HW_PERFORMANCE= _LEVEL[1]=E2=80=99 > {aka =E2=80=98struct SISLANDS_SMC_HW_PERFORMANCE_LEVEL[1]=E2=80=99} [-War= ray-bounds] > drivers/gpu/drm/amd/amdgpu/../pm/powerplay/si_dpm.c:2449:20: warning: arr= ay > subscript 1 is above array bounds of =E2=80=98SISLANDS_SMC_HW_PERFORMANCE= _LEVEL[1]=E2=80=99 > {aka =E2=80=98struct SISLANDS_SMC_HW_PERFORMANCE_LEVEL[1]=E2=80=99} [-War= ray-bounds] > drivers/gpu/drm/amd/amdgpu/../pm/powerplay/si_dpm.c:2450:20: warning: arr= ay > subscript 1 is above array bounds of =E2=80=98SISLANDS_SMC_HW_PERFORMANCE= _LEVEL[1]=E2=80=99 > {aka =E2=80=98struct SISLANDS_SMC_HW_PERFORMANCE_LEVEL[1]=E2=80=99} [-War= ray-bounds] > drivers/gpu/drm/amd/amdgpu/../pm/powerplay/si_dpm.c:2451:20: warning: arr= ay > subscript 1 is above array bounds of =E2=80=98SISLANDS_SMC_HW_PERFORMANCE= _LEVEL[1]=E2=80=99 > {aka =E2=80=98struct SISLANDS_SMC_HW_PERFORMANCE_LEVEL[1]=E2=80=99} [-War= ray-bounds] > drivers/gpu/drm/amd/amdgpu/../pm/powerplay/si_dpm.c:2452:20: warning: arr= ay > subscript 1 is above array bounds of =E2=80=98SISLANDS_SMC_HW_PERFORMANCE= _LEVEL[1]=E2=80=99 > {aka =E2=80=98struct SISLANDS_SMC_HW_PERFORMANCE_LEVEL[1]=E2=80=99} [-War= ray-bounds] > drivers/gpu/drm/amd/amdgpu/../pm/powerplay/si_dpm.c:5570:20: warning: arr= ay > subscript 1 is above array bounds of =E2=80=98SISLANDS_SMC_HW_PERFORMANCE= _LEVEL[1]=E2=80=99 > {aka =E2=80=98struct SISLANDS_SMC_HW_PERFORMANCE_LEVEL[1]=E2=80=99} [-War= ray-bounds] > > [1] https://en.wikipedia.org/wiki/Flexible_array_member > [2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-len= gth-and-one-element-arrays > > Link: https://github.com/KSPP/linux/issues/79 > Link: https://github.com/KSPP/linux/issues/109 > Build-tested-by: kernel test robot > Link: https://lore.kernel.org/lkml/6023be58.sk66L%2FV4vuSJI5mI%25lkp@inte= l.com/ > Signed-off-by: Gustavo A. R. Silva Applied. Thanks! Alex > --- > drivers/gpu/drm/amd/pm/powerplay/si_dpm.c | 6 ++---- > drivers/gpu/drm/amd/pm/powerplay/sislands_smc.h | 10 +++++----- > 2 files changed, 7 insertions(+), 9 deletions(-) > > diff --git a/drivers/gpu/drm/amd/pm/powerplay/si_dpm.c b/drivers/gpu/drm/= amd/pm/powerplay/si_dpm.c > index afa1711c9620..62291358fb1c 100644 > --- a/drivers/gpu/drm/amd/pm/powerplay/si_dpm.c > +++ b/drivers/gpu/drm/amd/pm/powerplay/si_dpm.c > @@ -5715,11 +5715,9 @@ static int si_upload_sw_state(struct amdgpu_device= *adev, > int ret; > u32 address =3D si_pi->state_table_start + > offsetof(SISLANDS_SMC_STATETABLE, driverState); > - u32 state_size =3D sizeof(SISLANDS_SMC_SWSTATE) + > - ((new_state->performance_level_count - 1) * > - sizeof(SISLANDS_SMC_HW_PERFORMANCE_LEVEL)); > SISLANDS_SMC_SWSTATE *smc_state =3D &si_pi->smc_statetable.driver= State; > - > + size_t state_size =3D struct_size(smc_state, levels, > + new_state->performance_level_coun= t); > memset(smc_state, 0, state_size); > > ret =3D si_convert_power_state_to_smc(adev, amdgpu_new_state, smc= _state); > diff --git a/drivers/gpu/drm/amd/pm/powerplay/sislands_smc.h b/drivers/gp= u/drm/amd/pm/powerplay/sislands_smc.h > index d2930eceaf3c..0f7554052c90 100644 > --- a/drivers/gpu/drm/amd/pm/powerplay/sislands_smc.h > +++ b/drivers/gpu/drm/amd/pm/powerplay/sislands_smc.h > @@ -182,11 +182,11 @@ typedef struct SISLANDS_SMC_HW_PERFORMANCE_LEVEL SI= SLANDS_SMC_HW_PERFORMANCE_LEV > > struct SISLANDS_SMC_SWSTATE > { > - uint8_t flags; > - uint8_t levelCount; > - uint8_t padding2; > - uint8_t padding3; > - SISLANDS_SMC_HW_PERFORMANCE_LEVEL levels[1]; > + uint8_t flags; > + uint8_t levelCount; > + uint8_t padding2; > + uint8_t padding3; > + SISLANDS_SMC_HW_PERFORMANCE_LEVEL levels[]; > }; > > typedef struct SISLANDS_SMC_SWSTATE SISLANDS_SMC_SWSTATE; > -- > 2.27.0 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel