From patchwork Sun Feb 18 22:20:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Ehrhardt X-Patchwork-Id: 13562085 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 C438EC48BC4 for ; Sun, 18 Feb 2024 22:31:11 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OrVWDJZ47/JVK4e3eqAne7+wUl6vOf+F4pMkZFjawjA=; b=dGMK0x4V2Dfy7k q0Z7Pu2DdW49F9eCdPwJ4MPoA2rGzfejpMANqCesEslKYODA/jcGj7PwOKiS9hf8oYRtG45A3IWms KkEk2Cn/gNhWBdLgl+60+nf5U/K2X67t8Wh8inCTsmEx1exveavJDvKrmy608b3DV3ixCzpc4C+/w LPaozQlAOoP6jKhk2yqeJjh/qoM5ExdAIee4USWQuoF4aMG9Jcxd9+0kG7rwLW4Ob6wb5rB6GYjSc IiS6KHvZhX92w6qkVMFLoUV4/MhnBG+fDz02kLrhYYllUb31KA8vMk7Yww1OIYoQ2KoL8LxDkXLWE c1IAqj/aO7ocQwxk8mJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbpgd-00000008YTF-2MXr; Sun, 18 Feb 2024 22:31:03 +0000 Received: from cae.in-ulm.de ([217.10.14.231]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbpgW-00000008YRJ-0hCV for linux-arm-kernel@lists.infradead.org; Sun, 18 Feb 2024 22:30:57 +0000 Received: by cae.in-ulm.de (Postfix, from userid 1000) id CE2C414033C; Sun, 18 Feb 2024 23:21:05 +0100 (CET) From: "Christian A. Ehrhardt" To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Christian A. Ehrhardt" , Heikki Krogerus , Greg Kroah-Hartman , Maxime Coquelin , Alexandre Torgue , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= , =?utf-8?q?Samuel_?= =?utf-8?q?=C4=8Cavoj?= , Hans de Goede , Neil Armstrong , Prashanth K , Dmitry Baryshkov , Saranya Gopal , Haotien Hsu , Andy Shevchenko , Utkarsh Patel , Bjorn Andersson , Luca Weiss , Min-Hua Chen , Rob Herring , Rajaram Regupathy , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Abhishek Pandit-Subedi Subject: [RFC PATCH 2/6] ucsi_ccg: Cleanup endianness confusion Date: Sun, 18 Feb 2024 23:20:35 +0100 Message-Id: <20240218222039.822040-3-lk@c--e.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240218222039.822040-1-lk@c--e.de> References: <20240218222039.822040-1-lk@c--e.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240218_143056_370899_24576B6D X-CRM114-Status: GOOD ( 15.88 ) 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 When storing the cci value in the op_region struct it is converted from host to little endian. However, the value is read from hardware that is little endian according to the spec and it is never converted to host byte order. However, the value is used as if it where in host byte order. Additionally, the message_in buffer is a byte array. Any endian interpretation depends on the current command and must be done in the ocntext of that command. While all the UCSI world seems to be little endian and there are many other endian issues if this is not true, this particular value is treated with endian awareness, so it should at least be done correctly. Add the missing conversion from little endian to host byte order when reading the CCI value from hardware. Additionally, make the message_in buffer an u8 array and adjust the size macro accordingly. Signed-off-by: Christian A. Ehrhardt --- drivers/usb/typec/ucsi/ucsi_ccg.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index dda7c7c94e08..709295948c65 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -192,10 +192,10 @@ struct ucsi_ccg_altmode { bool checked; } __packed; -#define CCGX_MESSAGE_IN_MAX 4 +#define CCGX_MESSAGE_IN_MAX 16 struct op_region { __le32 cci; - __le32 message_in[CCGX_MESSAGE_IN_MAX]; + u8 message_in[CCGX_MESSAGE_IN_MAX]; }; struct ucsi_ccg { @@ -678,6 +678,7 @@ static irqreturn_t ccg_irq_handler(int irq, void *data) u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(UCSI_CCI); struct ucsi_ccg *uc = data; u8 intr_reg; + __le32 __cci; u32 cci = 0; int ret = 0; @@ -690,9 +691,10 @@ static irqreturn_t ccg_irq_handler(int irq, void *data) else if (!(intr_reg & UCSI_READ_INT)) goto err_clear_irq; - ret = ccg_read(uc, reg, (void *)&cci, sizeof(cci)); + ret = ccg_read(uc, reg, (void *)&__cci, sizeof(__cci)); if (ret) goto err_clear_irq; + cci = le32_to_cpu(__cci); if (UCSI_CCI_CONNECTOR(cci)) ucsi_connector_change(uc->ucsi, UCSI_CCI_CONNECTOR(cci));