Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp622236imm; Fri, 29 Jun 2018 03:44:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKItuyYz0HoNd9O9Au3jemmO1qDxGUdzuB3/Ltp4ro3HzEz6yN+ZKsyghyfPQULnvRKP2B3x X-Received: by 2002:a63:3190:: with SMTP id x138-v6mr12160138pgx.60.1530269094947; Fri, 29 Jun 2018 03:44:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530269094; cv=none; d=google.com; s=arc-20160816; b=kGFeFviWHtWkJ0BYWaheheIRZujNkP1j1aMFFiWqsnGeUZ8mhzmlnR2UsLKjI5rR65 SbBHcUAV4f3nBrGF69gH49I4D5lvy9jXG9yXSrWuGRdfGCx6v1ZJjk7aK5T47F/B/cNv eZSlk4u7NPNqTQNJUo/X6JwQj4Vz3ldSxjoTom1hiv+Q9jWEOjbP3qhfM9KBfnGUUNt3 b1lFu5OYI7CHMmLsyVmIkn3By86jYketgxVrVEA8R59WPB7Idp3Jnd7eQVJGwFc5mywR J/p++T0dPNPqYP156HQcwuBri686EBIQv2vfXuKseGdcKCDgrE58EMtwdOTnjeJGS8OA JPmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:arc-authentication-results; bh=lZbXsSO6IzEngdHZ0QdbcWRxIwN5OZpNZ0a8qwXC7Jw=; b=HX1f/d3p36xMbWV2mjksdXLJK96X21qMlK0NL3pF/zTCAXmBsTIVpjS2KmlqqKPh7T /jOiyRNCwf0v1QQC6Ly04w9jjDOocmEDXvH2EwHPoscE4Z2qYYwTB4ylT9R+TRH2fupP PbSiMT2j+RD6af9Xd4Pi5cSpv/1D5Rpgp+nTHDYMxWSlqft/EZJEm09txmQYDrXroMry R2RJOcKbxijadf10F8gq1/nATopqAPA4mBWOGWEXDZGkECENRA1GLVhA+lEM0UzRkiN2 7l5g0Hs9Fs8bDkEehe0rMpJJ7TrhslHKrr3yDNSblkYUZuYCN5ULQ1zKfXYZaHhd9/vH N05Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 190-v6si5841027pfe.136.2018.06.29.03.44.40; Fri, 29 Jun 2018 03:44:54 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935326AbeF2K1k (ORCPT + 99 others); Fri, 29 Jun 2018 06:27:40 -0400 Received: from mga14.intel.com ([192.55.52.115]:64569 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932468AbeF2K1j (ORCPT ); Fri, 29 Jun 2018 06:27:39 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jun 2018 03:27:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,285,1526367600"; d="scan'208";a="62562992" Received: from pipin.fi.intel.com (HELO localhost) ([10.237.68.37]) by fmsmga002.fm.intel.com with ESMTP; 29 Jun 2018 03:27:37 -0700 From: Felipe Balbi To: Robert Jarzmik Cc: Jia-Ju Bai , gregkh@linuxfoundation.org, nicolas.ferre@microchip.com, keescook@chromium.org, allen.lkml@gmail.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] usb: gadget: r8a66597: Fix two possible sleep-in-atomic-context bugs in init_controller() In-Reply-To: <87efgqkrzl.fsf@belgarion.home> References: <20180620035453.7721-1-baijiaju1990@gmail.com> <87efh0o6f9.fsf@belgarion.home> <87y3eydrs1.fsf@linux.intel.com> <87efgqkrzl.fsf@belgarion.home> Date: Fri, 29 Jun 2018 13:25:02 +0300 Message-ID: <87k1qhevpd.fsf@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Robert Jarzmik writes: >>>> The driver may sleep with holding a spinlock. >>>> The function call paths (from bottom to top) in Linux-4.16.7 are: >>>> >>>> [FUNC] msleep >>>> drivers/usb/gadget/udc/r8a66597-udc.c, 839: >>>> msleep in init_controller >>>> drivers/usb/gadget/udc/r8a66597-udc.c, 96: >>>> init_controller in r8a66597_usb_disconnect >>>> drivers/usb/gadget/udc/r8a66597-udc.c, 93: >>>> spin_lock in r8a66597_usb_disconnect >>> >>> That should not happen... >>> >>> If think the issue you have is that your usb_connect() and usb_disconnect() are >>> called from interrupt context. I think the proper fix, as what is done in most >>> udc phys, is to schedule a workqueue, see drivers/usb/phy/phy-gpio-vbus-usb.c, >>> gpio_vbus_data.vbus. >> >> argh, no. No workqueues needed here. Sorry > Technically why ? well, strictly technically there's nothing wrong. But it opens a can of worms. We've seen time and time again drivers growing into unmaintainable mess because of workqueues being fired in several places. > > And as bonus question, why is it better to have mdelay() calls in the driver ? As a bugfix, it's the smallest fix possible, right? Ideally, we wouldn't need either of them. Perhaps there's a bit which can be polled instead? Looking at the code again, it looks like that's messing with controller's clock and PLL; seems like it should've been done with CCF anyway. -- balbi