diff mbox series

[2/3] drm/msm/dp: Shrink locking area of dp_aux_transfer()

Message ID 20210507212505.1224111-3-swboyd@chromium.org
State Accepted
Commit 47327fdd7e85ed4a90b76c2fcf69967f98230935
Headers show
Series drm/msm/dp: Simplify aux code | expand

Commit Message

Stephen Boyd May 7, 2021, 9:25 p.m. UTC
We don't need to hold the lock to inspect the message we're going to
transfer, and we don't need to clear the busy flag either. Take the lock
later and bail out earlier if conditions aren't met.

Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: Abhinav Kumar <abhinavk@codeaurora.org>
Cc: Kuogee Hsieh <khsieh@codeaurora.org>
Cc: aravindh@codeaurora.org
Cc: Sean Paul <sean@poorly.run>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 drivers/gpu/drm/msm/dp/dp_aux.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

Comments

Kuogee Hsieh May 24, 2021, 4:22 p.m. UTC | #1
On 2021-05-07 14:25, Stephen Boyd wrote:
> We don't need to hold the lock to inspect the message we're going to
> transfer, and we don't need to clear the busy flag either. Take the 
> lock
> later and bail out earlier if conditions aren't met.
> 
> Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> Cc: Abhinav Kumar <abhinavk@codeaurora.org>
> Cc: Kuogee Hsieh <khsieh@codeaurora.org>
> Cc: aravindh@codeaurora.org
> Cc: Sean Paul <sean@poorly.run>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>

Reviewed-by: Kuogee Hsieh <khsieh@codeaurora.org>
> ---
>  drivers/gpu/drm/msm/dp/dp_aux.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/msm/dp/dp_aux.c 
> b/drivers/gpu/drm/msm/dp/dp_aux.c
> index 91188466cece..b49810396513 100644
> --- a/drivers/gpu/drm/msm/dp/dp_aux.c
> +++ b/drivers/gpu/drm/msm/dp/dp_aux.c
> @@ -329,30 +329,29 @@ static ssize_t dp_aux_transfer(struct drm_dp_aux 
> *dp_aux,
>  	ssize_t ret;
>  	int const aux_cmd_native_max = 16;
>  	int const aux_cmd_i2c_max = 128;
> -	struct dp_aux_private *aux = container_of(dp_aux,
> -		struct dp_aux_private, dp_aux);
> +	struct dp_aux_private *aux;
> 
> -	mutex_lock(&aux->mutex);
> +	aux = container_of(dp_aux, struct dp_aux_private, dp_aux);
> 
>  	aux->native = msg->request & (DP_AUX_NATIVE_WRITE & 
> DP_AUX_NATIVE_READ);
> 
>  	/* Ignore address only message */
> -	if ((msg->size == 0) || (msg->buffer == NULL)) {
> +	if (msg->size == 0 || !msg->buffer) {
>  		msg->reply = aux->native ?
>  			DP_AUX_NATIVE_REPLY_ACK : DP_AUX_I2C_REPLY_ACK;
> -		ret = msg->size;
> -		goto unlock_exit;
> +		return msg->size;
>  	}
> 
>  	/* msg sanity check */
> -	if ((aux->native && (msg->size > aux_cmd_native_max)) ||
> -		(msg->size > aux_cmd_i2c_max)) {
> +	if ((aux->native && msg->size > aux_cmd_native_max) ||
> +	    msg->size > aux_cmd_i2c_max) {
>  		DRM_ERROR("%s: invalid msg: size(%zu), request(%x)\n",
>  			__func__, msg->size, msg->request);
> -		ret = -EINVAL;
> -		goto unlock_exit;
> +		return -EINVAL;
>  	}
> 
> +	mutex_lock(&aux->mutex);
> +
>  	dp_aux_update_offset_and_segment(aux, msg);
>  	dp_aux_transfer_helper(aux, msg, true);
diff mbox series

Patch

diff --git a/drivers/gpu/drm/msm/dp/dp_aux.c b/drivers/gpu/drm/msm/dp/dp_aux.c
index 91188466cece..b49810396513 100644
--- a/drivers/gpu/drm/msm/dp/dp_aux.c
+++ b/drivers/gpu/drm/msm/dp/dp_aux.c
@@ -329,30 +329,29 @@  static ssize_t dp_aux_transfer(struct drm_dp_aux *dp_aux,
 	ssize_t ret;
 	int const aux_cmd_native_max = 16;
 	int const aux_cmd_i2c_max = 128;
-	struct dp_aux_private *aux = container_of(dp_aux,
-		struct dp_aux_private, dp_aux);
+	struct dp_aux_private *aux;
 
-	mutex_lock(&aux->mutex);
+	aux = container_of(dp_aux, struct dp_aux_private, dp_aux);
 
 	aux->native = msg->request & (DP_AUX_NATIVE_WRITE & DP_AUX_NATIVE_READ);
 
 	/* Ignore address only message */
-	if ((msg->size == 0) || (msg->buffer == NULL)) {
+	if (msg->size == 0 || !msg->buffer) {
 		msg->reply = aux->native ?
 			DP_AUX_NATIVE_REPLY_ACK : DP_AUX_I2C_REPLY_ACK;
-		ret = msg->size;
-		goto unlock_exit;
+		return msg->size;
 	}
 
 	/* msg sanity check */
-	if ((aux->native && (msg->size > aux_cmd_native_max)) ||
-		(msg->size > aux_cmd_i2c_max)) {
+	if ((aux->native && msg->size > aux_cmd_native_max) ||
+	    msg->size > aux_cmd_i2c_max) {
 		DRM_ERROR("%s: invalid msg: size(%zu), request(%x)\n",
 			__func__, msg->size, msg->request);
-		ret = -EINVAL;
-		goto unlock_exit;
+		return -EINVAL;
 	}
 
+	mutex_lock(&aux->mutex);
+
 	dp_aux_update_offset_and_segment(aux, msg);
 	dp_aux_transfer_helper(aux, msg, true);