From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Cc: Guenter Roeck <linux@roeck-us.net>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sebastian Reichel <sre@kernel.org>,
Hans de Goede <hdegoede@redhat.com>,
Yueyao Zhu <yueyao.zhu@gmail.com>,
Rui Miguel Silva <rmfrfs@gmail.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Support Opensource <Support.Opensource@diasemi.com>
Subject: Re: [PATCH v4 4/7] typec: tcpm: Add core support for sink side PPS
Date: Tue, 6 Feb 2018 16:53:57 +0200 [thread overview]
Message-ID: <20180206145357.GA25136@kuha.fi.intel.com> (raw)
In-Reply-To: <2E89032DDAA8B9408CB92943514A0337014C1C1538@SW-EX-MBX01.diasemi.com>
On Tue, Feb 06, 2018 at 02:33:08PM +0000, Adam Thomson wrote:
> On 30 January 2018 12:47, Heikki Krogerus wrote:
>
> > > +static int tcpm_pps_set_op_curr(struct tcpm_port *port, u16 op_curr)
> > > +{
> > > + unsigned int target_mw;
> > > + int ret = 0;
> > > +
> > > + mutex_lock(&port->swap_lock);
> > > + mutex_lock(&port->lock);
> > > +
> > > + if (!port->pps_data.active) {
> > > + ret = -EOPNOTSUPP;
> > > + goto port_unlock;
> > > + }
> > > +
> > > + if (port->state != SNK_READY) {
> > > + ret = -EAGAIN;
> > > + goto port_unlock;
> > > + }
> > > +
> > > + if (op_curr > port->pps_data.max_curr) {
> > > + ret = -EINVAL;
> > > + goto port_unlock;
> > > + }
> > > +
> > > + target_mw = (op_curr * port->pps_data.out_volt) / 1000;
> > > + if (target_mw < port->operating_snk_mw) {
> > > + ret = -EINVAL;
> > > + goto port_unlock;
> > > + }
> > > +
> > > + reinit_completion(&port->pps_complete);
> > > + port->pps_data.op_curr = op_curr;
> > > + port->pps_status = 0;
> > > + port->pps_pending = true;
> > > + tcpm_set_state(port, SNK_NEGOTIATE_PPS_CAPABILITIES, 0);
> >
> > Why not just take the swap_lock here..
>
> I believe this would result in deadlock. All of the existing uses of swap_lock
> acquire it first before the port->lock is then acquired (and vice-versa for
> unlock). We don't want the power role to change during this procedure, so we
> hold the swap_lock for the whole process. Have a look at tcpm_dr_set() and
> tcpm_pr_set() as examples of existing usage.
OK. Then I'm fine with this patch as well. FWIW:
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
--
heikki
WARNING: multiple messages have this Message-ID (diff)
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Cc: Guenter Roeck <linux@roeck-us.net>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sebastian Reichel <sre@kernel.org>,
Hans de Goede <hdegoede@redhat.com>,
Yueyao Zhu <yueyao.zhu@gmail.com>,
Rui Miguel Silva <rmfrfs@gmail.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Support Opensource <Support.Opensource@diasemi.com>
Subject: [v4,4/7] typec: tcpm: Add core support for sink side PPS
Date: Tue, 6 Feb 2018 16:53:57 +0200 [thread overview]
Message-ID: <20180206145357.GA25136@kuha.fi.intel.com> (raw)
On Tue, Feb 06, 2018 at 02:33:08PM +0000, Adam Thomson wrote:
> On 30 January 2018 12:47, Heikki Krogerus wrote:
>
> > > +static int tcpm_pps_set_op_curr(struct tcpm_port *port, u16 op_curr)
> > > +{
> > > + unsigned int target_mw;
> > > + int ret = 0;
> > > +
> > > + mutex_lock(&port->swap_lock);
> > > + mutex_lock(&port->lock);
> > > +
> > > + if (!port->pps_data.active) {
> > > + ret = -EOPNOTSUPP;
> > > + goto port_unlock;
> > > + }
> > > +
> > > + if (port->state != SNK_READY) {
> > > + ret = -EAGAIN;
> > > + goto port_unlock;
> > > + }
> > > +
> > > + if (op_curr > port->pps_data.max_curr) {
> > > + ret = -EINVAL;
> > > + goto port_unlock;
> > > + }
> > > +
> > > + target_mw = (op_curr * port->pps_data.out_volt) / 1000;
> > > + if (target_mw < port->operating_snk_mw) {
> > > + ret = -EINVAL;
> > > + goto port_unlock;
> > > + }
> > > +
> > > + reinit_completion(&port->pps_complete);
> > > + port->pps_data.op_curr = op_curr;
> > > + port->pps_status = 0;
> > > + port->pps_pending = true;
> > > + tcpm_set_state(port, SNK_NEGOTIATE_PPS_CAPABILITIES, 0);
> >
> > Why not just take the swap_lock here..
>
> I believe this would result in deadlock. All of the existing uses of swap_lock
> acquire it first before the port->lock is then acquired (and vice-versa for
> unlock). We don't want the power role to change during this procedure, so we
> hold the swap_lock for the whole process. Have a look at tcpm_dr_set() and
> tcpm_pr_set() as examples of existing usage.
OK. Then I'm fine with this patch as well. FWIW:
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
next prev parent reply other threads:[~2018-02-06 14:54 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-02 15:50 [PATCH v4 0/7] typec: tcpm: Add sink side support for PPS Adam Thomson
2018-01-02 15:50 ` Adam Thomson
2018-01-02 15:50 ` [PATCH v4 1/7] typec: tcpm: Add PD Rev 3.0 definitions to PD header Adam Thomson
2018-01-02 15:50 ` Adam Thomson
2018-01-02 15:50 ` [v4,1/7] " Opensource [Adam Thomson]
2018-01-30 12:21 ` [PATCH v4 1/7] " Heikki Krogerus
2018-01-30 12:21 ` [v4,1/7] " Heikki Krogerus
2018-02-06 14:14 ` [PATCH v4 1/7] " Adam Thomson
2018-02-06 14:14 ` [v4,1/7] " Opensource [Adam Thomson]
2018-01-02 15:50 ` [PATCH v4 2/7] typec: tcpm: Add ADO header for Alert message handling Adam Thomson
2018-01-02 15:50 ` Adam Thomson
2018-01-02 15:50 ` [v4,2/7] " Opensource [Adam Thomson]
2018-01-30 12:22 ` [PATCH v4 2/7] " Heikki Krogerus
2018-01-30 12:22 ` [v4,2/7] " Heikki Krogerus
2018-01-02 15:50 ` [PATCH v4 3/7] typec: tcpm: Add SDB header for Status " Adam Thomson
2018-01-02 15:50 ` Adam Thomson
2018-01-02 15:50 ` [v4,3/7] " Opensource [Adam Thomson]
[not found] ` <b11474b10b9a5a7865d38d58a166899a08d08521.1514904982.git.Adam.Thomson.Opensource-WBD+wuPFNBhBDgjK7y7TUQ@public.gmane.org>
2018-01-30 12:22 ` [PATCH v4 3/7] " Heikki Krogerus
2018-01-30 12:22 ` Heikki Krogerus
2018-01-30 12:22 ` [v4,3/7] " Heikki Krogerus
2018-01-02 15:50 ` [PATCH v4 4/7] typec: tcpm: Add core support for sink side PPS Adam Thomson
2018-01-02 15:50 ` Adam Thomson
2018-01-02 15:50 ` [v4,4/7] " Opensource [Adam Thomson]
2018-01-30 12:46 ` [PATCH v4 4/7] " Heikki Krogerus
2018-01-30 12:46 ` [v4,4/7] " Heikki Krogerus
2018-02-06 14:33 ` [PATCH v4 4/7] " Adam Thomson
2018-02-06 14:33 ` [v4,4/7] " Opensource [Adam Thomson]
2018-02-06 14:53 ` Heikki Krogerus [this message]
2018-02-06 14:53 ` Heikki Krogerus
2018-01-02 15:50 ` [PATCH v4 5/7] power: supply: Add 'connected_type' property and supporting code Adam Thomson
2018-01-02 15:50 ` Adam Thomson
2018-01-02 15:50 ` [v4,5/7] " Opensource [Adam Thomson]
2018-01-30 12:54 ` [PATCH v4 5/7] " Heikki Krogerus
2018-01-30 12:54 ` [v4,5/7] " Heikki Krogerus
2018-02-08 21:30 ` [PATCH v4 5/7] " Sebastian Reichel
2018-02-08 21:30 ` [v4,5/7] " Sebastian Reichel
2018-02-09 11:28 ` [PATCH v4 5/7] " Adam Thomson
2018-02-09 11:28 ` [v4,5/7] " Opensource [Adam Thomson]
2018-02-09 15:01 ` [PATCH v4 5/7] " Sebastian Reichel
2018-02-09 15:01 ` [v4,5/7] " Sebastian Reichel
2018-02-09 15:43 ` [PATCH v4 5/7] " Adam Thomson
2018-02-09 15:43 ` [v4,5/7] " Opensource [Adam Thomson]
2018-01-02 15:50 ` [PATCH v4 6/7] typec: tcpm: Represent source supply through power_supply class Adam Thomson
2018-01-02 15:50 ` Adam Thomson
2018-01-02 15:50 ` [v4,6/7] " Opensource [Adam Thomson]
2018-01-30 13:11 ` [PATCH v4 6/7] " Heikki Krogerus
2018-01-30 13:11 ` [v4,6/7] " Heikki Krogerus
2018-02-06 15:51 ` [PATCH v4 6/7] " Adam Thomson
2018-02-06 15:51 ` [v4,6/7] " Opensource [Adam Thomson]
2018-02-08 10:45 ` [PATCH v4 6/7] " Heikki Krogerus
2018-02-08 10:45 ` [v4,6/7] " Heikki Krogerus
2018-02-09 16:06 ` [PATCH v4 6/7] " Adam Thomson
2018-02-09 16:06 ` [v4,6/7] " Opensource [Adam Thomson]
2018-01-02 15:50 ` [PATCH v4 7/7] typec: tcpm: Add support for sink PPS related messages Adam Thomson
2018-01-02 15:50 ` Adam Thomson
2018-01-02 15:50 ` [v4,7/7] " Opensource [Adam Thomson]
2018-01-30 13:18 ` [PATCH v4 7/7] " Heikki Krogerus
2018-01-30 13:18 ` [v4,7/7] " Heikki Krogerus
[not found] ` <cover.1514904982.git.Adam.Thomson.Opensource-WBD+wuPFNBhBDgjK7y7TUQ@public.gmane.org>
2018-01-22 14:31 ` [PATCH v4 0/7] typec: tcpm: Add sink side support for PPS Greg Kroah-Hartman
2018-01-22 14:31 ` Greg Kroah-Hartman
2018-01-22 15:57 ` Guenter Roeck
2018-01-30 13:25 ` Heikki Krogerus
2018-01-30 14:27 ` Guenter Roeck
2018-02-05 10:30 ` Adam Thomson
2018-03-09 17:33 ` Greg Kroah-Hartman
2018-03-12 8:32 ` Adam Thomson
2018-03-19 10:39 ` Adam Thomson
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=20180206145357.GA25136@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=Adam.Thomson.Opensource@diasemi.com \
--cc=Support.Opensource@diasemi.com \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=rmfrfs@gmail.com \
--cc=sre@kernel.org \
--cc=yueyao.zhu@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.