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 A. Ehrhardt" X-Patchwork-Id: 202883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp972328dyc; Sun, 18 Feb 2024 14:22:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW7LxZRxmec8JJ/mo7GmedbR9W9JMYM48INcyX/DgQjJca0wCHDk77CD0lCzIjYA3NLxzmv6HQ95PKdFIGzh1hk482bcQ== X-Google-Smtp-Source: AGHT+IELzyWe45amH48SqfhFvZcpcURH2WgFG7hgWwEt8ytd4u13tOC0/Fr4tJ7MX8BISFCgM7c1 X-Received: by 2002:a05:620a:439f:b0:787:6bf5:c37b with SMTP id a31-20020a05620a439f00b007876bf5c37bmr220203qkp.58.1708294946113; Sun, 18 Feb 2024 14:22:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708294946; cv=pass; d=google.com; s=arc-20160816; b=BOvkPb3zVAjNPPYGPvcp/hD6khP9Be6OJ3sjkIUSSlmC9RDoCGRfyIaCqbOrk0npY6 GML8lbDkvlJghWPZjVNPkCVMIMTxbLy6eKIZlRJYWxwawsHrhJx3rA0F+7Vp9WqWaarP ciBO4aZO9m5cDBL6qHIJlMG76Cn+Yg/zQi+OOBGpathtXSmeol8+Zx+Uigc4QC/Yi3pd QCEYsd/u77eaN3OekLLXdRCr6RAyZIh3IQQ0Jf/odD+rVrlnEG8bDlSeh9ClhuJotee4 3SEJQ0Xt9PrNCS0TZnWkhXjYvrWrHNXIv+3rRt9xo6/sLmdxkLan5k/PVGJwpjgtzf91 xC3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=AYRpWObDltOBLtMQlbjO166Ghi+6JlBmWhbF8LRJTQg=; fh=NZYqj9rN7CYKDURs9gmqF/Q4C0zz9wOO6FGPGe/FaIo=; b=RoBFJX9x3J/GKiWqLdw/VMdNi9ReqrmJbBwz3ddpZAu/rgVVkvB+NSblKPo8eys3YY VYjEoHVB1BhaJC5kpBrBKxtraKmi+a37o4ajj4ON8h6MybLM8dz14IOTvyJ8MNhcgm6k RlZHeIVYgfsa5j1xrHevZ3n5gwdeKRaQhRHmSmUQPMPyjYMhmh6Dss/pnGbiMEmHKk2s YTCbRVet15r983UfhwkmcWH24JRM9KxaYaGicREoDG7JjSg6rKyzmZW5ZqLdVqtWYloL Y5iK3BzMpidPlWjSo5NOzlQdwuTCCALGZE/fgAZgBiDhXnx3brELpM+yd2Nk7EGa9khK TagA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=c--e.de); spf=pass (google.com: domain of linux-kernel+bounces-70608-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70608-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o17-20020a05620a229100b0078594ff95f3si4941026qkh.682.2024.02.18.14.22.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 14:22:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70608-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=c--e.de); spf=pass (google.com: domain of linux-kernel+bounces-70608-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70608-ouuuleilei=gmail.com@vger.kernel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BB2611C20C58 for ; Sun, 18 Feb 2024 22:22:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE8D7763F1; Sun, 18 Feb 2024 22:21:15 +0000 (UTC) Received: from cae.in-ulm.de (cae.in-ulm.de [217.10.14.231]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A542C745F8; Sun, 18 Feb 2024 22:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.10.14.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708294874; cv=none; b=h/dpz4qza7HxsTjMYNNmBg/jkdsOPXTPz4HcdZaJZrHRk7eA9J+QwvtCiP0ijmLPlxfSnnLwu5DB3JPW84z8JWZIcH7ogOh/HpnBb7MC2XUycn/NLuj1vz/2UJmu7cUQTxOI4oEZNGI4CBH6+5qbfk84/WeWEY61f5BHSdwgf28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708294874; c=relaxed/simple; bh=+stEjvwEshPruJnaSd7743lZYwerj31wMavbwUiF8lQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jMdcFGeziHoCeiPlLnOew0XGSLB1ChGph5ISBwi5k9uPwcw/p0doFrtG3jB7Xff9q5pqP1FAoC9A145Jw35QUcJH+TTnDTHPrdREsy0a5QUNH3WONGTT+iCUseUpX4j/5Tff2/1h+djy9Tgr20Ij6cCWrEbp/CWcmJ32S25YIBo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=c--e.de; spf=pass smtp.mailfrom=c--e.de; arc=none smtp.client-ip=217.10.14.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=c--e.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=c--e.de 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791277081251123833 X-GMAIL-MSGID: 1791277081251123833 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));