Skip to contentSkip to conversation

Don't test for NULL firmware before releasing

PATCH In review Jesper Juhl 3 participants 3 messages Feb 16, 2023 – Feb 17, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Don't test for NULL firmware before releasing

From 4fe34831e2e7677b1c9616356f0a2e0a36ec092f Mon Sep 17 00:00:00 2001
From: Jesper Juhl <[email protected]>
Date: Thu, 16 Feb 2023 02:33:05 +0100
Subject: [PATCH] Don't test for NULL firmware before releasing

release_firmware() tests for a NULL pointer itself, no need to do it up-front.

---
 drivers/gpu/drm/tegra/falcon.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/tegra/falcon.c +1 -2
index c0d85463eb1a..ae599441f031 100644
@@ -153,8 +153,7 @@ int falcon_init(struct falcon *falcon)
 
 void falcon_exit(struct falcon *falcon)
 {
-	if (falcon->firmware.firmware)
-		release_firmware(falcon->firmware.firmware);
+       	release_firmware(falcon->firmware.firmware);
 }
 
 int falcon_boot(struct falcon *falcon)
Signature · 1 line
2.39.2
#1 lore raw

Hi

Quoted 18 lines · Jesper Juhl

From 4fe34831e2e7677b1c9616356f0a2e0a36ec092f Mon Sep 17 00:00:00 2001
From: Jesper Juhl <[email protected]>
Date: Thu, 16 Feb 2023 02:33:05 +0100
Subject: [PATCH] Don't test for NULL firmware before releasing

release_firmware() tests for a NULL pointer itself, no need to do it up-front.

---
 drivers/gpu/drm/tegra/falcon.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/tegra/falcon.c +0 -0
index c0d85463eb1a..ae599441f031 100644

drivers/gpu/drm/tegra/falcon.c int falcon_init(struct falcon *falcon) · line 156

Quoted 6 lines
drivers/gpu/drm/tegra/falcon.c +1 -2
@@ -153,8 +153,7 @@ int falcon_init(struct falcon *falcon)
 
 void falcon_exit(struct falcon *falcon)
 {
-	if (falcon->firmware.firmware)
-		release_firmware(falcon->firmware.firmware);
+       	release_firmware(falcon->firmware.firmware);

Please check patches with checkpatch.pl before posting.

Regards
Stanislaw

#2 lore raw
Quoted 30 lines · Stanislaw Gruszka

Hi

Quoted 18 lines · Jesper Juhl

From 4fe34831e2e7677b1c9616356f0a2e0a36ec092f Mon Sep 17 00:00:00 2001
From: Jesper Juhl <[email protected]>
Date: Thu, 16 Feb 2023 02:33:05 +0100
Subject: [PATCH] Don't test for NULL firmware before releasing

release_firmware() tests for a NULL pointer itself, no need to do it up-front.

---
  drivers/gpu/drm/tegra/falcon.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/tegra/falcon.c +0 -0
index c0d85463eb1a..ae599441f031 100644

drivers/gpu/drm/tegra/falcon.c int falcon_init(struct falcon *falcon) · line 156

Quoted 6 lines
drivers/gpu/drm/tegra/falcon.c +1 -2
@@ -153,8 +153,7 @@ int falcon_init(struct falcon *falcon)
 
  void falcon_exit(struct falcon *falcon)
  {
-	if (falcon->firmware.firmware)
-		release_firmware(falcon->firmware.firmware);
+       	release_firmware(falcon->firmware.firmware);

Please check patches with checkpatch.pl before posting.

Quoted 3 lines

Regards
Stanislaw

Aside the formatting deficiencies, I'm also not in favor of relying on NULL checks inside callees since doing so removes contextual information from the programmer; just looking at the code, it is easy to assume the pointer cannot be NULL if there is no NULL check. Recently had a longer thread about this in the context of kfree in TegraDRM.

Thanks
Mikko