]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
usb: typec: ucsi: Call CANCEL from single location
authorHeikki Krogerus <heikki.krogerus@linux.intel.com>
Fri, 16 Aug 2024 13:58:58 +0000 (16:58 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Aug 2024 10:47:39 +0000 (18:47 +0800)
The command cancellation can be done right after detecting
that the PPM is busy. There is no need to do it separately
in ucsi_read_error() and ucsi_send_command_common().

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20240816135859.3499351-6-heikki.krogerus@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/ucsi/ucsi.c

index 2d8ebeac02b832196a1a4479455b2f7feadc2344..8be10a207121292389e6ff4ec459669656374bed 100644 (file)
@@ -111,7 +111,7 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci,
                return ret;
 
        if (*cci & UCSI_CCI_BUSY)
-               return -EBUSY;
+               return ucsi_run_command(ucsi, UCSI_CANCEL, cci, NULL, 0, false) ?: -EBUSY;
 
        if (!(*cci & UCSI_CCI_COMMAND_COMPLETE))
                return -EIO;
@@ -144,15 +144,7 @@ static int ucsi_read_error(struct ucsi *ucsi, u8 connector_num)
        int ret;
 
        command = UCSI_GET_ERROR_STATUS | UCSI_CONNECTOR_NUMBER(connector_num);
-       ret = ucsi_run_command(ucsi, command, &cci,
-                              &error, sizeof(error), false);
-
-       if (cci & UCSI_CCI_BUSY) {
-               ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false);
-
-               return ret ? ret : -EBUSY;
-       }
-
+       ret = ucsi_run_command(ucsi, command, &cci, &error, sizeof(error), false);
        if (ret < 0)
                return ret;
 
@@ -234,9 +226,8 @@ static int ucsi_send_command_common(struct ucsi *ucsi, u64 cmd,
        mutex_lock(&ucsi->ppm_lock);
 
        ret = ucsi_run_command(ucsi, cmd, &cci, data, size, conn_ack);
-       if (cci & UCSI_CCI_BUSY)
-               ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false) ?: -EBUSY;
-       else if (cci & UCSI_CCI_ERROR)
+
+       if (cci & UCSI_CCI_ERROR)
                ret = ucsi_read_error(ucsi, connector_num);
 
        mutex_unlock(&ucsi->ppm_lock);