From nobody Sat Feb 7 17:55:33 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B19551993B1; Thu, 3 Apr 2025 16:45:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743698721; cv=none; b=DwfDa0AylqcT9KMgViJJHmuO1x/IXHJcTtjZjp6mG8XFWjJKzTVanHJuksH+78XbxqT/Ee4FL33tbrk44xHu9wQqaAFCQWWNwxDm8kXVXxhdbK0ERkZ6kTEmHgss+y9yqLtqhkB9rHgJ0pLCCRL1DNNRE51b8I/ZMChgHhpUQBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743698721; c=relaxed/simple; bh=rAccSmKogNdZqOMCmUuI1Eux/x/3CMaAChmohtmbCd8=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=V0QENzb3BzuapbpN1R789wVFL08dQ0HYvwcEs/wXWVgj20zwVv0Ysk1ScF/dbKUzZiDqxbNxJICqepmXLSSIDo8eI8JvJsmSZpSH99/yIYQbaiw6HTeBC3ebTjbpRiRWoN/zdsBjHRZfhv6LMXR6aQQZT5XNFG5/uy+TEfU7kmU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uy68cCCL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uy68cCCL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54625C4CEE3; Thu, 3 Apr 2025 16:45:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743698721; bh=rAccSmKogNdZqOMCmUuI1Eux/x/3CMaAChmohtmbCd8=; h=Date:From:To:Cc:Subject:From; b=uy68cCCLzya5knEykk9QlaK/yc9DY2hkxl4f1N8xmkhCR6vNXbk59I2DbINpoz1hj z5fgcEWGV8X4zUH5TTnXdsWWHZIM3oVNl/XDnj6FUYUJOSTJc9bQ9FNpcM7BEfW3zL nctDcJnTqMKSIeHE7CEbFT8roJ+MHw/oAed09GVRhde48Xl3dVXE60pnJN/pTiS5cT rOj1wjPijICVs8ilEAZIZKtuiq+u0azA2GDDfWp9yflHnjFl4QUucTR+0dONGgsXPs Im/HnijfAz4lwO+20FakDpe+QTzE78JzEVLmBVX+wFTvWR+d+fFU/PEQi3sBDOsbmX b/iU1xCAb6kyQ== Date: Thu, 3 Apr 2025 10:45:18 -0600 From: "Gustavo A. R. Silva" To: Lyude Paul , Danilo Krummrich , David Airlie , Simona Vetter Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] drm/nouveau: chan: Avoid -Wflex-array-member-not-at-end warnings Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" -Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally. Use the `DEFINE_RAW_FLEX()` helper for a few on-stack definitions of a flexible structure where the size of the flexible-array member is known at compile-time, and refactor the rest of the code, accordingly. So, with these changes, fix the following warnings: drivers/gpu/drm/nouveau/nouveau_chan.c:274:37: warning: structure containin= g a flexible array member is not at the end of another structure [-Wflex-ar= ray-member-not-at-end] drivers/gpu/drm/nouveau/nouveau_chan.c:371:46: warning: structure containin= g a flexible array member is not at the end of another structure [-Wflex-ar= ray-member-not-at-end] drivers/gpu/drm/nouveau/nouveau_chan.c:524:42: warning: structure containin= g a flexible array member is not at the end of another structure [-Wflex-ar= ray-member-not-at-end] Signed-off-by: Gustavo A. R. Silva --- drivers/gpu/drm/nouveau/nouveau_chan.c | 115 ++++++++++++------------- 1 file changed, 56 insertions(+), 59 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_chan.c b/drivers/gpu/drm/nouve= au/nouveau_chan.c index cd659b9fd1d9..a7e70517b7cd 100644 --- a/drivers/gpu/drm/nouveau/nouveau_chan.c +++ b/drivers/gpu/drm/nouveau/nouveau_chan.c @@ -270,10 +270,7 @@ nouveau_channel_ctor(struct nouveau_cli *cli, bool pri= v, u64 runm, { NV03_CHANNEL_DMA , 0 }, {} }; - struct { - struct nvif_chan_v0 chan; - char name[TASK_COMM_LEN+16]; - } args; + DEFINE_RAW_FLEX(struct nvif_chan_v0, args, name, TASK_COMM_LEN + 16); struct nvif_device *device =3D &cli->device; struct nouveau_channel *chan; const u64 plength =3D 0x10000; @@ -298,28 +295,28 @@ nouveau_channel_ctor(struct nouveau_cli *cli, bool pr= iv, u64 runm, return ret; =20 /* create channel object */ - args.chan.version =3D 0; - args.chan.namelen =3D sizeof(args.name); - args.chan.runlist =3D __ffs64(runm); - args.chan.runq =3D 0; - args.chan.priv =3D priv; - args.chan.devm =3D BIT(0); + args->version =3D 0; + args->namelen =3D __struct_size(args) - sizeof(*args); + args->runlist =3D __ffs64(runm); + args->runq =3D 0; + args->priv =3D priv; + args->devm =3D BIT(0); if (hosts[cid].oclass < NV50_CHANNEL_GPFIFO) { - args.chan.vmm =3D 0; - args.chan.ctxdma =3D nvif_handle(&chan->push.ctxdma); - args.chan.offset =3D chan->push.addr; - args.chan.length =3D 0; + args->vmm =3D 0; + args->ctxdma =3D nvif_handle(&chan->push.ctxdma); + args->offset =3D chan->push.addr; + args->length =3D 0; } else { - args.chan.vmm =3D nvif_handle(&chan->vmm->vmm.object); + args->vmm =3D nvif_handle(&chan->vmm->vmm.object); if (hosts[cid].oclass < FERMI_CHANNEL_GPFIFO) - args.chan.ctxdma =3D nvif_handle(&chan->push.ctxdma); + args->ctxdma =3D nvif_handle(&chan->push.ctxdma); else - args.chan.ctxdma =3D 0; - args.chan.offset =3D ioffset + chan->push.addr; - args.chan.length =3D ilength; + args->ctxdma =3D 0; + args->offset =3D ioffset + chan->push.addr; + args->length =3D ilength; } - args.chan.huserd =3D 0; - args.chan.ouserd =3D 0; + args->huserd =3D 0; + args->ouserd =3D 0; =20 /* allocate userd */ if (hosts[cid].oclass >=3D VOLTA_CHANNEL_GPFIFO_A) { @@ -329,27 +326,28 @@ nouveau_channel_ctor(struct nouveau_cli *cli, bool pr= iv, u64 runm, if (ret) return ret; =20 - args.chan.huserd =3D nvif_handle(&chan->mem_userd.object); - args.chan.ouserd =3D 0; + args->huserd =3D nvif_handle(&chan->mem_userd.object); + args->ouserd =3D 0; =20 chan->userd =3D &chan->mem_userd.object; } else { chan->userd =3D &chan->user; } =20 - snprintf(args.name, sizeof(args.name), "%s[%d]", current->comm, task_pid_= nr(current)); + snprintf(args->name, __struct_size(args) - sizeof(*args), "%s[%d]", + current->comm, task_pid_nr(current)); =20 ret =3D nvif_object_ctor(&device->object, "abi16ChanUser", 0, hosts[cid].= oclass, - &args, sizeof(args), &chan->user); + args, __struct_size(args), &chan->user); if (ret) { nouveau_channel_del(pchan); return ret; } =20 - chan->runlist =3D args.chan.runlist; - chan->chid =3D args.chan.chid; - chan->inst =3D args.chan.inst; - chan->token =3D args.chan.token; + chan->runlist =3D args->runlist; + chan->chid =3D args->chid; + chan->inst =3D args->inst; + chan->token =3D args->token; return 0; } =20 @@ -367,17 +365,17 @@ nouveau_channel_init(struct nouveau_channel *chan, u3= 2 vram, u32 gart) return ret; =20 if (chan->user.oclass >=3D FERMI_CHANNEL_GPFIFO) { - struct { - struct nvif_event_v0 base; - struct nvif_chan_event_v0 host; - } args; + DEFINE_RAW_FLEX(struct nvif_event_v0, args, data, + sizeof(struct nvif_chan_event_v0)); + struct nvif_chan_event_v0 *host =3D + (struct nvif_chan_event_v0 *)args->data; =20 - args.host.version =3D 0; - args.host.type =3D NVIF_CHAN_EVENT_V0_KILLED; + host->version =3D 0; + host->type =3D NVIF_CHAN_EVENT_V0_KILLED; =20 ret =3D nvif_event_ctor(&chan->user, "abi16ChanKilled", chan->chid, nouveau_channel_killed, false, - &args.base, sizeof(args), &chan->kill); + args, __struct_size(args), &chan->kill); if (ret =3D=3D 0) ret =3D nvif_event_allow(&chan->kill); if (ret) { @@ -520,46 +518,45 @@ nouveau_channels_fini(struct nouveau_drm *drm) int nouveau_channels_init(struct nouveau_drm *drm) { - struct { - struct nv_device_info_v1 m; - struct { - struct nv_device_info_v1_data channels; - struct nv_device_info_v1_data runlists; - } v; - } args =3D { - .m.version =3D 1, - .m.count =3D sizeof(args.v) / sizeof(args.v.channels), - .v.channels.mthd =3D NV_DEVICE_HOST_CHANNELS, - .v.runlists.mthd =3D NV_DEVICE_HOST_RUNLISTS, - }; + DEFINE_RAW_FLEX(struct nv_device_info_v1, args, data, 2); + struct nv_device_info_v1_data *channels =3D &args->data[0]; + struct nv_device_info_v1_data *runlists =3D &args->data[1]; struct nvif_object *device =3D &drm->client.device.object; int ret, i; =20 - ret =3D nvif_object_mthd(device, NV_DEVICE_V0_INFO, &args, sizeof(args)); + args->version =3D 1; + args->count =3D (__struct_size(args) - sizeof(*args)) / + sizeof(*args->data); + channels->mthd =3D NV_DEVICE_HOST_CHANNELS; + runlists->mthd =3D NV_DEVICE_HOST_RUNLISTS; + + ret =3D nvif_object_mthd(device, NV_DEVICE_V0_INFO, args, + __struct_size(args)); if (ret || - args.v.runlists.mthd =3D=3D NV_DEVICE_INFO_INVALID || !args.v.runlist= s.data || - args.v.channels.mthd =3D=3D NV_DEVICE_INFO_INVALID) + runlists->mthd =3D=3D NV_DEVICE_INFO_INVALID || !runlists->data || + channels->mthd =3D=3D NV_DEVICE_INFO_INVALID) return -ENODEV; =20 - drm->chan_nr =3D drm->chan_total =3D args.v.channels.data; - drm->runl_nr =3D fls64(args.v.runlists.data); + drm->chan_nr =3D drm->chan_total =3D channels->data; + drm->runl_nr =3D fls64(runlists->data); drm->runl =3D kcalloc(drm->runl_nr, sizeof(*drm->runl), GFP_KERNEL); if (!drm->runl) return -ENOMEM; =20 if (drm->chan_nr =3D=3D 0) { for (i =3D 0; i < drm->runl_nr; i++) { - if (!(args.v.runlists.data & BIT(i))) + if (!(runlists->data & BIT(i))) continue; =20 - args.v.channels.mthd =3D NV_DEVICE_HOST_RUNLIST_CHANNELS; - args.v.channels.data =3D i; + channels->mthd =3D NV_DEVICE_HOST_RUNLIST_CHANNELS; + channels->data =3D i; =20 - ret =3D nvif_object_mthd(device, NV_DEVICE_V0_INFO, &args, sizeof(args)= ); - if (ret || args.v.channels.mthd =3D=3D NV_DEVICE_INFO_INVALID) + ret =3D nvif_object_mthd(device, NV_DEVICE_V0_INFO, args, + __struct_size(args)); + if (ret || channels->mthd =3D=3D NV_DEVICE_INFO_INVALID) return -ENODEV; =20 - drm->runl[i].chan_nr =3D args.v.channels.data; + drm->runl[i].chan_nr =3D channels->data; drm->runl[i].chan_id_base =3D drm->chan_total; drm->runl[i].context_base =3D dma_fence_context_alloc(drm->runl[i].chan= _nr); =20 --=20 2.43.0