Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5435242rdb; Wed, 13 Dec 2023 08:32:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IE3+zHhPjxkLUSIganuV+4YWrDWUckqOA6u00C6T75Sc9G/qtRjX3pyYma988B1IUAot54M X-Received: by 2002:a17:902:eb8e:b0:1d3:40f2:4340 with SMTP id q14-20020a170902eb8e00b001d340f24340mr1601166plg.127.1702485179624; Wed, 13 Dec 2023 08:32:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702485179; cv=none; d=google.com; s=arc-20160816; b=P+WQcUKdQZLT5mt/qtRZMtL9gB/FOTBOD/LT9W03rWajXAujZXGzlLD7Hm+4uwp0zC I+t2oFOMrL7FZubdmesEsAkhIX3ojWydJcr1DcwHQ1PkWRqJdq75h81/qQoaqpEfJsa/ GPNZ805JIyPw8C+A+hjJkvlM7kqZ3zScn13m8aH8OK/Nu0FG5yN6pqtFSC0pyDj7+9rW cXRNw+udaFr5srrdn+zo0pMvh3UpuROFQFdI/qig6ix5XSzxoNwokoOVAtgM4UVLxdUv cyxjSICzeZ49MCHBm1COFYppKrKQ6Myc48GZP6hKoUs6Xoq5qWz2Wg+1JA9ITwyubcfA WoiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=N/E28jRK/viDvwysZ67eINh1B/xnv1AANrAAo+m468A=; fh=0CjR/P59gkS3RoA1MzYD3TAB1GMUolY2z17tQE+puF0=; b=vkEqYcjxxfLvPkAbmiRQTS/zUwhFcGgjicpvjGDJheEfghyn7x2iL5To0HYrYVDEoK fbevtIwTP+ss3Y7kMQiUiWI1wLWDFPXWCF1vlN5FPq6dpzz9zvN4+nxl5pFNRbU4hK/J cbZWESQw4hR78GGJPJQ2aALPnEZJzlRkAPxeYxp3trzyd0ZwdK86RFWa/Y8B7ZLT09A8 y/EWmvptuYO2S+sNEHtEuOyPl/dRz84aBi5Oc1l3hb6voRLDNcWt2WuIU4fLh8Xd5+As XdPhwNUI0J/5JlKkPHni4zXJV5rFey7P5mKhKMVxEgiogR0wTihawrr65I+t3tuXg3cy kWiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=F9FacYpA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id c10-20020a170902d48a00b001d07126d233si10227966plg.564.2023.12.13.08.32.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 08:32:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=F9FacYpA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 07148808D696; Wed, 13 Dec 2023 08:32:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231638AbjLMQcn (ORCPT + 99 others); Wed, 13 Dec 2023 11:32:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230390AbjLMQcm (ORCPT ); Wed, 13 Dec 2023 11:32:42 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75F9E91; Wed, 13 Dec 2023 08:32:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=N/E28jRK/viDvwysZ67eINh1B/xnv1AANrAAo+m468A=; b=F9FacYpAvC8VBP83kNMIpHTuVL StsEhcooImqRL0oa7xdnDBllK6KkpkYTk4gTnuRIertAdiNTHp46DxpNDNkPXUyY+qmdUNEk+D1SA Y6EeaRQWlHQl0ztEkl4ENZhDEj2QYIJeIWfrxOu0/3+b4418i6lBBlF44tHLDS/PHuAaewGCrZFZO e/l1KFXkDC9rYxkwhe7qw3Vq8NOoXmrGZmZZxGEaWXG7UPAXtkBRH71zg7IecLdbT96sUJqvLbBTh bSZIRZgFS8fOdfUo0i+S0ewDHQU3lMDUgcCJ3dOOtUMa5WJS93cn8lz7MuT+uBAgeA26m9zUfusQ+ Q5lacQ0Q==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:59474) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rDS9o-0000HK-1N; Wed, 13 Dec 2023 16:32:24 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rDS9l-0001eT-VG; Wed, 13 Dec 2023 16:32:21 +0000 Date: Wed, 13 Dec 2023 16:32:21 +0000 From: "Russell King (Oracle)" To: Serge Semin Cc: Andrew Lunn , Heiner Kallweit , Alexandre Torgue , Jose Abreu , Jose Abreu , Maxime Chevallier , Tomer Maimon , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next 06/16] net: pcs: xpcs: Avoid creating dummy XPCS MDIO device Message-ID: References: <20231205103559.9605-1-fancer.lancer@gmail.com> <20231205103559.9605-7-fancer.lancer@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Russell King (Oracle) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 13 Dec 2023 08:32:57 -0800 (PST) On Wed, Dec 13, 2023 at 03:01:45AM +0300, Serge Semin wrote: > On Tue, Dec 05, 2023 at 01:46:44PM +0000, Russell King (Oracle) wrote: > > xpcs_create_mdiodev() as it originally stood creates the mdiodev from > > the bus/address, and then passes that to xpcs_create(). Once > > xpcs_create() has finished its work (irrespective of whether it was > > successful or not) we're done with the mdiodev in this function, so > > the reference is _always_ put. > > You say that it's required to manage the refcounting twice: when we > get the reference from some external place and internally when the > reference is stored in the XPCS descriptor. What's the point in such > redundancy with the internal ref-counting if we know that the pointer > can be safely stored and utilized afterwards? Better maintainability? > Is it due to having the object retrieval and storing implemented in > different functions? The point is that the error handling gets simpler: - One can see in xpcs_create_mdiodev() that the reference taken by mdio_device_create() is always dropped if that function was successful, irrespective of whether xpcs_create() was successful. - xpcs_create() is responsible for managing the refcount on the mdiodev that is passed to it - and if it's successful, it needs to increment the refcount, or leave it in the same state as it was on entry if failing. This avoids complexities in error paths, which are notorious for things being forgotten - since with this, each of these functions is resposible for managing its refcount. It's a different style of refcount management, one I think more people should adopt. > While at it if you happen to know an answer could you please also > clarify the next question. None of the ordinary > platform/PCI/USB/hwmon/etc drivers I've been working with managed > refcounting on storing a passed to probe() device pointer in the > private driver data. Is it wrong not doing that? If we wanted to do refcounting strictly, then every time a new pointer to a data structure is created, we should be taking a refcount on it, and each time that pointer is destroyed, we should be putting the refcount. That is what refcounting is all about. However, there are circumstances where this can be done lazily, and for drivers we would prefer driver authors not to end up with refcount errors where they've forgotten to put something. In the specific case of drivers, we have a well defined lifetime for a device bound to a driver. We guarantee that the struct device will not go away if a driver is bound to the device, until such time that the driver's .remove method has been called. Thus, we guarantee that the device driver will be notified of the struct device going away before it has been freed. This frees the driver author from having to worry about the refcount of the struct device. As soon as we start doing stuff that is outside of that model, then objects that are refcounted need to be dealt with, and I much prefer the "strict" refcounting implementation such as the one I added to xpcs, because IMHO it's much easier to see that the flow is obviously correct - even if it does need a comment to describe why we always do a put. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!