[PATCH 1/4] drm/i915/opregion: fix leaking fw on error path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Convert the code to return-early style and fix missing calls
to release_firmware() if vbt is not valid.

Signed-off-by: Lucas De Marchi <lucas.demarchi@xxxxxxxxx>
---
 drivers/gpu/drm/i915/display/intel_opregion.c | 28 +++++++++++--------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_opregion.c b/drivers/gpu/drm/i915/display/intel_opregion.c
index 969ade623691..9738511147b1 100644
--- a/drivers/gpu/drm/i915/display/intel_opregion.c
+++ b/drivers/gpu/drm/i915/display/intel_opregion.c
@@ -872,23 +872,29 @@ static int intel_load_vbt_firmware(struct drm_i915_private *dev_priv)
 		return ret;
 	}
 
-	if (intel_bios_is_valid_vbt(fw->data, fw->size)) {
-		opregion->vbt_firmware = kmemdup(fw->data, fw->size, GFP_KERNEL);
-		if (opregion->vbt_firmware) {
-			DRM_DEBUG_KMS("Found valid VBT firmware \"%s\"\n", name);
-			opregion->vbt = opregion->vbt_firmware;
-			opregion->vbt_size = fw->size;
-			ret = 0;
-		} else {
-			ret = -ENOMEM;
-		}
-	} else {
+	if (!intel_bios_is_valid_vbt(fw->data, fw->size)) {
 		DRM_DEBUG_KMS("Invalid VBT firmware \"%s\"\n", name);
 		ret = -EINVAL;
+		goto err_release_fw;
+	}
+
+	opregion->vbt_firmware = kmemdup(fw->data, fw->size, GFP_KERNEL);
+	if (!opregion->vbt_firmware) {
+		ret = -ENOMEM;
+		goto err_release_fw;
 	}
 
+	opregion->vbt = opregion->vbt_firmware;
+	opregion->vbt_size = fw->size;
+
+	DRM_DEBUG_KMS("Found valid VBT firmware \"%s\"\n", name);
+
 	release_firmware(fw);
 
+	return 0;
+
+err_release_fw:
+	release_firmware(fw);
 	return ret;
 }
 
-- 
2.23.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux