Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2051743pxy; Mon, 2 Aug 2021 17:58:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyumDvSGSnSqKYwiIpSBIkP4tc2uMhgEUeNRx7n7Kyvc3iXsgRzrBXGI45m4BIJw3bfB6VC X-Received: by 2002:a02:866b:: with SMTP id e98mr17491534jai.48.1627952324816; Mon, 02 Aug 2021 17:58:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627952324; cv=none; d=google.com; s=arc-20160816; b=luvGOT/pe8zGoZBcPZEBGQ7kLB/QANpJuxa/LdxL9de3GV6XjYy7XSWTsGFhb+Yc2V 1BYOlQUvNNQl9Ny1rqWPUs+65I+qQNoPTx6+X1sk0B5TN6Ly7LcxYHpG4JPRfw4jcgJy SAng7JlNeZYwDUqtqnqbWHrl8sX3vYAq24AuhG1FR/c8Wau474oS31cqDCuyvbEP2Dyg d7WPSYPWzQtdSdA5xGZ1V1AhyhjxkMhUQZxHoBgi/jdXXvM9SZnRHWHh9Jx+YlfE6l8v OXLRdBN4JtTKIrRlrQnBqA3EL0DZX66Y+r/9ZWYJrCBjWBv3YXl7+1Q38eKm1ScyuThv rqWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=cGncO0Cvb3vYPo8Zdg999560Asr8IFWGV6afJV+4FxE=; b=Tclityq3M2RlUFQMyOfwJ+s07EbMMZFangUrErdWI7gFO2ek/+swj2VDgcQ8ZEEXKh JmiaDxNXfpmiW+A+zTz/dWiqlEVgKxaQOPHk86rZRxVCYpjw8jNCTrgLjCFA1MEQaGlT R9KeA/7AvARlAJWtDObxLetHkbj6338NLnww8CkudviRo5ueTmrSdTo8E1Sgpp1krMIi 2XaacF4s4H/DmEWhb0iZXQf/BBOuse9u2aHVagfMmTBdwS7bcdR7CxgWqkOuEvFzSwYy mmGBvgmQ6VGn0q614Vmxy0o9F2StS8RkuIKk7Mm8CD3x92U2BewuXFA+cK1s8qhcDk0n HpwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u12si12915330iot.101.2021.08.02.17.58.32; Mon, 02 Aug 2021 17:58:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233195AbhHCA4l (ORCPT + 99 others); Mon, 2 Aug 2021 20:56:41 -0400 Received: from netrider.rowland.org ([192.131.102.5]:44559 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S232798AbhHCA4j (ORCPT ); Mon, 2 Aug 2021 20:56:39 -0400 Received: (qmail 350279 invoked by uid 1000); 2 Aug 2021 20:56:28 -0400 Date: Mon, 2 Aug 2021 20:56:28 -0400 From: Alan Stern To: Salah Triki Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: storage: realtek_cr: get lock before calling usb_enable_autosuspend() Message-ID: <20210803005628.GA349864@rowland.harvard.edu> References: <20210802230313.GA1480457@pc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210802230313.GA1480457@pc> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 03, 2021 at 12:03:13AM +0100, Salah Triki wrote: > Based on the documentation of usb_enable_autosuspend(), the > caller must hold udev's device lock. > > Signed-off-by: Salah Triki > --- > drivers/usb/storage/realtek_cr.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c > index 3789698d9d3c..6948d6fdad39 100644 > --- a/drivers/usb/storage/realtek_cr.c > +++ b/drivers/usb/storage/realtek_cr.c > @@ -918,9 +918,13 @@ static int realtek_cr_autosuspend_setup(struct us_data *us) > timer_setup(&chip->rts51x_suspend_timer, rts51x_suspend_timer_fn, 0); > fw5895_init(us); > > + usb_lock_device(us->pusb_dev); > + > /* enable autosuspend function of the usb device */ > usb_enable_autosuspend(us->pusb_dev); > > + usb_unlock_device(us->pusb_dev); > + > return 0; > } > #endif I assume you didn't test this patch, because RTS51xx card readers aren't very common. If you had tested it, you would have found that it causes the system to hang. This is because when realtek_cr_autosuspend_setup runs, the driver already holds the device lock. The route is a little circuitous: realtek_cr_probe is called with the lock held, like all probe routines. It calls usb_store_probe2, which calls usb_stor_acquire_resources. That routine calls us->unusual_dev->initFunction. For the realtek_cr driver, the initFunction is set to init_realtek_cr (see unusual_realtek.h). init_realtek_cr calls realtek_cr_autosuspend_setup. There is no other pathway to the usb_enable_autosuspend call. So your patch is not needed. Alan Stern