From patchwork Mon Aug 13 02:34:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 1310841 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 2E81F3FC23 for ; Mon, 13 Aug 2012 02:35:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753118Ab2HMCfH (ORCPT ); Sun, 12 Aug 2012 22:35:07 -0400 Received: from cantor2.suse.de ([195.135.220.15]:55574 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752857Ab2HMCfG (ORCPT ); Sun, 12 Aug 2012 22:35:06 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id E28019FB23; Mon, 13 Aug 2012 04:35:03 +0200 (CEST) Date: Mon, 13 Aug 2012 12:34:53 +1000 From: NeilBrown To: balbi@ti.com Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: Infinite looping in omap2430.c USB driver Message-ID: <20120813123453.4cba14ca@notabene.brown> In-Reply-To: <20120809111549.GT12174@arwen.pp.htv.fi> References: <20120707083949.2cf91eeb@notabene.brown> <20120809111549.GT12174@arwen.pp.htv.fi> X-Mailer: Claws Mail 3.7.10 (GTK+ 2.24.7; x86_64-suse-linux-gnu) Mime-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org On Thu, 9 Aug 2012 14:15:51 +0300 Felipe Balbi wrote: > hehe, that's nasty. Please send a patch converting to a try count and a > udelay_range(), or something. > how's this? Thanks, NeilBrown From: NeilBrown Date: Mon, 13 Aug 2012 12:32:58 +1000 Subject: [PATCH] omap2430: don't loop indefinitely in interrupt. When called during resume_irqs, omap2430_musb_set_vbus() is run with interrupts disabled, In that case 'jiffies' never changes so the loop can loop forever. So impose a maximum loop count and add an 'mdelay' to ensure we wait a reasonable amount of time for bit to be cleared. This fixes a hang on resume. Signed-of-by: NeilBrown diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index c7785e8..8a93381 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "musb_core.h" #include "omap2430.h" @@ -145,6 +146,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on) if (is_on) { if (musb->xceiv->state == OTG_STATE_A_IDLE) { + int loops = 100; /* start the session */ devctl |= MUSB_DEVCTL_SESSION; musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); @@ -154,9 +156,11 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on) */ while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) { + mdelay(5); cpu_relax(); - if (time_after(jiffies, timeout)) { + if (time_after(jiffies, timeout) + || loops-- <= 0) { dev_err(musb->controller, "configured as A device timeout"); ret = -EINVAL;