public inbox for chrome-platform@lists.linux.dev
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Radu Vele <raduvele@google.com>
Cc: Benson Leung <bleung@chromium.org>,
	Abhishek Pandit-Subedi <abhishekpandit@chromium.org>,
	Jameson Thies <jthies@google.com>,
	Andrei Kuchynski <akuchynski@chromium.org>,
	chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/2] platform/chrome: cros_ec_typec: Add lock per-port
Date: Thu, 10 Jul 2025 04:06:35 +0000	[thread overview]
Message-ID: <aG88SyVAdO0txGMi@google.com> (raw)
In-Reply-To: <20250709132232.2475172-2-raduvele@google.com>

On Wed, Jul 09, 2025 at 01:22:32PM +0000, Radu Vele wrote:
> @@ -8,6 +8,7 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/module.h>
> +#include <linux/mutex.h>
>  #include <linux/of.h>
>  #include <linux/platform_data/cros_ec_commands.h>
>  #include <linux/platform_data/cros_usbpd_notify.h>

Please consider to include linux/cleanup.h and use guard() to simplify the
patch.

> @@ -54,8 +55,11 @@ static int cros_typec_enter_usb_mode(struct typec_port *tc_port, enum usb_mode m
>  		.mode_to_enter = CROS_EC_ALTMODE_USB4
>  	};
>  
> -	return cros_ec_cmd(port->typec_data->ec, 0, EC_CMD_TYPEC_CONTROL,
> +	mutex_lock(&port->lock);
> +	int ret = cros_ec_cmd(port->typec_data->ec, 0, EC_CMD_TYPEC_CONTROL,
>  			  &req, sizeof(req), NULL, 0);
> +	mutex_unlock(&port->lock);
> +	return ret;

E.g.:
        guard(mutex)(&port->lock);
        return cros_ec_cmd(...);

>  static int cros_typec_perform_role_swap(struct typec_port *tc_port, int target_role, u8 swap_type)
> @@ -70,6 +74,8 @@ static int cros_typec_perform_role_swap(struct typec_port *tc_port, int target_r
>  	if (!data->pd_ctrl_ver)
>  		return -EOPNOTSUPP;
>  
> +	mutex_lock(&port->lock);

It can drop all the following diff hunks in the function if using:
        guard(mutex)(&port->lock);

> @@ -1232,6 +1248,7 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
>  		return -EINVAL;
>  	}
>  
> +	mutex_lock(&typec->ports[port_num]->lock);

It can drop all the following diff hunks in the function if using:
        guard(mutex)(&typec->ports[port_num]->lock);

  parent reply	other threads:[~2025-07-10  4:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 13:22 [PATCH v1 1/2] platform/chrome: cros_ec_typec: Add role swap ops Radu Vele
2025-07-09 13:22 ` [PATCH v1 2/2] platform/chrome: cros_ec_typec: Add lock per-port Radu Vele
2025-07-09 18:54   ` Benson Leung
2025-07-10  4:06   ` Tzung-Bi Shih [this message]
2025-07-09 18:45 ` [PATCH v1 1/2] platform/chrome: cros_ec_typec: Add role swap ops Benson Leung
2025-07-10  4:06 ` Tzung-Bi Shih

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aG88SyVAdO0txGMi@google.com \
    --to=tzungbi@kernel.org \
    --cc=abhishekpandit@chromium.org \
    --cc=akuchynski@chromium.org \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=jthies@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=raduvele@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox