Skip to contentSkip to conversation

device: call nvkm_device_fini if nvkm_device_init fails

PATCH In review Alexandre Courbot 4 participants 7 messages Jan 25, 2016 – Jan 28, 2016 5 messages not in the archive Tegra architecture support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 device: call nvkm_device_fini if nvkm_device_init fails

nvkm_device_fini is never called if a failure occurs in nvkm_device_init, even when unloading the module. This can lead to a resources leak (one example is the Tegra interrupt which would never be freed in that case). Fix this by calling nvkm_device_fini in nvkm_device_init's failure path.

---
 drm/nouveau/nvkm/engine/device/base.c | 2 ++
 1 file changed, 2 insertions(+)
drm/nouveau/nvkm/engine/device/base.c +2 -0
index b1ba1c782a2b..8ef0ae854038 100644
@@ -2261,6 +2261,8 @@ fail_subdev:
 	} while (--i >= 0);
 
 fail:
+	nvkm_device_fini(device, false);
+
 	nvdev_error(device, "init failed with %d\n", ret);
 	return ret;
 }
Signature · 6 lines
2.7.0

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
#2 lore raw

PATCH 1/1 device/tegra: fix uninitialized IRQ number

In reply to a message not in the archive

nvkm_device_tegra_new initializes the irq member of the Tegra device to -1 in order to signal that it is uninitialized. However, nvkm_device_tegra_fini tests it against 0 to check whether an IRQ has been allocated or not. This leads to free_irq being called on -1 during device initialization.

---
 drm/nouveau/nvkm/engine/device/tegra.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drm/nouveau/nvkm/engine/device/tegra.c +2 -2
index 7f8a42721eb2..0a22439fd9ae 100644
@@ -195,9 +195,9 @@ static void
 nvkm_device_tegra_fini(struct nvkm_device *device, bool suspend)
 {
 	struct nvkm_device_tegra *tdev = nvkm_device_tegra(device);
-	if (tdev->irq) {
+	if (tdev->irq != -1) {
 		free_irq(tdev->irq, tdev);
-		tdev->irq = 0;
+		tdev->irq = -1;
 	};
 }
 
Signature · 6 lines
2.7.0

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
#9 lore raw
In reply to a message not in the archive

Should these get back-ported to any released kernels?

Quoted 27 lines · Alexandre Courbot

nvkm_device_fini is never called if a failure occurs in nvkm_device_init, even when unloading the module. This can lead to a resources leak (one example is the Tegra interrupt which would never be freed in that case). Fix this by calling nvkm_device_fini in nvkm_device_init's failure path.

---
 drm/nouveau/nvkm/engine/device/base.c | 2 ++
 1 file changed, 2 insertions(+)
drm/nouveau/nvkm/engine/device/base.c +2 -1
index b1ba1c782a2b..8ef0ae854038 100644
@@ -2261,6 +2261,8 @@ fail_subdev:
        } while (--i >= 0);
 
 fail:
+       nvkm_device_fini(device, false);
+
        nvdev_error(device, "init failed with %d\n", ret);
        return ret;
 }
--

2.7.0

Quoted 4 lines

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#11 lore raw
In reply to a message not in the archive
Quoted 1 line · Ilia Mirkin

Should these get back-ported to any released kernels?

Probably ok not to, I found these while testing the error paths for secure boot.

Quoted 29 lines · Alexandre Courbot
Quoted 27 lines

nvkm_device_fini is never called if a failure occurs in nvkm_device_init, even when unloading the module. This can lead to a resources leak (one example is the Tegra interrupt which would never be freed in that case). Fix this by calling nvkm_device_fini in nvkm_device_init's failure path.

---
 drm/nouveau/nvkm/engine/device/base.c | 2 ++
 1 file changed, 2 insertions(+)
drm/nouveau/nvkm/engine/device/base.c +2 -1
index b1ba1c782a2b..8ef0ae854038 100644
@@ -2261,6 +2261,8 @@ fail_subdev:
        } while (--i >= 0);
 
 fail:
+       nvkm_device_fini(device, false);
+
        nvdev_error(device, "init failed with %d\n", ret);
        return ret;
 }
--

2.7.0

Quoted 8 lines
Quoted 4 lines

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#4 lore raw

Re: [PATCH] device/tegra: fix uninitialized IRQ number

In reply to a message not in the archive

Am Montag, den 25.01.2016, 18:44 +0900 schrieb Alexandre Courbot:

Quoted 7 lines

nvkm_device_tegra_new initializes the irq member of the Tegra device to -1 in order to signal that it is uninitialized. However, nvkm_device_tegra_fini tests it against 0 to check whether an IRQ has been allocated or not. This leads to free_irq being called on -1 during
device initialization.

The convention in other parts of the Linux kernel is that IRQ number 0 means unallocated/invalid IRQ. So I think it is the initialization to -1 that should be fixed instead.

Quoted 21 lines

---
 drm/nouveau/nvkm/engine/device/tegra.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drm/nouveau/nvkm/engine/device/tegra.c +2 -2
index 7f8a42721eb2..0a22439fd9ae 100644
@@ -195,9 +195,9 @@ static void
  nvkm_device_tegra_fini(struct nvkm_device *device, bool suspend)
  {
  	struct nvkm_device_tegra *tdev = nvkm_device_tegra(device);
-	if (tdev->irq) {
+	if (tdev->irq != -1) {
  		free_irq(tdev->irq, tdev);
-		tdev->irq = 0;
+		tdev->irq = -1;
  	};
  }
Quoted 1 line

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#6 lore raw

Re: [PATCH] device/tegra: fix uninitialized IRQ number

In reply to a message not in the archive
Quoted 11 lines · Lucas Stach

Am Montag, den 25.01.2016, 18:44 +0900 schrieb Alexandre Courbot:

Quoted 7 lines

nvkm_device_tegra_new initializes the irq member of the Tegra device to -1 in order to signal that it is uninitialized. However, nvkm_device_tegra_fini tests it against 0 to check whether an IRQ has been allocated or not. This leads to free_irq being called on -1 during
device initialization.

The convention in other parts of the Linux kernel is that IRQ number 0 means unallocated/invalid IRQ. So I think it is the initialization to -1 that should be fixed instead.

Uh, that sounds unsafe. Thanks for spotting this, will resend.
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#8 lore raw

PATCH v2 1/1 device/tegra: fix uninitialized IRQ number

In reply to a message not in the archive

nvkm_device_tegra_new initializes the irq member of the Tegra device to -1 in order to signal that it is uninitialized. However, nvkm_device_tegra_fini tests it against 0 to check whether an IRQ has been allocated or not. This leads to free_irq being called on -1 during device initialization.

Fix this by using 0 as the uninitialized value everywhere.

---
v2: use 0 as the uninitialized value, as suggested by Lucas.

 drm/nouveau/nvkm/engine/device/tegra.c | 1 -
 1 file changed, 1 deletion(-)
drm/nouveau/nvkm/engine/device/tegra.c +0 -1
index 7f8a42721eb2..6d89416f0bc1 100644
@@ -255,7 +255,6 @@ nvkm_device_tegra_new(const struct nvkm_device_tegra_func *func,
 	*pdevice = &tdev->device;
 	tdev->func = func;
 	tdev->pdev = pdev;
-	tdev->irq = -1;
 
 	tdev->vdd = devm_regulator_get(&pdev->dev, "vdd");
 	if (IS_ERR(tdev->vdd))
Signature · 6 lines
2.7.0

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau