From patchwork Thu Dec 14 20:37:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 178897 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8834392dys; Thu, 14 Dec 2023 12:38:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8GfyL2otXwQNy4HcZ4Hh65foEtXCf/UVcTiarfhTPwK/ZbiG3txhLRfddZK26ecwVqxXv X-Received: by 2002:a05:620a:19a6:b0:77d:98c3:1eda with SMTP id bm38-20020a05620a19a600b0077d98c31edamr13782795qkb.43.1702586315094; Thu, 14 Dec 2023 12:38:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702586315; cv=none; d=google.com; s=arc-20160816; b=GglJucmcyWhtav8nKhhCTmWZAhE7yDoEccAE9ATUOwKAVaE7NYJ8OUu5Fm77gLZZUi 6MbZN6hrtz2EjY7fC3KkGcdY4GNA+CItLqKsZyVkrqiIH03rzvcFA1IkKBRX+JW7d3S9 aUt9RQQNNxkOb6x5cWLk6FlbsJQcESq5JoAWRdv6vTjAE99fciCxi7eLXsqLbQT+Iqtf BJI25gmLhUiE0+JTbVuMmcZ4Z5DW1FDLpU3uFNq1HJw/gZ9ocs10UlteFyRAyOq06IX8 RIxPslyFcS1OiGt249BYtANyJeYv1oEHAOXnL0szEKlClesGaP/9VZ5Y0Q6jNoB/PizO SDEQ== ARC-Message-Signature: i=1; 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:message-id:date:subject:cc:to :from:dkim-signature; bh=CEbYOeExhWxrQcvIrSnW0dzfFwJIoL+EWRTjsEQRQR4=; fh=0uTLTr2riDmlYDujtHZf/aXqxPzrYy60z/zevNy6jwI=; b=H9WX0um0TCE9S16HjMvcDaHd8frvOsHzIZ1qlgsv6a523DWHnE6XRnA1KM0PCp5KWB +i8sxxNQ9YUQ/1gnjnl9obUR6lJhRYmjijMEVBiVKzmTWtBR9PdZgt5JtQ/e3i2e7snO LbC1Hx7nkViMXK44WZAdiJMnBELiBZe1pJFS0YLLNDElS33Z58GQqRt1rfXsaHDZwBGl IGJiW89Au0LO3Mj31crmqdqqmHsZZdF9e/N5U6rmbohzWFCaduy/3bfGkCLOv8E6cW1O daK4hvRuSMVtvPg80u50VF1TJpzTqsRsv7dEXhffr1U5lyz5a9u2yrV5P0SUyyrT27z8 iurA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iduOy+Fy; spf=pass (google.com: domain of linux-kernel+bounces-77-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s17-20020a05620a29d100b0077f63268fd3si13303701qkp.48.2023.12.14.12.38.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:38:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iduOy+Fy; spf=pass (google.com: domain of linux-kernel+bounces-77-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 DE6591C21B4D for ; Thu, 14 Dec 2023 20:38:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E5ED06D1AB; Thu, 14 Dec 2023 20:38:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="iduOy+Fy" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 E695A2112 for ; Thu, 14 Dec 2023 20:38:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1d307cf18fdso31313485ad.3 for ; Thu, 14 Dec 2023 12:38:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702586290; x=1703191090; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=CEbYOeExhWxrQcvIrSnW0dzfFwJIoL+EWRTjsEQRQR4=; b=iduOy+FypuQQ7pXz+XyjB+/lRThjfh9ttCsMv8zreqNCWM5WTv2La6OOI45l7Y13sg RoW6l87zpZB0Y/jmLzcpXM6pPlPYEo1bG6yen4KwUri8ELKBdeHBwhCXk2zffU9trDE2 YNhbh1i/KL1vomXJzonBC2PQweZVQMNCqkNiA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702586290; x=1703191090; 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=CEbYOeExhWxrQcvIrSnW0dzfFwJIoL+EWRTjsEQRQR4=; b=thyTXEuI9nUGXyffmrj+e70HfHXX3tG+zACETkFEvyZ/xhkz29z/pg0AAnbZH1JstF X8995G9IFWCCdqusQ+RArU92G+72euy/8toIxLxRWyhAhMfBaPlDlXLvBVVNgkgfEgu1 xiXRzcZ0X0nIlpVRGndAxZXKarF/0chqmPW0HQS8iU8xr+nSS38mQPt1ifMqqRj79SVx NDlq+rjs8ImigIeMxXev+QD/hjOQm1R59Zqw7hO22Vvm9D1WvdVjycA2fRIPcoGYvdft yEsCPPwC/Iu+1p0/t+YeOrroJUtpqBM42D/N9deI1XgdIfCqeOZJfwye9FrH0ugL88Z9 L3Eg== X-Gm-Message-State: AOJu0Yx6lvACBIjLeEC8z6UqYUJfXzmjT6+gVhivMS7QHaVJFZdYrRmL jsSHE3Pdqn1dzXsKh+Okd/f4Lw== X-Received: by 2002:a17:902:ec89:b0:1d0:c26d:e509 with SMTP id x9-20020a170902ec8900b001d0c26de509mr6417151plg.108.1702586290186; Thu, 14 Dec 2023 12:38:10 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:9d0c:9bd0:17f6:8236]) by smtp.gmail.com with ESMTPSA id y18-20020a170902b49200b001cfc2e0a82fsm12799081plr.26.2023.12.14.12.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:38:09 -0800 (PST) From: Douglas Anderson To: dri-devel@lists.freedesktop.org Cc: Guenter Roeck , Douglas Anderson , Andrzej Hajda , Daniel Vetter , David Airlie , Jernej Skrabec , Jonas Karlman , Laurent Pinchart , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Philip Chen , Robert Foss , Sam Ravnborg , Stephen Boyd , Thomas Zimmermann , linux-kernel@vger.kernel.org Subject: [PATCH v3 1/2] drm/bridge: parade-ps8640: Never store more than msg->size bytes in AUX xfer Date: Thu, 14 Dec 2023 12:37:51 -0800 Message-ID: <20231214123752.v3.1.I9d1afcaad76a3e2c0ca046dc4adbc2b632c22eda@changeid> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog 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: 1785290800195907108 X-GMAIL-MSGID: 1785291148056465713 While testing, I happened to notice a random crash that looked like: Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: drm_dp_dpcd_probe+0x120/0x120 Analysis of drm_dp_dpcd_probe() shows that we pass in a 1-byte buffer (allocated on the stack) to the aux->transfer() function. Presumably if the aux->transfer() writes more than one byte to this buffer then we're in a bad shape. Dropping into kgdb, I noticed that "aux->transfer" pointed at ps8640_aux_transfer(). Reading through ps8640_aux_transfer(), I can see that there are cases where it could write more bytes to msg->buffer than were specified by msg->size. This could happen if the hardware reported back something bogus to us. Let's fix this so we never write more than msg->size bytes. We'll still read all the bytes from the hardware just in case the hardware requires it since the aux transfer data comes through an auto-incrementing register. NOTE: I have no actual way to reproduce this issue but it seems likely this is what was happening in the crash I looked at. Fixes: 13afcdd7277e ("drm/bridge: parade-ps8640: Add support for AUX channel") Signed-off-by: Douglas Anderson Reviewed-by: Guenter Roeck Reviewed-by: Stephen Boyd --- Changes in v3: - Never return more than msg->size as the number of bytes we read. Changes in v2: - Still read all the bytes; just don't write them all to the buffer. drivers/gpu/drm/bridge/parade-ps8640.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/bridge/parade-ps8640.c b/drivers/gpu/drm/bridge/parade-ps8640.c index 8161b1a1a4b1..d264b80d909d 100644 --- a/drivers/gpu/drm/bridge/parade-ps8640.c +++ b/drivers/gpu/drm/bridge/parade-ps8640.c @@ -330,11 +330,12 @@ static ssize_t ps8640_aux_transfer_msg(struct drm_dp_aux *aux, return ret; } - buf[i] = data; + if (i < msg->size) + buf[i] = data; } } - return len; + return min(len, msg->size); } static ssize_t ps8640_aux_transfer(struct drm_dp_aux *aux, From patchwork Thu Dec 14 20:37:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 178898 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8834587dys; Thu, 14 Dec 2023 12:38:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvEcVXj7e2ZlFH69U0fBIcWq2FXUQcc/MChBi1Qq/Lak5N6KM6hIXvP4PRlSE0rZZSti9T X-Received: by 2002:a05:620a:b94:b0:77f:913:1dd1 with SMTP id k20-20020a05620a0b9400b0077f09131dd1mr10265315qkh.105.1702586325400; Thu, 14 Dec 2023 12:38:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702586325; cv=none; d=google.com; s=arc-20160816; b=UQXdNK1CSvYbyQzJa1oczDOtl7BwL2+DhuJZfku3xG5HnbQhim/9w2teXbcKkDDdjW dLLJjudNLuYQq5rAxv7Dk4ot9atO5fzaC6uHTBWAkkgZbkoDORQ3tMDSYx9dwh5+Ir0h uJXbE16ADeoqSiFaCeiFYfRewDb4P8uxtHx+2nDyAG5PVPAMBQHLzS6RQCK0DQy1w7td rjAnSlq6ar21qtsNPxWavVp+fHBPfdzch+BNn/C68AT6UhrtYiD8e/qCCx7lza0qP508 23WsZcuXiK3lWIOrt6KlgrRo8B7Gq4MqwxZ3T9qyZ1nGRh41hnrTDr6GDOdM4UTrqRI3 buLw== ARC-Message-Signature: i=1; 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:dkim-signature; bh=RCuUsFQR6lp6/7dcHWOPjNe2VLvS+gov+CkK1fWJuUI=; fh=2/whrSurlCvVh9Z/Qmn+h5dkhtzQzhlyNw5IH9iNECA=; b=YrdFMv0Ub19U/MHKWLgqrBRR+ujQiH/OU2CDah0TchXPTADYAAwqghUl1i67BvklIL CQgx4U8l1VZgdC5KMouUAe2EC97aXludc9BQbFDlKWz3Ls9UyszuUAYyvYQs4lU/maBs r/geOW5oWwgEUpDk9prqrZ1TtqJ4luno9nPSRoTR/a4+RUjBQNqjxNK3Tyna0Z1Z0NVP wUljGM9ZYgvGZdmRLSAq59i9S+50pfkP1TCzKvQKKU1408tcQJbfuG0S87uaaByKaK1+ o/r9ZgxPG7sxYAeUK41HZTkV1wCD8o5I2Uau3z7ii58zH4RDQSB55/LGGepVOBqF6+Zo YrKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IEIwaPvB; spf=pass (google.com: domain of linux-kernel+bounces-78-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z33-20020a05620a262100b007706c5a23f6si17198765qko.175.2023.12.14.12.38.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:38:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IEIwaPvB; spf=pass (google.com: domain of linux-kernel+bounces-78-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 2DF8D1C20F29 for ; Thu, 14 Dec 2023 20:38:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9EC46D1D4; Thu, 14 Dec 2023 20:38:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="IEIwaPvB" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 00B593BB48 for ; Thu, 14 Dec 2023 20:38:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6cef5220d07so3732965b3a.2 for ; Thu, 14 Dec 2023 12:38:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702586292; x=1703191092; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RCuUsFQR6lp6/7dcHWOPjNe2VLvS+gov+CkK1fWJuUI=; b=IEIwaPvBlbRN6MlPEIXuK9Cfa3vOfSKOxMZhVd8KOKGTUZxTgWaiX+Y9Yle7QvekcP F0Af/TuvFjWVLHiqp1BLhXe8TojCeveAUWU+dm+0c0W9OUtFda2Fte1OvrYv1ugpZymI 0+SAZSHnPETZtIsl6bYgvtyIc+0yxBEokH7Cc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702586292; x=1703191092; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RCuUsFQR6lp6/7dcHWOPjNe2VLvS+gov+CkK1fWJuUI=; b=QMuuIhBF4YvNBbPm10WXTrvRDxKmYReFXJmL2zfbvx6VJNkSWdScwepl26oPbw0fp2 FYiQrrhzmCpGLLTjeChRc09X6Oto1fB1L7RYdwA/K71UaEFcnrMHZY/Etz+IycpU9s9n Cvybet6A8m0WvdSSrQkQzlkYQE0sC4L56bTbvqfpBLE4708xFd5MD4+O4n65oo1uizlB zZGvTCXaWq3yiNbUuQlVA+FSOC/4t0aocqbT8AMg7aP4gFLaTtRzT6gXEWarKsOECfKb xXUkhMEb/kczRo6NOwFHdK8vEBRKr2brNA6dVpwrvQexGxUt43XzpqY0+cXKFdRB4WVQ 0eYw== X-Gm-Message-State: AOJu0YzNvxj63UMRQEOmfNaaCa6KhtuvzphUvoQNmz7+M7qtagroLlKr ZlYLnY50uDzOONwlqB0m0R+zPw== X-Received: by 2002:a05:6a21:3398:b0:18c:2287:29cf with SMTP id yy24-20020a056a21339800b0018c228729cfmr6588631pzb.40.1702586292209; Thu, 14 Dec 2023 12:38:12 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:9d0c:9bd0:17f6:8236]) by smtp.gmail.com with ESMTPSA id y18-20020a170902b49200b001cfc2e0a82fsm12799081plr.26.2023.12.14.12.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:38:11 -0800 (PST) From: Douglas Anderson To: dri-devel@lists.freedesktop.org Cc: Guenter Roeck , Douglas Anderson , Andrzej Hajda , Daniel Vetter , David Airlie , Jernej Skrabec , Jonas Karlman , Laurent Pinchart , Maarten Lankhorst , Maxime Ripard , Neil Armstrong , Robert Foss , Sam Ravnborg , Stephen Boyd , Thomas Zimmermann , linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] drm/bridge: ti-sn65dsi86: Never store more than msg->size bytes in AUX xfer Date: Thu, 14 Dec 2023 12:37:52 -0800 Message-ID: <20231214123752.v3.2.I7b83c0f31aeedc6b1dc98c7c741d3e1f94f040f8@changeid> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231214123752.v3.1.I9d1afcaad76a3e2c0ca046dc4adbc2b632c22eda@changeid> References: <20231214123752.v3.1.I9d1afcaad76a3e2c0ca046dc4adbc2b632c22eda@changeid> 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: 1785291158383537343 X-GMAIL-MSGID: 1785291158383537343 For aux reads, the value `msg->size` indicates the size of the buffer provided by `msg->buffer`. We should never in any circumstances write more bytes to the buffer since it may overflow the buffer. In the ti-sn65dsi86 driver there is one code path that reads the transfer length from hardware. Even though it's never been seen to be a problem, we should make extra sure that the hardware isn't increasing the length since doing so would cause us to overrun the buffer. Fixes: 982f589bde7a ("drm/bridge: ti-sn65dsi86: Update reply on aux failures") Signed-off-by: Douglas Anderson Reviewed-by: Guenter Roeck Reviewed-by: Stephen Boyd --- (no changes since v2) Changes in v2: - Updated patch subject to match ps8640 patch. drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c index 9095d1453710..62cc3893dca5 100644 --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c @@ -527,6 +527,7 @@ static ssize_t ti_sn_aux_transfer(struct drm_dp_aux *aux, u32 request_val = AUX_CMD_REQ(msg->request); u8 *buf = msg->buffer; unsigned int len = msg->size; + unsigned int short_len; unsigned int val; int ret; u8 addr_len[SN_AUX_LENGTH_REG + 1 - SN_AUX_ADDR_19_16_REG]; @@ -600,7 +601,8 @@ static ssize_t ti_sn_aux_transfer(struct drm_dp_aux *aux, } if (val & AUX_IRQ_STATUS_AUX_SHORT) { - ret = regmap_read(pdata->regmap, SN_AUX_LENGTH_REG, &len); + ret = regmap_read(pdata->regmap, SN_AUX_LENGTH_REG, &short_len); + len = min(len, short_len); if (ret) goto exit; } else if (val & AUX_IRQ_STATUS_NAT_I2C_FAIL) {