From patchwork Sun Jun 2 23:25:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13683134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 564EAC27C50 for ; Sun, 2 Jun 2024 23:25:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IZtRESOfT/tTcH3edULUFd5Va9IpeWPWAjpQh+8CDuo=; b=KJ84dYJ9/GcYWv MXBMs085J/uz9S5HxHCBKaObqwmRbOyopFMo5Nrw2eFCsWznfyz6lueJjVwRa/KFu1sKRkXy6Ta/7 ewA9xXXzcjD1yxEz1NGBZDKi+11+0IFIx1re+xHZfSNWB5qwOBlAId4NdCDKdrsyqbnqRlXOZt6EE XtPD7kDs18ywCiAulfVoQLMrPEn9w93bz8UVdj6Ti95eyWoANjxOsYWXtwSzsoQHJcy98PonXy/kL CNWcMo0b1+6lFb2Ox7+kLqnc0h5LVVqCXRCEa3mf4Tpj7eIZFCoHQz4Y343P5jBhKwB8jLgr0wWWg pn+2hEi/HoCrBYt4pQXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sDuZe-0000000F6B7-0l5S; Sun, 02 Jun 2024 23:25:14 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sDuZT-0000000F64f-2YVl for linux-arm-kernel@lists.infradead.org; Sun, 02 Jun 2024 23:25:05 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-52b93370ad0so1654652e87.2 for ; Sun, 02 Jun 2024 16:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717370701; x=1717975501; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=r8Iq+3RgEig8Cx0iz/mpoUKg07pqVjSqpR5cr51J2sg=; b=mp2V1xVRxTqjf9VtzISmVuQ6DvSt+CjVT9Qqf3EnE05V216oaf9QPM0GYLD5OrZiYF bWuiW5SfFnZ0dnORsnXsej8xwaVfCkLb4cnh+OePoOPIudyA7WjA/gQHbL6jhESscPAN n7rGWUoi+c+sw3P5Zupn67+n6nDvSIzJJWmZwzH45i360dL9Co+1YsWK81vIp/k21gfh /WMCT9VH9tslbB1tp1P4lJBa88Ra/hJ6kxjSmsnyyEA4UIjbSyTtrvR6f/Gf+XSLAFkp e6gxRPTF/z9pCo79veR+2KFsBOmG+B/HBzaALkCBimXJOz3BJ3OI9f2GGi6aKWoBTH7h 0LFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717370701; x=1717975501; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r8Iq+3RgEig8Cx0iz/mpoUKg07pqVjSqpR5cr51J2sg=; b=bTDphWNzyNWsP+RPk8nDGpBrxI0m4r2/Ypob9rvZM1tKUpRDcL63swtRkJ3ioEH0E/ BKwj6EKbQKe3tDdNAYGLaxNleVS7KMpzoBXlZ3Jy261NlkYEjc+beA9BbWctSlCAfbiT BOSq3+SznDp4e9OVfLz7fm4SAvbR79uJ1AsQG0oebblNjlte6+XtO0DE8IXIPvZ79WRm rB6C4zLeP0fz4m518fL63K0fk9GHErZZFY9SagKafZ+Uha5guqPJEf3ro7TwavCMVB8U znwERadQyZzgRvwCeazuIHXq06juHwpuQ+M1IQGXvL0jRH/nQuyfToJeol9+IKGPhEE6 /HMg== X-Forwarded-Encrypted: i=1; AJvYcCViETUjNB/R4FZLgIt1/Q1pOG2qKn67L9d7qJ1JB8Y7yrQDIb8StZYalSsXrRZffuQHrakSxFAF7h16H4niXLFoFgwsEn7HOYM/onnXuCfREuUPmds= X-Gm-Message-State: AOJu0Yw66TRcyFFQcdjpOlUdOJz6cG/PC2F/QWK4RhBUShX3OyhmXn8W MXC5rdx0JtxYorYLRyaGdRDfYe2TVf/+Ep9TRTPjuj8n8wqBA79SkYblyk7gD7I= X-Google-Smtp-Source: AGHT+IERXsZJtbptbub4OPpmYt4izzdy6vVE3d9VwxncjVETVSXMGoMmwAAaAqx2FFQoGX/3InI1uA== X-Received: by 2002:ac2:58e7:0:b0:52b:88ba:da88 with SMTP id 2adb3069b0e04-52b8954ea17mr5935410e87.26.1717370701481; Sun, 02 Jun 2024 16:25:01 -0700 (PDT) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52b959008aasm392369e87.269.2024.06.02.16.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jun 2024 16:25:01 -0700 (PDT) From: Dmitry Baryshkov Date: Mon, 03 Jun 2024 02:25:00 +0300 Subject: [PATCH RFC 7/7] usb: typec: ucsi: reorder operations in ucsi_run_command() MIME-Version: 1.0 Message-Id: <20240603-ucsi-rework-interface-v1-7-99a6d544cec8@linaro.org> References: <20240603-ucsi-rework-interface-v1-0-99a6d544cec8@linaro.org> In-Reply-To: <20240603-ucsi-rework-interface-v1-0-99a6d544cec8@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman , Maxime Coquelin , Alexandre Torgue Cc: Nikita Travkin , Neil Armstrong , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2070; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=qwhd20pcT6mKmuOmdJvReDADwvss13IfbnCS0P5O90U=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBmXP9I9UoE+huJlSrwgEUi7zxKYLl7ib9SuXtkX fxqsDm1/vWJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZlz/SAAKCRCLPIo+Aiko 1ZPnB/wJiXKUWKNGHNVrmNmaiYUeTXAzLFk/CckWZubxbjYiTn17Iv99ejxUhjRVFoYE2cwU8lE SxN7gerADf7/9A3HXwgOOU40QkmSFfc+FAo2sjoBUw8Nq7Lisst2c7LvRypbflv6wXu44KyYh+R cq4NC5KGZPlvD1io3PThZep4n5w7OrgFBl2deD0gg14CCl9W6NvMoYWarHh6jGN3G3t9Xez6JjP 8iQ8r/aWZvXmBySF+7nS+Ohc6U0dC6AE4R3VSB8FCKMUUEACMEVU0mQlf4693IcOC0KvJRopr3x KVVbA1SK1EL9fbV1BpZSHlFPziFH+A+NPxqCFOlMsw/GUGwy X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240602_162503_798118_7055512D X-CRM114-Status: GOOD ( 15.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Streamline control stream of ucsi_run_command(). Reorder operations so that there is only one call to ucsi_acknowledge(), making sure that all complete commands are acknowledged. This also makes sure that the command is acknowledged even if reading MESSAGE_IN data returns an error. Signed-off-by: Dmitry Baryshkov --- drivers/usb/typec/ucsi/ucsi.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 4d36a04dc63b..4666dec005a6 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -95,7 +95,7 @@ static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack) static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, void *data, size_t size, bool conn_ack) { - int ret; + int ret, err; *cci = 0; @@ -120,30 +120,24 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, if (!(*cci & UCSI_CCI_COMMAND_COMPLETE)) return -EIO; - if (*cci & UCSI_CCI_NOT_SUPPORTED) { - if (ucsi_acknowledge(ucsi, false) < 0) - dev_err(ucsi->dev, - "ACK of unsupported command failed\n"); - return -EOPNOTSUPP; - } - - if (*cci & UCSI_CCI_ERROR) { - /* Acknowledge the command that failed */ - ret = ucsi_acknowledge(ucsi, false); - return ret ? ret : -EIO; - } + if (*cci & UCSI_CCI_NOT_SUPPORTED) + err = -EOPNOTSUPP; + else if (*cci & UCSI_CCI_ERROR) + err = -EIO; + else + err = 0; - if (data) { - ret = ucsi->ops->read_message_in(ucsi, data, size); - if (ret) - return ret; - } + if (!err && data && UCSI_CCI_LENGTH(*cci)) + err = ucsi->ops->read_message_in(ucsi, data, size); - ret = ucsi_acknowledge(ucsi, conn_ack); + /* + * Don't ACK connection change if there was an error. + */ + ret = ucsi_acknowledge(ucsi, err ? false : conn_ack); if (ret) return ret; - return 0; + return err; } static int ucsi_read_error(struct ucsi *ucsi)