Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753390AbdFMQCN (ORCPT ); Tue, 13 Jun 2017 12:02:13 -0400 Received: from mail-yb0-f169.google.com ([209.85.213.169]:35849 "EHLO mail-yb0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751826AbdFMQCL (ORCPT ); Tue, 13 Jun 2017 12:02:11 -0400 MIME-Version: 1.0 In-Reply-To: References: From: Tal Shorer Date: Tue, 13 Jun 2017 19:02:10 +0300 Message-ID: Subject: Re: gadgetfs: how to wait for USB device initialization? To: Andrey Konovalov Cc: Felipe Balbi , Greg Kroah-Hartman , Alan Stern , Kees Cook , Andrew Morton , Elena Reshetova , USB list , LKML , syzkaller , Dmitry Vyukov , Kostya Serebryany Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 926 Lines: 25 On Tue, Jun 13, 2017 at 3:21 PM, Andrey Konovalov wrote: > Hi! > > I'm trying to use gadgetfs to fuzz USB device drivers by simply > connecting random devices for now. > > What I want to achieve right now is the following: > > 1. mount gadgetfs > 2. emulate connection of a new USB device > 3. wait for the device to finish initializing > 4. unmount gadgetfs > 5. goto 1 > > The question is how do I wait for the device to finish initializing > (the corresponding USB driver to finish probing?) before unmounting > gadgetfs? As I understand, when I write device description to > "/dev/gadget/dummy_udc" the initialization happens asynchronously > after writing is done. > You can use inotify on the state file inside a udc's sysfs directory. It's awesome like that. Here's a sample code that doesn't do any cleanups because I'm lazy: https://gist.github.com/talshorer/61be1bc3472cc2a7b4866b9bd5a239ca