Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp204196ybi; Fri, 26 Jul 2019 08:24:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvZZeDaMXiu+3Nfk/Zp22vIJCoYv6tfd6HSHmofR9nC7ALwgk3Z8x79aB8Bjq8HHUWWWl/ X-Received: by 2002:a17:902:9f93:: with SMTP id g19mr95842338plq.223.1564154670005; Fri, 26 Jul 2019 08:24:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564154669; cv=none; d=google.com; s=arc-20160816; b=Tiii5b2w9US/luSWMl3vp+xSSRnx+gV90sJ7cLu5zuISH8ROm6GgKrxYY9VLdn2ghY b7KHfchEIj08E4YpBI7Wj7XdnnUGdqRfkaWpiZJroAQ63aWHJNSwuBG3Ju/XjYd1hIFA ffrx4OmdirDz8pReJGliVEE+4xJdkNER0mQUpbYxbRsrtN9bcgT0jwIOAJ1cnxeYCrMg TxPOp0rlBk59FTg+yET15IVhVOeNNXgBE2tQDVJbAg2L8yYph9T3XV28kIat134FLsOG WbvSkzhAMGRRQeA52AmLHtVC3SwxrmCTD71SotcWcxbvdlxXYbQa/HVnCaEIwThx4Vcc +hWw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:reply-to; bh=KWC+pqB9im+dQN9qceJ6uly5m5DZrHv3rybSHjvde+g=; b=eDCJWrPQvf5lPk0sXIsUQpUsbT1H1W0uiLNiaa6QHdplHFtk5qvt6GMZ62sEiFjt5M 2PLjmbCVFU1apvPAYXUTsCsTqURDhvjHZJNG/YzvRFlOjInljjo7RpBEnIYrz3qDeWjg TsEvS4XnJ+INUXq8fasbh1pWqXMFoJX43vGwSxVBp89KpzPRD7Sj3k7qM1K92HrFAY9J vlIRD1fEwprJEPM/KJa0YKAn6t9OMuXRU4ZL7l3zXHrlyTtWkPd4QCUgrb2g2jyg8paW xvUUznOc/FL7N8iw8Mck/ZFx7NHTRB6v21K43OLuAceqtHGFyj5XlQhkPWDOvmzuL8c7 Qk6g== 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 y14si4027619pfr.82.2019.07.26.08.24.14; Fri, 26 Jul 2019 08:24:29 -0700 (PDT) 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 S1728328AbfGZPVg (ORCPT + 99 others); Fri, 26 Jul 2019 11:21:36 -0400 Received: from smtp.infotech.no ([82.134.31.41]:52302 "EHLO smtp.infotech.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726731AbfGZPVg (ORCPT ); Fri, 26 Jul 2019 11:21:36 -0400 Received: from localhost (localhost [127.0.0.1]) by smtp.infotech.no (Postfix) with ESMTP id 3618C204194; Fri, 26 Jul 2019 17:21:33 +0200 (CEST) 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 WrYd0Hozk3az; Fri, 26 Jul 2019 17:21:26 +0200 (CEST) Received: from [192.168.48.23] (host-23-251-188-50.dyn.295.ca [23.251.188.50]) by smtp.infotech.no (Postfix) with ESMTPA id 473D7204187; Fri, 26 Jul 2019 17:21:24 +0200 (CEST) Reply-To: dgilbert@interlog.com Subject: Re: [RFC PATCH] usb: typec: tcpm: Ignore unsupported/unknown alternate mode requests To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org References: <1564029037-22929-1-git-send-email-linux@roeck-us.net> From: Douglas Gilbert Message-ID: Date: Fri, 26 Jul 2019 11:21:23 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <1564029037-22929-1-git-send-email-linux@roeck-us.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-CA Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-07-25 12:30 a.m., Guenter Roeck wrote: > TCPM may receive PD messages associated with unknown or unsupported > alternate modes. If that happens, calls to typec_match_altmode() > will return NULL. The tcpm code does not currently take this into > account. This results in crashes. > > Unable to handle kernel NULL pointer dereference at virtual address 000001f0 > pgd = 41dad9a1 > [000001f0] *pgd=00000000 > Internal error: Oops: 5 [#1] THUMB2 > Modules linked in: tcpci tcpm > CPU: 0 PID: 2338 Comm: kworker/u2:0 Not tainted 5.1.18-sama5-armv7-r2 #6 > Hardware name: Atmel SAMA5 > Workqueue: 2-0050 tcpm_pd_rx_handler [tcpm] > PC is at typec_altmode_attention+0x0/0x14 > LR is at tcpm_pd_rx_handler+0xa3b/0xda0 [tcpm] > ... > [] (typec_altmode_attention) from [] > (tcpm_pd_rx_handler+0xa3b/0xda0 [tcpm]) > [] (tcpm_pd_rx_handler [tcpm]) from [] > (process_one_work+0x123/0x2a8) > [] (process_one_work) from [] > (worker_thread+0xbd/0x3b0) > [] (worker_thread) from [] (kthread+0xcf/0xf4) > [] (kthread) from [] (ret_from_fork+0x11/0x38) > > Ignore PD messages if the asociated alternate mode is not supported. > > Reported-by: Douglas Gilbert > Cc: Douglas Gilbert > Fixes: e9576fe8e605c ("usb: typec: tcpm: Support for Alternate Modes") > Signed-off-by: Guenter Roeck > --- > Taking a stab at the problem. I don't really know if this is the correct > fix, or even if my understanding of the problem is correct, thus marking > the patch as RFC. Tested-by: Douglas Gilbert Took a little while because I was changing my Linux end to being based on a Acme Systems Arietta (at91sam9g25). Reason: on the sama5d2xplained I can't have the shield plugged into the Arduino sockets because it drives the pin used by the OM13588 for its interrupt (nalert). So I need to "jump" the pins needed (SDA, SCL, nALERT, 3v3 and ground) to get this working (and 'cat /proc/interrupts' shows me its working with >0 interrupts on "2-0050"). Anyway the DUT is a OM13588+sama5d2xplained running lk 5.1.18 and the other end of the USB-C cable is a OM13588+KL27Z running NXP PD software. Both ends can "play" sink or source (power). The oops occurred when the DUT was source and the other end sent a "send attention" ("l") command. With this patch I do not see the oops. BTW I have tried to run lk 5.2.1 on the sama5d2xplained and the kernel wouldn't start :-( Zilch after u-boot said it was loading the kernel. > drivers/usb/typec/tcpm/tcpm.c | 38 ++++++++++++++++++++++++-------------- > 1 file changed, 24 insertions(+), 14 deletions(-) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index 77f71f602f73..1df2844469aa 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -1096,7 +1096,8 @@ static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt, > break; > case CMD_ATTENTION: > /* Attention command does not have response */ > - typec_altmode_attention(adev, p[1]); > + if (adev) > + typec_altmode_attention(adev, p[1]); > return 0; > default: > break; > @@ -1148,20 +1149,26 @@ static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt, > } > break; > case CMD_ENTER_MODE: > - typec_altmode_update_active(pdev, true); > - > - if (typec_altmode_vdm(adev, p[0], &p[1], cnt)) { > - response[0] = VDO(adev->svid, 1, CMD_EXIT_MODE); > - response[0] |= VDO_OPOS(adev->mode); > - return 1; > + if (adev && pdev) { > + typec_altmode_update_active(pdev, true); > + > + if (typec_altmode_vdm(adev, p[0], &p[1], cnt)) { > + response[0] = VDO(adev->svid, 1, > + CMD_EXIT_MODE); > + response[0] |= VDO_OPOS(adev->mode); > + return 1; > + } > } > return 0; > case CMD_EXIT_MODE: > - typec_altmode_update_active(pdev, false); > + if (adev && pdev) { > + typec_altmode_update_active(pdev, false); > > - /* Back to USB Operation */ > - WARN_ON(typec_altmode_notify(adev, TYPEC_STATE_USB, > - NULL)); > + /* Back to USB Operation */ > + WARN_ON(typec_altmode_notify(adev, > + TYPEC_STATE_USB, > + NULL)); > + } > break; > default: > break; > @@ -1171,8 +1178,10 @@ static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt, > switch (cmd) { > case CMD_ENTER_MODE: > /* Back to USB Operation */ > - WARN_ON(typec_altmode_notify(adev, TYPEC_STATE_USB, > - NULL)); > + if (adev) > + WARN_ON(typec_altmode_notify(adev, > + TYPEC_STATE_USB, > + NULL)); > break; > default: > break; > @@ -1183,7 +1192,8 @@ static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt, > } > > /* Informing the alternate mode drivers about everything */ > - typec_altmode_vdm(adev, p[0], &p[1], cnt); > + if (adev) > + typec_altmode_vdm(adev, p[0], &p[1], cnt); > > return rlen; > } >