From patchwork Thu Jun 27 14:44:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13714512 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 4312EC30653 for ; Thu, 27 Jun 2024 14:46:00 +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=dO9vc3WlwnOOdxIv2wYOfRp/f4HDsDDrITVn2Ghy1d0=; b=nSGD5rhKLfJSaWh0FWdHXsrNme WiEBqz6SFWvDG054jpEj2gm1gZtoUjD6tzfzSRSFpyMwzDo9p5iJILKMtEujyU10Ulqnhhae+Yw1I oHsZeGYk50tfkeC7A+YEUODrXLMB0MJKB2s6O5+gNfVq07yW+6TT21HgXT1S4Tu7ebCfIwdJn8SIh hPf2TgwbAXRhyaijRPQd3DGb4FifQR1zNDgrYDGPRTlFb8TcAnLiErI5knHYmBFcO9XZpnaRJTxBL o+NRCvtPEh1k+qtasB2sxyDG1X/RaPvCIsEQU5pIfjV956LYEuwbCTCF5OAKHqk7TY9UQEgA9x5IC VnpTHfJw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMqNh-0000000AgqG-3EQr; Thu, 27 Jun 2024 14:45:49 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMqMo-0000000AgLv-2xgS for linux-arm-kernel@lists.infradead.org; Thu, 27 Jun 2024 14:44:59 +0000 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2ec17eb4493so110592641fa.2 for ; Thu, 27 Jun 2024 07:44:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719499489; x=1720104289; 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=dO9vc3WlwnOOdxIv2wYOfRp/f4HDsDDrITVn2Ghy1d0=; b=jHVqHuhoDJ6iRhPTFn2Lzr3OfPodUF4HPgYwnJXb4UB7pOKRkeBtOH66e6c5/azo3B 2+8ZlsFIT8c9Oeu6K0fQ/4q65OYM2W7WUeRnN8fOx6yj/RCf/DNhI7OliN1OaVlACIMV qLRAJZ2b82HMeru5bLlcIVLOZD4EUvISZRUpWd4c4LtfyrZSD7s/HsfFki63t1MTXMTy WplOJOfxuaE1ecbi0cntYUKBirVlm/Yk6YaEW9DKWfqo9A2Q8/sifMRDZLBHnuhNVgKT 3kEoKs4JBjct6+Mo1tcO/LvDlY0Sm2TuhDnP8q9UswAjT8H++CQpbGN12e+0QJ95blCI l4qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719499489; x=1720104289; 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=dO9vc3WlwnOOdxIv2wYOfRp/f4HDsDDrITVn2Ghy1d0=; b=D7We9P4Y66jBCQ4GQBcKcei9KIupfiK+jeY/PkZmkJil5cPj9L9/8hg5w20Nm69rXg ROIB8cvIcANqZXCaQbk+GPMOGzmQCmzUBK+AwdcszRpEZ+N7+rEcK14insfG+IBFtuQ6 apyudWkzezKTHHtcQ9jrsT2b8XhtSQszWRTS+U9T8885yyLjZk+bgVcO6DSiIWha2Vke HJxk6xHaB2MyEPU62tiwejIEVYQXo1m4Zynxh7ipDAUeQTH0Wrz6sA9fhPld+hbqq0UM b1dLt3I4NvjgQkC+3DvkhLFCMZ/HjSZR4V5cOS6Bb7mbADxlnN3+JhQ6HVwgsd7KCVzb AcLA== X-Forwarded-Encrypted: i=1; AJvYcCXTRSh9rHY8AWTlcSheQDEvY42iEvkpnQ4+tvIxiA7/G4w6/yAs6DjaFxyfCC9Ow5bBY/+CGVergGZ8ELbWH5k9HSH1A3eOxmqeb1oUmaehDYdi2t8= X-Gm-Message-State: AOJu0YwdSQFs/+EdHy9hWU2O/Zg8VgbPJm2usfVciOv42QKzWBq+QjtE O+rRqCYUw4mRJioC1eqbgf8VgcxZr0PC2afkwExXrZb7I2u9J16K5r75PlJrpJ8= X-Google-Smtp-Source: AGHT+IH7syasty7HaTDsD5E51KorF8XfnrmM9ehc/fLT067hmE63RvbKOsoAR+lMidxzL11uJ8ieFA== X-Received: by 2002:a2e:a5cb:0:b0:2ee:4a67:3d82 with SMTP id 38308e7fff4ca-2ee4a673edcmr21435651fa.28.1719499489631; Thu, 27 Jun 2024 07:44:49 -0700 (PDT) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ee4a34447fsm2775911fa.11.2024.06.27.07.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 07:44:49 -0700 (PDT) From: Dmitry Baryshkov Date: Thu, 27 Jun 2024 17:44:46 +0300 Subject: [PATCH v4 7/7] usb: typec: ucsi: reorder operations in ucsi_run_command() MIME-Version: 1.0 Message-Id: <20240627-ucsi-rework-interface-v4-7-289ddc6874c7@linaro.org> References: <20240627-ucsi-rework-interface-v4-0-289ddc6874c7@linaro.org> In-Reply-To: <20240627-ucsi-rework-interface-v4-0-289ddc6874c7@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=2214; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=8t+rc0a05n9eyrWDZO2kMieJ1aEfnXGXWDcAD9GfTds=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBmfXratpXe2Md2H7XXIFiFlNCnAymp1cbi5Lu3s qKILWjJemOJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZn162gAKCRCLPIo+Aiko 1Vy9CACQ+eAL9dx+gexu83BB5XxVSv6Vuxl4xliWjn7OFQ5qhxpaKRh9ucFB2OfRdDoDeIVc18T MoqzXZJWA2gqYP1kStZ4QPCA6+0iw8+2UHZd9AsQKWvzcrmtuwKzwy1V462QBHKrujuB1iw/5CR T/5lE2vCu/gucwCPeeSYreoIpc6c27v32N8foNt1wKRy2iNpl5mhJloJqi00fHLWHDVVYTwzdV1 5RKDglkwuPy7nsSYxwg/s/2tRnL8pyw70IotCuYqMpoix5oGImSWc8bxTX73YyyXJ6FCuiDNHPW +4ySKPNRD0Ud8QgBYaG+IbKt41a4Heejgijje2FTFn7iNol4 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-20240627_074454_798001_B9F54600 X-CRM114-Status: GOOD ( 15.57 ) 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. Tested-by: Heikki Krogerus Reviewed-by: Heikki Krogerus 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 25d2ee5ee8bb..dcd3765cc1f5 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, u8 connector_num)