From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by smtp.subspace.kernel.org (Postfix) with SMTP id D527452F6F for ; Fri, 19 Jan 2024 16:22:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.131.102.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705681348; cv=none; b=PbDk+JkvJo9hm3RolRnYAULkXmt/bipnDV+gzQWHVr2krXNEO4Xn5D5P84EQFzub65TEVBYkaSdmW8FQ0XcUye7ZHMivCzipUsPPqWVl0jJelWY+Te1LWj+/5FA9vAetHm34OhGRR5CPWJUOikz1DqNmNftK9WgSRjw9kr0gqIg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705681348; c=relaxed/simple; bh=N3nDl66knVvipxA6CSmaXfX6Ic9CiIDzcAuWh5t6NIE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KXGn+YZdN5PVDSPWD7cMJf6e2ufzbBePOU1xK/7rzROY8gpAPy+2se3Msy+3dwBgXcwWYKcH0DspQCjVg0bhQs3tonfcT0io35lGTjtjYDmt1yFrgoCKevrJu/oidFHZDIPSrQIYivvX6/zIYjzHr4YMwSkiugtsOaj47kB6HDA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=rowland.harvard.edu; spf=pass smtp.mailfrom=netrider.rowland.org; arc=none smtp.client-ip=192.131.102.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=rowland.harvard.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netrider.rowland.org Received: (qmail 44291 invoked by uid 1000); 19 Jan 2024 11:22:19 -0500 Date: Fri, 19 Jan 2024 11:22:19 -0500 From: Alan Stern To: Xu Yang Cc: Greg KH , Heikki Krogerus , "benjamin.tissoires@redhat.com" , "hdegoede@redhat.com" , "ivan.orlov0322@gmail.com" , "linux-usb@vger.kernel.org" , dl-linux-imx , Jun Li Subject: Re: [EXT] Re: [PATCH] usb: roles: try to get/put all relevant modules Message-ID: <2d25ce4a-13e4-4ec7-b762-e5de56ff4bf5@rowland.harvard.edu> References: <2024011801-chewer-coastline-a16f@gregkh> <2024011842-harpist-password-b965@gregkh> <5a16bd56-52f7-4ea0-a2bb-f83fe0e710a7@rowland.harvard.edu> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Jan 19, 2024 at 03:23:50PM +0000, Xu Yang wrote: > > What happens if the provider module is unloaded but then > > usb_role_switch_put() is called after usb_role_switch_unregister()? > > Won't there be a NULL pointer dereference inside the put_device() call? > > The get_device() will be called after the user successfully get usb_role_switch > device. So the resource of sw will continue to exist until usb_role_switch_put() > is called. But look: Your patch essentially prevents usb_role_switch_set_role() from running after the role-switch device has been unregistered. But what if someone had already called usb_role_switch_set_role() before the device was unregistered? Won't that eventually lead to problems if the provider's module is then unloaded from memory? To put it another way, all those try_module_get() and module_put() calls were originally added to prevent a specific problem from occurring. Once you remove them, won't that problem be able to occur again? Alan Stern