Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp656763lqj; Sun, 2 Jun 2024 16:26:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUpoP9WCD5evysfZbCZn2n3d5LbgV7iwx4+gyIMRFEt9c+JjQ/Kq0RonOK37czimJXVx0silciDYrCQrz8dZ3Cn3gvJ0ox+tn8w05y4nw== X-Google-Smtp-Source: AGHT+IHfVAPJQHC+iyH9uTF4z5I6Ocm7GZifDnJzsByO4D2nyCi9pxRkDT4sTqHhNVRX1BBtI7H6 X-Received: by 2002:a05:6a20:728c:b0:1ad:7bfd:54a1 with SMTP id adf61e73a8af0-1b26f1ba020mr8520346637.17.1717370785733; Sun, 02 Jun 2024 16:26:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717370785; cv=pass; d=google.com; s=arc-20160816; b=raIwUrEZ0doJ4ZqG/a/FW3IgUGmWsZtuUfL5tW7HyujN17CQJfQwqrP6atixais0c5 x21hSP7BuB6S6arrwFHrWy2+4MOnr2tFVU3SNUNX0Pa9Z0yWHae9sJVjcn55lcgo+2bq SOiA6YMwAoUIdBlY4n2kAUlRyCpz5bQuOFoR4DxjPYQ5lGTmqucgm0t2Uk04ScobST9a ZIKBSweUThCoxsylSKyRw5taNeQpt5/illdQT3RRTyla2hSeve09DLppEypPTDmfPGow 2jW6R/NuSvMY3N6rNORZvV5zpH7VY7ouXhMInxrTh09Eobt0bKqORZo1QaSESPeiWaiA 85XA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=r8Iq+3RgEig8Cx0iz/mpoUKg07pqVjSqpR5cr51J2sg=; fh=P7pqkYRNn5ySyZORKButSPHuUjwMOM5mzcQf+abT5kc=; b=FV/Tw53lihaHlY3NjQS/+940Hw5nIBnIz7R2y7ULMKkdx1QBrJizS1830j26PX0Ah2 piaWEaMr5CpIBFtohvCo4InEFmjbUeVpMqlhENS9Q8/2y+qBbxrcYRVwS/HYpokj+I4C pu1gZ+FvzYXwZS/Ugkv2byB/UutmfcO/C5kJ1uXhYYTwoOpzpfGwth4Eb+HLZHGUAmMA W0V5x2Ux3/1L90EK+g/jJ94/Pb2kHoQYGoiGP28I/HcQAH5VHnOTNQ64AWemmY6FSAri NUHeNLspcmOrXY1iJfWbNB8XbyIAde7ejc71m0Keo0PJSSg8bk4O3imO4x3FjWD++NeP bEjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tPAmxdjW; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-198481-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198481-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c35552ba0fsi5433909a12.243.2024.06.02.16.26.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jun 2024 16:26:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198481-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tPAmxdjW; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-198481-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198481-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1AB612817B7 for ; Sun, 2 Jun 2024 23:26:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98A8B839FF; Sun, 2 Jun 2024 23:25:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="tPAmxdjW" Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91626811FE for ; Sun, 2 Jun 2024 23:25:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717370705; cv=none; b=PwsMrJ3msgpRoIPVIzAmmI8rZK2EMuQZwyDoE7WCjgMr+wDcAOWLq9LhB2nEw8zG4CpLUDbyjsUuDlKE9wywf2cVm8yRCVdEYCHc2NmsbqG7p+TCsnAP1HEnDT1Tli+DI9+r/iQOZKqdBxvCCdrqPNLsLvIfLPwfnhWHrXfmuyw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717370705; c=relaxed/simple; bh=qwhd20pcT6mKmuOmdJvReDADwvss13IfbnCS0P5O90U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t5HBAmpyTqzeuHmdB8ZvauJMpozC3c7+flZEqdE2tab9Fksm/No3os/e+uCIwt5/F2kDyqStTyyGfbmLo1ygJLVo7CIs0khsmzWj56mW6Gm7DLRPaLzySFBZWZi8YJMupkU94oJVd7pzEmt38ecGGVJM9KVBWspKx733UIpKhTY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=tPAmxdjW; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-52b93370ad0so1654658e87.2 for ; Sun, 02 Jun 2024 16:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717370701; x=1717975501; darn=vger.kernel.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=tPAmxdjWhtIQBTKVcAuPpJpM6qNMEfAqaXzwdemOZl3uXnrwp/HfXTQ7kYFrj1DIRT sSAvsaR4fbm68vJhalIoHPqQROmBptZvdEsoUtOkjdKzRe4+hHLCrXmahJ0IlHSvNwfa TKd1I5c4wVxXITL5Au+IKwbI5g2/7wXCcyN3PClz7qdprzlHqTmHR+GKlRfk03r/KASg BcYUwllskBcTkkMDwXMZRYK6rDZXEP/TMzYoKVFuIjzMwuOH0wziXOy4m8+tEDuRq5hJ JLF8szIcL6CVOrhve4hsEgfK6p/ylpSKl9GZyCBZibFzlfcbhVJajEysvzb8uCYLL6gE kyjw== 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=AlxbvB88k1T4WBj6il01J4TyBuPSKoMpE/U+LRlfjfTs2PM9kzqD3DF+HG7OzEB1tD mxLJoJbFqfLRGCXFcGuBJMExMgtnW/QgtH/M3UklQPdsxv0uL4HjJTp/M+KLVw8trlBZ b8lbERisS4pE8Otpsm/dMTlImXGx/N90H2lIVbTq5brsezbgnJNe5xIMD27VPh4VXMO6 w2avN7BNQtwr+ZP7V97iKS34xMI07yWkDIK/EanfoUN1Xk3cHY8et5zKwqhvV/h1d8dN cO9oCcrE63ApfcMS2WBF5OCUf6TvW1MeRR1BFZnBgjOSwjA/IfiWmrHHC6DAOofSjMQV afGQ== X-Forwarded-Encrypted: i=1; AJvYcCUeyuIeH83PsJE6WsSqYhe0s5UkR0rnJbxOwDIOZW8/nl+7su46hnbmRsVbpPI33hN8QOwdSxsKmBvbTihFEB7G929xT4NI/EN6IUcF X-Gm-Message-State: AOJu0YzfaEE+NoJKDeLV9FiXk7va3SjZqQ0XAGnyWZAD7SMQPxrVfQA4 dSpdjLtPINarlMEMHahDo8m3ApH8zxcpGeGOBszY1a4bPrA6pSlqOklxF/KUgmpS3XSVBZiuj3f z 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() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 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) -- 2.39.2