diff mbox

[1/2] drm/i915: Fix memory leak in intel_hdcp auth

Message ID 20180404000456.1407-1-radhakrishna.sripada@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sripada, Radhakrishna April 4, 2018, 12:04 a.m. UTC
Static code analysis tool reported memory leak in
intel_hdcp_auth_downstream. Fixing the memory leak.

Cc: Anusha Srivatsa <anusha.srivatsa@intel.com>
Signed-off-by: Radhakrishna Sripada <radhakrishna.sripada@intel.com>
---
 drivers/gpu/drm/i915/intel_hdcp.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

Comments

Jani Nikula April 4, 2018, 12:04 p.m. UTC | #1
On Tue, 03 Apr 2018, Radhakrishna Sripada <radhakrishna.sripada@intel.com> wrote:
> Static code analysis tool reported memory leak in
> intel_hdcp_auth_downstream. Fixing the memory leak.
>
> Cc: Anusha Srivatsa <anusha.srivatsa@intel.com>
> Signed-off-by: Radhakrishna Sripada <radhakrishna.sripada@intel.com>
> ---
>  drivers/gpu/drm/i915/intel_hdcp.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_hdcp.c b/drivers/gpu/drm/i915/intel_hdcp.c
> index 14ca5d3057a7..ce771f6c1a5a 100644
> --- a/drivers/gpu/drm/i915/intel_hdcp.c
> +++ b/drivers/gpu/drm/i915/intel_hdcp.c
> @@ -186,14 +186,18 @@ int intel_hdcp_auth_downstream(struct intel_digital_port *intel_dig_port,
>  		return -ENOMEM;
>  
>  	ret = shim->read_ksv_fifo(intel_dig_port, num_downstream, ksv_fifo);
> -	if (ret)
> +	if (ret) {
> +		kfree(ksv_fifo);

Please add an single cleanup label and goto it from all error paths.

BR,
Jani.


>  		return ret;
> +	}
>  
>  	/* Process V' values from the receiver */
>  	for (i = 0; i < DRM_HDCP_V_PRIME_NUM_PARTS; i++) {
>  		ret = shim->read_v_prime_part(intel_dig_port, i, &vprime);
> -		if (ret)
> +		if (ret) {
> +			kfree(ksv_fifo);
>  			return ret;
> +		}
>  		I915_WRITE(HDCP_SHA_V_PRIME(i), vprime);
>  	}
>  
> @@ -222,8 +226,10 @@ int intel_hdcp_auth_downstream(struct intel_digital_port *intel_dig_port,
>  			sha_text |= ksv[j] << ((sizeof(sha_text) - j - 1) * 8);
>  
>  		ret = intel_write_sha_text(dev_priv, sha_text);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			kfree(ksv_fifo);
>  			return ret;
> +		}
>  
>  		/* Programming guide writes this every 64 bytes */
>  		sha_idx += sizeof(sha_text);
> @@ -245,13 +251,18 @@ int intel_hdcp_auth_downstream(struct intel_digital_port *intel_dig_port,
>  			continue;
>  
>  		ret = intel_write_sha_text(dev_priv, sha_text);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			kfree(ksv_fifo);
>  			return ret;
> +		}
> +
>  		sha_leftovers = 0;
>  		sha_text = 0;
>  		sha_idx += sizeof(sha_text);
>  	}
>  
> +	kfree(ksv_fifo);
> +
>  	/*
>  	 * We need to write BINFO/BSTATUS, and M0 now. Depending on how many
>  	 * bytes are leftover from the last ksv, we might be able to fit them
Srivatsa, Anusha April 4, 2018, 11:05 p.m. UTC | #2
Thanks for fixing this.


>-----Original Message-----
>From: Sripada, Radhakrishna
>Sent: Tuesday, April 3, 2018 5:05 PM
>To: intel-gfx@lists.freedesktop.org
>Cc: Sripada, Radhakrishna <radhakrishna.sripada@intel.com>; Srivatsa, Anusha
><anusha.srivatsa@intel.com>
>Subject: [PATCH 1/2] drm/i915: Fix memory leak in intel_hdcp auth
>
>Static code analysis tool reported memory leak in intel_hdcp_auth_downstream.
>Fixing the memory leak.
>
>Cc: Anusha Srivatsa <anusha.srivatsa@intel.com>
>Signed-off-by: Radhakrishna Sripada <radhakrishna.sripada@intel.com>
Reviewed-by: Anusha Srivatsa <anusha.srivatsa@intel.com>
>---
> drivers/gpu/drm/i915/intel_hdcp.c | 19 +++++++++++++++----
> 1 file changed, 15 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/gpu/drm/i915/intel_hdcp.c
>b/drivers/gpu/drm/i915/intel_hdcp.c
>index 14ca5d3057a7..ce771f6c1a5a 100644
>--- a/drivers/gpu/drm/i915/intel_hdcp.c
>+++ b/drivers/gpu/drm/i915/intel_hdcp.c
>@@ -186,14 +186,18 @@ int intel_hdcp_auth_downstream(struct
>intel_digital_port *intel_dig_port,
> 		return -ENOMEM;
>
> 	ret = shim->read_ksv_fifo(intel_dig_port, num_downstream, ksv_fifo);
>-	if (ret)
>+	if (ret) {
>+		kfree(ksv_fifo);
> 		return ret;
>+	}
>
> 	/* Process V' values from the receiver */
> 	for (i = 0; i < DRM_HDCP_V_PRIME_NUM_PARTS; i++) {
> 		ret = shim->read_v_prime_part(intel_dig_port, i, &vprime);
>-		if (ret)
>+		if (ret) {
>+			kfree(ksv_fifo);
> 			return ret;
>+		}
> 		I915_WRITE(HDCP_SHA_V_PRIME(i), vprime);
> 	}
>
>@@ -222,8 +226,10 @@ int intel_hdcp_auth_downstream(struct
>intel_digital_port *intel_dig_port,
> 			sha_text |= ksv[j] << ((sizeof(sha_text) - j - 1) * 8);
>
> 		ret = intel_write_sha_text(dev_priv, sha_text);
>-		if (ret < 0)
>+		if (ret < 0) {
>+			kfree(ksv_fifo);
> 			return ret;
>+		}
>
> 		/* Programming guide writes this every 64 bytes */
> 		sha_idx += sizeof(sha_text);
>@@ -245,13 +251,18 @@ int intel_hdcp_auth_downstream(struct
>intel_digital_port *intel_dig_port,
> 			continue;
>
> 		ret = intel_write_sha_text(dev_priv, sha_text);
>-		if (ret < 0)
>+		if (ret < 0) {
>+			kfree(ksv_fifo);
> 			return ret;
>+		}
>+
> 		sha_leftovers = 0;
> 		sha_text = 0;
> 		sha_idx += sizeof(sha_text);
> 	}
>
>+	kfree(ksv_fifo);
>+
> 	/*
> 	 * We need to write BINFO/BSTATUS, and M0 now. Depending on how
>many
> 	 * bytes are leftover from the last ksv, we might be able to fit them
>--
>2.9.3
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_hdcp.c b/drivers/gpu/drm/i915/intel_hdcp.c
index 14ca5d3057a7..ce771f6c1a5a 100644
--- a/drivers/gpu/drm/i915/intel_hdcp.c
+++ b/drivers/gpu/drm/i915/intel_hdcp.c
@@ -186,14 +186,18 @@  int intel_hdcp_auth_downstream(struct intel_digital_port *intel_dig_port,
 		return -ENOMEM;
 
 	ret = shim->read_ksv_fifo(intel_dig_port, num_downstream, ksv_fifo);
-	if (ret)
+	if (ret) {
+		kfree(ksv_fifo);
 		return ret;
+	}
 
 	/* Process V' values from the receiver */
 	for (i = 0; i < DRM_HDCP_V_PRIME_NUM_PARTS; i++) {
 		ret = shim->read_v_prime_part(intel_dig_port, i, &vprime);
-		if (ret)
+		if (ret) {
+			kfree(ksv_fifo);
 			return ret;
+		}
 		I915_WRITE(HDCP_SHA_V_PRIME(i), vprime);
 	}
 
@@ -222,8 +226,10 @@  int intel_hdcp_auth_downstream(struct intel_digital_port *intel_dig_port,
 			sha_text |= ksv[j] << ((sizeof(sha_text) - j - 1) * 8);
 
 		ret = intel_write_sha_text(dev_priv, sha_text);
-		if (ret < 0)
+		if (ret < 0) {
+			kfree(ksv_fifo);
 			return ret;
+		}
 
 		/* Programming guide writes this every 64 bytes */
 		sha_idx += sizeof(sha_text);
@@ -245,13 +251,18 @@  int intel_hdcp_auth_downstream(struct intel_digital_port *intel_dig_port,
 			continue;
 
 		ret = intel_write_sha_text(dev_priv, sha_text);
-		if (ret < 0)
+		if (ret < 0) {
+			kfree(ksv_fifo);
 			return ret;
+		}
+
 		sha_leftovers = 0;
 		sha_text = 0;
 		sha_idx += sizeof(sha_text);
 	}
 
+	kfree(ksv_fifo);
+
 	/*
 	 * We need to write BINFO/BSTATUS, and M0 now. Depending on how many
 	 * bytes are leftover from the last ksv, we might be able to fit them