Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754884AbcC3Wpb (ORCPT ); Wed, 30 Mar 2016 18:45:31 -0400 Received: from us01smtprelay-2.synopsys.com ([198.182.60.111]:34637 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751430AbcC3Wpa (ORCPT ); Wed, 30 Mar 2016 18:45:30 -0400 Subject: Re: [PATCH] usb: dwc2: gadget: avoid null dereference on incomplete transfer To: Felipe Balbi , John Keeping , John Youn References: <1457983214-4317-1-git-send-email-john@metanate.com> <87k2kkhzk1.fsf@intel.com> From: John Youn CC: Greg Kroah-Hartman , , Message-ID: <56FC5707.80601@synopsys.com> Date: Wed, 30 Mar 2016 15:45:27 -0700 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <87k2kkhzk1.fsf@intel.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.9.139.66] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2150 Lines: 62 On 3/30/2016 6:22 AM, Felipe Balbi wrote: > > Hi, > > John Keeping writes: >> Setting up a gadget with the uac2 function results in: >> >> Unable to handle kernel NULL pointer dereference at virtual address 00000058 >> ... >> PC is at dwc2_hsotg_irq+0x7f0/0x908 >> LR is at dwc2_hsotg_irq+0x4c/0x908 >> Backtrace: >> [] (dwc2_hsotg_irq) from [] (handle_irq_event_percpu+0x130/0x3ec) >> [] (handle_irq_event_percpu) from [] (handle_irq_event+0x48/0x6c) >> >> In all other loops we already skip endpoints that are null, so do so >> here as well. >> >> Signed-off-by: John Keeping >> --- >> drivers/usb/dwc2/gadget.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c >> index 0abf73c..df43ec0 100644 >> --- a/drivers/usb/dwc2/gadget.c >> +++ b/drivers/usb/dwc2/gadget.c >> @@ -2606,7 +2606,9 @@ irq_retry: >> for (idx = 1; idx < hsotg->num_of_eps; idx++) { >> hs_ep = hsotg->eps_in[idx]; >> >> - if (!hs_ep->isochronous || hs_ep->has_correct_parity) >> + if (!hs_ep || >> + !hs_ep->isochronous || >> + hs_ep->has_correct_parity) > > this is fine (even though choice of where to break line is a bit odd), > but I have a question about how the rest of the code works (a bit > off-topic, sorry) > >> continue; >> >> epctl_reg = DIEPCTL(idx); > > So, this means that the first ISO endpoint without correct parity will > be used. Isn't this a bit fragile ? What happens when you use a device > with several different interfaces using several different endpoints ? > > Isn't there a register where we can check which physical endpoint > generated the IRQ ? Seems like you really wanna check what: > We discussed this back when the patch was first submitted and determined it should work fine like this. I don't remember exactly why though. But this ISOC parity stuff is a workaround and we have a series of patches to correctly set up ISOC allowing us to remove it. We're doing some final tests before we send them. Regards, John