From: "Danilo Krummrich" <dakr@kernel.org>
To: <sashiko-bot@kernel.org>
Cc: <sashiko-reviews@lists.linux.dev>,
"Dave Airlie" <airlied@redhat.com>,
"Lyude Paul" <lyude@redhat.com>,
"Alexandre Courbot" <acourbot@nvidia.com>,
<dri-devel@lists.freedesktop.org>, <nova-gpu@lists.linux.dev>
Subject: Re: [PATCH v2 1/3] drm/nouveau/nvkm: fix device leak on ctor failure
Date: Mon, 23 Nov 2026 14:47:24 +0100 [thread overview]
Message-ID: <DN2MY0QDBWUK.2F9NT145RIG9B@kernel.org> (raw)
In-Reply-To: <sashiko-outbox-228586@kernel.org>
On Mon Nov 23, 2026 at 4:14 AM CET, sashiko-bot wrote:
>> diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/base.c b/drivers/gpu/drm/nouveau/nvkm/engine/device/base.c
>> index a2ed8c4fe52a0..625bb019736af 100644
>> --- a/drivers/gpu/drm/nouveau/nvkm/engine/device/base.c
>> +++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/base.c
>> @@ -3152,10 +3152,19 @@ nvkm_device_ctor(const struct nvkm_device_func *func,
>> unsigned chipset;
>>
>> mutex_lock(&nv_devices_mutex);
>> +
>> + /* Set up the state that nvkm_device_del() relies on before anything
>> + * that can fail, so that a device whose construction failed can be
>> + * cleaned up by the caller with nvkm_device_del().
>> + */
>> + device->func = func;
>> + INIT_LIST_HEAD(&device->head);
>> + INIT_LIST_HEAD(&device->subdev);
>> + nvkm_intr_ctor(device);
>> +
>> if (nvkm_device_find_locked(handle))
>> goto done;
>>
>> - device->func = func;
>> device->quirk = quirk;
>> device->dev = dev;
>
> [Severity: Medium]
> Should device->dev = dev also be set before nvkm_device_find_locked()?
>
> If nvkm_device_find_locked() returns an existing device on Tegra,
> nvkm_device_tegra_new() now calls nvkm_device_del(), which runs
> nvkm_device_tegra_dtor() -> nvkm_device_tegra_remove_iommu():
>
> drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c:nvkm_device_tegra_remove_iommu() {
> if (tdev->iommu.domain) {
> nvkm_mm_fini(&tdev->iommu.mm);
> iommu_detach_device(tdev->iommu.domain, tdev->device.dev);
> iommu_domain_free(tdev->iommu.domain);
> }
> }
>
> Because nvkm_device_tegra_probe_iommu() has already attached
> tdev->iommu.domain before calling nvkm_device_ctor(), leaving
> tdev->device.dev as NULL causes a NULL pointer dereference inside
> iommu_detach_device().
I think Sashiko is right about this, but having an API contract that relies on a
struct being partially initialized on failure isn't great at all.
I think nvkm_device_tegra_remove_iommu() should just not rely on struct
nvkm_device being initialized. struct nvkm_device_tegra already stores struct
platform_device, so I think we can just use &tdev->pdev.dev in
nvkm_device_tegra_remove_iommu().
More generally, can't we keep the semantics of nvkm_device_ctor() to clean up
after itself and not guarantee partial initialization to reuse
nvkm_device_del()?
next prev parent reply other threads:[~2026-11-23 13:47 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 2:50 [PATCH v2 0/3] nova/nouveau: add configs/module options to control binding behaviour (v2) Dave Airlie
2026-11-23 2:50 ` Dave Airlie via B4 Relay
2026-11-23 2:50 ` [PATCH v2 1/3] drm/nouveau/nvkm: fix device leak on ctor failure Dave Airlie
2026-11-23 2:50 ` Dave Airlie via B4 Relay
2026-11-23 3:14 ` sashiko-bot
2026-11-23 13:47 ` Danilo Krummrich [this message]
2026-11-23 2:50 ` [PATCH v2 2/3] drm/nouveau: add option to leave GSP-capable GPUs to other drivers Dave Airlie
2026-11-23 2:50 ` Dave Airlie via B4 Relay
2026-11-23 2:58 ` sashiko-bot
2026-11-23 17:31 ` Timur Tabi
2026-11-23 21:11 ` David Airlie
2026-11-23 21:11 ` David Airlie
2026-11-23 21:14 ` Danilo Krummrich
2026-11-23 21:14 ` Danilo Krummrich
2026-11-23 22:47 ` John Hubbard
2026-11-23 22:47 ` John Hubbard
2026-11-23 21:16 ` Timur Tabi
2026-11-23 21:16 ` Timur Tabi
2026-11-23 22:58 ` John Hubbard
2026-11-23 2:50 ` [PATCH v2 3/3] nova-core: only bind to GPUs when explicitly requested Dave Airlie
2026-11-23 2:50 ` Dave Airlie via B4 Relay
2026-11-23 2:55 ` sashiko-bot
2026-11-23 15:18 ` Danilo Krummrich
2026-11-23 15:18 ` Danilo Krummrich
2026-11-23 16:53 ` Danilo Krummrich
2026-11-23 16:53 ` Danilo Krummrich
2026-11-24 1:53 ` Dave Airlie
2026-11-24 11:55 ` Danilo Krummrich
2026-11-24 11:55 ` Danilo Krummrich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DN2MY0QDBWUK.2F9NT145RIG9B@kernel.org \
--to=dakr@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@redhat.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=lyude@redhat.com \
--cc=nova-gpu@lists.linux.dev \
--cc=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.