From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9B30C433EF for ; Sat, 26 Mar 2022 12:49:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232991AbiCZMvJ (ORCPT ); Sat, 26 Mar 2022 08:51:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232568AbiCZMvJ (ORCPT ); Sat, 26 Mar 2022 08:51:09 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [185.16.172.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEF4D49F80 for ; Sat, 26 Mar 2022 05:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=IiOqQVqNDorSEOcIS0u9fYArgUgRXKoO1VlYQa/w7d4=; b=XihdTeNlJPlfCZSOd1MTwWZTt0 xcvVT0q/Io0zpxcr4a0dXplyUAuYtTXUMVt+CzfrWsjGdR9En0dlvQGJNULoEg7Z6MHVTLj8Znydc orQkasVEisqOeFsCGoZaDKczJZN7dzY2YGinfT3R17a4JFg0Wq28K4c+OoxahZCgZ4e4=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1nY5rE-00Clyb-C9; Sat, 26 Mar 2022 13:49:28 +0100 Date: Sat, 26 Mar 2022 13:49:28 +0100 From: Andrew Lunn To: Lukas Wunner Cc: Oleksij Rempel , Oliver Neukum , Oleksij Rempel , "netdev@vger.kernel.org" , Heiner Kallweit Subject: Re: ordering of call to unbind() in usbnet_disconnect Message-ID: References: <20220310113820.GG15680@pengutronix.de> <20220314184234.GA556@wunner.de> <20220315054403.GA14588@pengutronix.de> <20220315083234.GA27883@wunner.de> <20220315113841.GA22337@pengutronix.de> <20220321100226.GA19177@wunner.de> <20220326123929.GB31022@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220326123929.GB31022@wunner.de> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Sat, Mar 26, 2022 at 01:39:29PM +0100, Lukas Wunner wrote: > On Mon, Mar 21, 2022 at 02:10:27PM +0100, Andrew Lunn wrote: > > There are two patterns in use at the moment: > > > > 1) The phy is attached in open() and detached in close(). There is no > > danger of the netdev disappearing at this time. > > > > 2) The PHY is attached during probe, and detached during release. > > > > This second case is what is being used here in the USB code. This is > > also a common pattern for complex devices. In probe, you get all the > > components of a complex devices, stitch them together and then > > register the composite device. During release, you unregister the > > composite device, and then release all the components. Since this is a > > natural model, i think it should work. > > I've gone through all drivers and noticed that some of them use a variation > of pattern 2 which looks fishy: > > On probe, they first attach the PHY, then register the netdev. > On remove, they detach the PHY, then unregister the netdev. > > Is it legal to detach the PHY from a registered (potentially running) > netdev? It looks wrong to me. I think the network stack guarantee that the close() method is called before unregister completes. It is a common pattern to attach the PHY in open() and detach it in close(). The stack itself should not be using the PHY when it is down, the exception being IOCTL handlers which people often get wrong. So i don't think this is an issue. Andrew