Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13740672ybl; Sun, 29 Dec 2019 19:36:49 -0800 (PST) X-Google-Smtp-Source: APXvYqzZwx4nddCqeJCOBjMcY56YSgvToM5EuzS5PBX59QXzBHkc5SHbMIhRlkIB8PJBvUt4VxL2 X-Received: by 2002:a9d:7b4a:: with SMTP id f10mr75461757oto.4.1577677009450; Sun, 29 Dec 2019 19:36:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577677009; cv=none; d=google.com; s=arc-20160816; b=fEKqWcPWDaGY/d+kSV8wwW6dZlaZKtUWaooXrYXqbHBMoWPDRF9vfMnrt3cDryUtim KfXyJCMEBnHCyNSNVNFiLnPcL2+V1UWNr5g8SVStzRFCXIVwivgzem3VTW5hR9WC2QN3 LKi0tBopASiMey1itcv7bXODjIHOrkdwTPbwLZiR3/Ji2ejjwCihqizTG4ZBtnztrfOQ GroVQkhGTWOJ9d9WvNYqqMIrpDkDed8C3r4viEDZE51Dmx3Ln+V3xuG9i2tPUoavXk22 WkALNeRt2MkenLh7vRT+R7SULCDWwdKUnDDyZj1RwTzxdIHqWwULktcBZ0SWg9AiyfdF XoZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=kwegLokC7Kbc+Tpfbuewa+8jDYPTbVeTO+01/L5vq5I=; b=ltUWJxS9ux0hZqha18aktrsmUxnL6VhvNLNAwKFBexiZABxrxF66L6fPueYg6nUufj nXphCrHh4Pw3aHwqZRT2+LTTo9BcT6VZwPs5lX1X18WPsXJCwVHVFSsllj08VyApO3kL MVBwTT9KoVc6jLxkvIvPTtgPwgLcieHdLeDMCHD6j7+36NhE0C3fYA+n98PiKVVy0ihl xBQ85Wo0VlO1AEUX73A+hD6Usgj0LvuCjlayZ7K37B+PIoEUrj3ImWko+XpOLKdym7cD 0LlVVqsr3DVV3l21Dz6Px5laGA5Cjc48YRCESiK2eUin/WIjnum+Cs+bpY+jBBh3damJ Ywwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a14si16174730oid.58.2019.12.29.19.36.36; Sun, 29 Dec 2019 19:36:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbfL3Df6 (ORCPT + 99 others); Sun, 29 Dec 2019 22:35:58 -0500 Received: from smtp.infotech.no ([82.134.31.41]:59458 "EHLO smtp.infotech.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727065AbfL3Df6 (ORCPT ); Sun, 29 Dec 2019 22:35:58 -0500 Received: from localhost (localhost [127.0.0.1]) by smtp.infotech.no (Postfix) with ESMTP id C945B204247; Mon, 30 Dec 2019 04:35:55 +0100 (CET) X-Virus-Scanned: by amavisd-new-2.6.6 (20110518) (Debian) at infotech.no Received: from smtp.infotech.no ([127.0.0.1]) by localhost (smtp.infotech.no [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0AVJGC7Mh64q; Mon, 30 Dec 2019 04:35:48 +0100 (CET) Received: from xtwo70.bingwo.ca (host-23-251-188-50.dyn.295.ca [23.251.188.50]) by smtp.infotech.no (Postfix) with ESMTPA id 00741204157; Mon, 30 Dec 2019 04:35:47 +0100 (CET) From: Douglas Gilbert To: linux-usb@vger.kernel.org Cc: linux@roeck-us.net, stable@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] USB-PD tcpm: bad warning+size, PPS adapters Date: Sun, 29 Dec 2019 22:35:44 -0500 Message-Id: <20191230033544.1809-1-dgilbert@interlog.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Augmented Power Delivery Objects (A)PDO_s are used by USB-C PD power adapters to advertize the voltages and currents they support. There can be up to 7 PDO_s but before PPS (programmable power supply) there were seldom more than 4 or 5. Recently Samsung released an optional PPS 45 Watt power adapter (EP-TA485) that has 7 PDO_s. It is for the Galaxy 10+ tablet and charges it quicker than the adapter supplied at purchase. The EP-TA485 causes an overzealous WARN_ON to soil the log plus it miscalculates the number of bytes to read. So this bug has been there for some time but goes undetected for the majority of USB-C PD power adapters on the market today that have 6 or less PDO_s. That may soon change as more USB-C PD adapters with PPS come to market. Tested on a EP-TA485 and an older Lenovo PN: SA10M13950 USB-C 65 Watt adapter (without PPS and has 4 PDO_s) plus several other PD power adapters. Signed-off-by: Douglas Gilbert --- drivers/usb/typec/tcpm/tcpci.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index c1f7073a56de..8b4ff9fff340 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -432,20 +432,30 @@ irqreturn_t tcpci_irq(struct tcpci *tcpci) if (status & TCPC_ALERT_RX_STATUS) { struct pd_message msg; - unsigned int cnt; + unsigned int cnt, payload_cnt; u16 header; regmap_read(tcpci->regmap, TCPC_RX_BYTE_CNT, &cnt); + /* + * 'cnt' corresponds to READABLE_BYTE_COUNT in section 4.4.14 + * of the TCPCI spec [Rev 2.0 Ver 1.0 October 2017] and is + * defined in table 4-36 as one greater than the number of + * bytes received. And that number includes the header. So: + */ + if (cnt > 3) + payload_cnt = cnt - (1 + sizeof(msg.header)); + else + payload_cnt = 0; tcpci_read16(tcpci, TCPC_RX_HDR, &header); msg.header = cpu_to_le16(header); - if (WARN_ON(cnt > sizeof(msg.payload))) - cnt = sizeof(msg.payload); + if (WARN_ON(payload_cnt > sizeof(msg.payload))) + payload_cnt = sizeof(msg.payload); - if (cnt > 0) + if (payload_cnt > 0) regmap_raw_read(tcpci->regmap, TCPC_RX_DATA, - &msg.payload, cnt); + &msg.payload, payload_cnt); /* Read complete, clear RX status alert bit */ tcpci_write16(tcpci, TCPC_ALERT, TCPC_ALERT_RX_STATUS); -- 2.24.1