From patchwork Tue Jun 25 14:54:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13711304 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 C12DCC3064D for ; Tue, 25 Jun 2024 14:55:20 +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=g2gxtQIN+xKJeYZrrZg4eTx3pd8ql0F1T/zN9SBRQsY=; b=DZvMfPOuhBySHy65/0QVfx/AJS QIuiEJxKQ2KXx9pVf1dhATfXFOEkSYUskjsp9evuH7tHU7jOvsyBiN4Dz8RouOJ4NYv3BivohyWEn jCricRdYm9R/DW5TlsVJj2dgs+4eAqAmXpxN8o6TU6I48GApVYXQQSqSzsWgQvb9BdQyX5ISkCBUH k09JPR3XmL1MI2g0IBZvt30qlP/0Q6+IggBqhITqVLqJtGkYDqWRnnU2hC9allstqCW1Lv/jxpnf6 t4HiOHnyqEc8R0uL3FmEJSv9PJj5xc2/zjjbfjRmkkvQsQVvetyWDXhK9kupnvGCE7LdvPJrLWtW4 VNFeiSfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7Ze-00000003HIA-0YZN; Tue, 25 Jun 2024 14:55:10 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM7Z7-00000003Gye-0SYO for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 14:54:38 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-52cf4ca8904so428179e87.3 for ; Tue, 25 Jun 2024 07:54:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719327275; x=1719932075; 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=g2gxtQIN+xKJeYZrrZg4eTx3pd8ql0F1T/zN9SBRQsY=; b=YAXSk1oL28hJWo6yPuw6tTjvmVhwKyB9jtTSWcnveB4GWTh78bDDhL95wdsfziMYjS q+CZHe/lsO+07hB01JeAB0k3ALU3g9F1e4RVfqU+2x2yezBnFsUoLYO13g1ou79dhi5z ak79sp+S7QvpnJ9JSz7sdI0aHzURlnPTPfXj7JL3f/upJXtSlHGyw1ZZSBg2+xoi4wlw I8WFgJ7np4ZNbjllPoF9m8TrYWrgeL6U6VrSitcsunymjT+vSqyGEP3byg6IyxotWsv3 xRnTtWMVdc63GCf13OwbVNZk6Wyk6OesKiMVu8Kxv/8Z+ac3JM4TJ1m6bZm7WZqy51Gq jYKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719327275; x=1719932075; 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=g2gxtQIN+xKJeYZrrZg4eTx3pd8ql0F1T/zN9SBRQsY=; b=fQR6ovHYYuiI9nIFoYB8BviLUZ/U+OS77DnVbSfSFEEjUqM2fpVFEiJrfXJ8MHtjqE sjoRidM/yfTpsFPZXUFSZcBP98P588ZHM3msETWrIhrclAIvHjGAd9y7dirdzme+mo3/ l6SlDpg20LBjA58uY1w6FrW9cH4MuH1ljITrAB8/Pp5vDOLc0oadIS92WfaOrxD2Sc+J WXCpDldms3mSAQqV/zK7VXxalZgxdooouUWAjLafsYQdOWQr1YBXBPLo4ResoHvDvZc2 BCrfwwwbibTmWq2cpTv1NClpcoyB2uPqxWQPjDihFJ3pH4CpwJZEmPNvZX8raHSv5exD VHJA== X-Forwarded-Encrypted: i=1; AJvYcCW7VqpN23Y9SE2l7RoVZhXf45g4kp/VrAbrXUXD2qBn+CF/FMEPVd33X1U+O6fWPjhdtPiwQxu1Nxt+j3Gs7uNqd5sl+94BBiOd4sAmZJXC+4jUROw= X-Gm-Message-State: AOJu0YzVB8hroi/7C9L5S7kUecJqn9PWA9bOGmktD9gz6YShT+4AT0J1 QGEAumbimuC5l+7NXUHa9GOgYBTHQR3hxHDkBfuAkfUhVMXDdel0cJVp8bDuabOzEMtdaKAQGns b5PI= X-Google-Smtp-Source: AGHT+IFgTfwsx7ElY5vsvTSzReP2HLuqQHHg6f+F1C3RO23ndtkGTJu8+wBSZAIAD6eWetNxoUG4Kg== X-Received: by 2002:a05:6512:46f:b0:52c:9f9e:d8e3 with SMTP id 2adb3069b0e04-52ce064e3d8mr4973783e87.31.1719327275739; Tue, 25 Jun 2024 07:54:35 -0700 (PDT) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd64328b7sm1251877e87.221.2024.06.25.07.54.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 07:54:35 -0700 (PDT) From: Dmitry Baryshkov Date: Tue, 25 Jun 2024 17:54:32 +0300 Subject: [PATCH v3 7/7] usb: typec: ucsi: reorder operations in ucsi_run_command() MIME-Version: 1.0 Message-Id: <20240625-ucsi-rework-interface-v3-7-7a6c8e17be3a@linaro.org> References: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@linaro.org> In-Reply-To: <20240625-ucsi-rework-interface-v3-0-7a6c8e17be3a@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=c1mFXRw/1F7jX+PLOZli37YidJtYzYIZwD0eERkZXpg=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBmetokKTBUAvA860F4TZ7LaGT2vn3//h0eO5fRP eXnVpE4f++JATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZnraJAAKCRCLPIo+Aiko 1Y7VCACNYuSM7sEYoqQvGqND2MRdAoZLFky1iBiqT6oimIP7qis1KVCv3F+gBFz/bdKtij+cztp Z5awCnGfW7Httm4zKIIT7NjJpuUDn4ia7oZOW3FAe99Zdq92p1EKUvXKnXApxNz6eom/iOY7qGH ZuClKE5VA15dUN4sl0zW6TTatSGt7zTfkToJ2jq8u83k9ID/maCxlb5V8FISVxuKEqgOJwLGGoE OvAeeooTh9x2NFAt/eeMWZ2D8kgVxeDZw+j5aVfO6x8v8emzAdbZuHaM+qRTH+T7uUXJOiJNXkB 9HVHfVpFVz76fdbmU925vbf0ul+6bFBUI9SNsbusDr5OPJul 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-20240625_075437_295225_AF277A30 X-CRM114-Status: GOOD ( 15.85 ) 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 3fb5d3a52b80..0d091f06abd3 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)