From patchwork Fri Jan 13 18:26:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 13101485 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 AB9CDAD4A for ; Fri, 13 Jan 2023 18:26:37 +0000 (UTC) Received: by mail-pf1-f176.google.com with SMTP id i65so13335072pfc.0 for ; Fri, 13 Jan 2023 10:26:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=v0IZMQ5s013CKLPMbvZH+OUmUx07zKwii/Tta4BO8NQ=; b=ochu6DRcIo08TOd/D8jh5Tf6fdQOlvs9XXYjw9VXWD1QJ6nUv0zY1YEEzocAoEf7eY KCIsfp9Pm0V31jq97KHsb3tRLRE3N47wfuTygppoSTRhrSQi5WYjrUvSGpCC4JieBiEG AbszzxRfLaJChuj8z9UUCZcoaCnKZx24qa+k0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v0IZMQ5s013CKLPMbvZH+OUmUx07zKwii/Tta4BO8NQ=; b=KeBjgW+5VqJtGhsKs+QJN/kP5ZOsHnGB8T6cwVSuPa4wQsA+ewM87/wD4Dl5vXkC8S wlEScbvQC//+BwwIs/YnzPvNOoFitNrRGiEUayoxJPtIwIUs/l3mgs3eZ9pUwJ7UCAO2 W11KQ414bwSp3vxTY4aUlvo9JYJa4SwhG/uLiUohpkC1WqUSVpyn6xOAW7SVlj8PKB5X 3OUcpP98G0oY9oIGaIEohMstuCoQGdzBJDpTK5TG9jylD6hHUl0E2+VeD12XzSNUGSGM j0wDYRjMcQ47SoVKPYmEhXd/S7TlihcEihwGNgnBZNzXqoHlD96KS1Ow0nHnTOx6d+Ui Q3EQ== X-Gm-Message-State: AFqh2kosJluHi8J86JGJ82rne78PZUNdnDmJZq7KKxj6wD6L4I9hoVlP RDGFJYrjlrK7qwSA/9kOu+k9Ea0PN5IeJnOB X-Google-Smtp-Source: AMrXdXvKc6B2+yqll8S678mrWE5J7iNXmXppKsc/lXs6VFCK7Gm1J1hzHJNPpJii6evUmrWWOnijuQ== X-Received: by 2002:a62:2903:0:b0:57f:f2cd:6180 with SMTP id p3-20020a622903000000b0057ff2cd6180mr74775013pfp.0.1673634397061; Fri, 13 Jan 2023 10:26:37 -0800 (PST) Received: from pmalani.c.googlers.com.com (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id 124-20020a621882000000b0057709fce782sm9330183pfy.54.2023.01.13.10.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:26:36 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev Cc: bleung@chromium.org, Prashant Malani Subject: [PATCH] platform/chrome: cros_typec_vdm: Fix VDO copy Date: Fri, 13 Jan 2023 18:26:26 +0000 Message-Id: <20230113182626.1149539-1-pmalani@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The usage of memcpy() affects the representation of the VDOs as they are copied to the EC Host Command buffer. Specifically, all higher order bits get dropped (for example: a VDO of 0x406 just gets copied as 0x6). Avoid this by explicitly copying each VDO in the array. The number of VDOs generated by alternate mode drivers in their VDMs is almost always just 1 (apart from the header) so this doesn't affect performance in a meaningful way). Fixes: 40a9b13a09ef ("platform/chrome: cros_typec_vdm: Add VDM send support") Signed-off-by: Prashant Malani Reviewed-by: Benson Leung --- drivers/platform/chrome/cros_typec_vdm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_typec_vdm.c b/drivers/platform/chrome/cros_typec_vdm.c index aca9d337118e..06f4a55999c5 100644 --- a/drivers/platform/chrome/cros_typec_vdm.c +++ b/drivers/platform/chrome/cros_typec_vdm.c @@ -86,10 +86,12 @@ static int cros_typec_port_amode_vdm(struct typec_altmode *amode, const u32 hdr, .command = TYPEC_CONTROL_COMMAND_SEND_VDM_REQ, }; struct typec_vdm_req vdm_req = {}; + int i; vdm_req.vdm_data[0] = hdr; vdm_req.vdm_data_objects = cnt; - memcpy(&vdm_req.vdm_data[1], vdo, cnt - 1); + for (i = 1; i < cnt; i++) + vdm_req.vdm_data[i] = vdo[i-1]; vdm_req.partner_type = TYPEC_PARTNER_SOP; req.vdm_req_params = vdm_req;