From patchwork Thu Jun 20 22:55:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13706468 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 46225C2BBCA for ; Thu, 20 Jun 2024 22:55:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type: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=IR6olVBcDJAiFqvRlmHubkR26Doy6VX5UC/TUKocw0g=; b=1Iz/JjRi4rjT4tG4KqnTzC6mhg LyaIUN896FQgkdSKcujCI4crVuIQTcGvfOmOV0vdDCZpOh4O5NxfE4pctbo2ncZOiCawgkc/x7/Og zLrsN1H421aNa8I6ft6BnyRo1A7odA1gQKH/SAMzJnOR52k2UwxnQwkSWI0v6Y2l+aFGTbvQC6pxl A1uwzqmLEIF0xIpV6xHM6TtmR+K8ldr2kl69YsAXPD6AZF2g2ZSjBraMz9CtsiFVp075Ju2DVa5W/ QBb+FsmAo1cwDPM1wGSMcVMfARVlCYIx31koXgudIRst1w8Z/tJPTC8K4PCu8u/WXHmftxSRR52a1 TnYWNOXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKQgr-000000070rL-2uZ4; Thu, 20 Jun 2024 22:55:37 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKQgj-000000070kP-3V4Y for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2024 22:55:31 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2e72224c395so14712651fa.3 for ; Thu, 20 Jun 2024 15:55:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718924128; x=1719528928; 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=IR6olVBcDJAiFqvRlmHubkR26Doy6VX5UC/TUKocw0g=; b=aqtsmXW7hunV5cPi7QzEIcJq9t4sf5P5PxiqeLzBlT5xvXCzKrA/aSj2NalWbLHMcT q2QjG9Qg59bR2IzpX9baUeEkG/gR89q/9kMh4SPokxR7Y7qLXx9o0xidhVn9m9EKc9gY y18PmQwG8x4VQjPYW1t95svXXIo1S18o8TCOTBQP3UWwsxs4JGgM+nEtnnir7bh2IcfY iNvJLyp/t54QFZgaGoeFZo/70OF4nCQDzsJiPB66hfrAys4P268CHwd/JfSAznA3et/1 7Jm4Zx5IXycwY0aIveRWx2gTAjzil9Zse+zDCQZ1BUwzfFjjxkGKPTdtfRWaSweHj3mY TdVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718924128; x=1719528928; 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=IR6olVBcDJAiFqvRlmHubkR26Doy6VX5UC/TUKocw0g=; b=SFkS26pvk5poZkLSXHrpKpG2MRTx+1F3eQh2PL53wSa/xpJKYUVgTzQfY5CgORj5b4 lfvSPxfL7H2rkRzVASRuUTU1IaL8rm1ujcYfmxYjYkg5XQwSaESsaruCIZn3VdKLaaiK e+NltkMqysgoivnu6RmkQzfcp3mD7tEaRgQqMfTFCuFm0wWsNX6oYu2zYpzRft9Db+I4 LWwU3PKb8tt7UGQ+P6tR2ZXsSF9pcgYA2ovC8dszX4lo+5wI56Cmi7cyDCGNFqGD48MX MgndpOhs+PVa8/voL5z3/lrLOcDVuG72e8XQlITItBNSIbhqdoKZE47hb5usxwZgx+2X 4BZA== X-Forwarded-Encrypted: i=1; AJvYcCUgIMbjmY0tyNLFRqvQ4futodL4WzPF5tpyEzgOTyDFhirIx+U5Va9RcwEroxWgarCHaJYBK/YLAVcaE70ulxGO/m2j5y/i6EqqUW8UTH6BjdqSXdk= X-Gm-Message-State: AOJu0YyfIJE11lmuverZj1BzuClBoRUkyxXTgb7Vq6UjfBa1tnC6Jq6P ZhJhqTVgvIIhU2ocax9R5ubXUB3nYV6LstjSOFdoIiYa6TXrp0lQN4Zxhv5KnA0= X-Google-Smtp-Source: AGHT+IHoxm/6bBTyOgi+zBFIRiNRkYizZyitnEFBjNxxc70xWD6BEN8Wul1ZDUIcnnkKkMaGcgzZdA== X-Received: by 2002:a05:651c:b26:b0:2ec:4086:ea6d with SMTP id 38308e7fff4ca-2ec4086ec1emr49099931fa.4.1718924127943; Thu, 20 Jun 2024 15:55:27 -0700 (PDT) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ec4d60126fsm510461fa.20.2024.06.20.15.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 15:55:27 -0700 (PDT) From: Dmitry Baryshkov Date: Fri, 21 Jun 2024 01:55:26 +0300 Subject: [PATCH v2 7/7] usb: typec: ucsi: reorder operations in ucsi_run_command() MIME-Version: 1.0 Message-Id: <20240621-ucsi-rework-interface-v2-7-a399ff96bf88@linaro.org> References: <20240621-ucsi-rework-interface-v2-0-a399ff96bf88@linaro.org> In-Reply-To: <20240621-ucsi-rework-interface-v2-0-a399ff96bf88@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=LOWb+Vw9/QmbxNoLHa2MHXOU60Fguix3lqbyVHzGXkk=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBmdLNaauNrup2m6YbsM/7Td6FdrCda5Pnyu6yKM KQfN812DcyJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZnSzWgAKCRCLPIo+Aiko 1WJVCACp9pu/iAzSt7ocCbeRjeF2QNEs+jrrsHD/b2EUMTwZj+CrEmvEUlQDxQXC7zXAd2CyulU 2CHiKhJzIcdW+ivIcX1VN4T+ZHDRrmbijLRu1P6gOHjj+tVsNuagPseUbs7eBe9OE8H3zUTaYYo 8uWyen4Q2yXas5QQ9lh5S2uxKHY2V0U7x3S+6KfUNySztOw7idFWM3qpd90cVLeq0MYDpC7Q0wN SdAXBNRai83HlLbWOV8IcsDtk8dTU+XqBv/pw1L8OveVRH3KmRlMU8fEY05haSv39zYydoJzZZL 9sN9Gt9sVPpd8Uy2e/m9rG9PTHHXSLm+lHzaIslA0nG/PqPf 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-20240620_155530_037816_2547EFC9 X-CRM114-Status: GOOD ( 15.52 ) 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 691ee0c4ef87..02d7f745acad 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)