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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BBE6DC46467 for ; Tue, 3 Jan 2023 17:35:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bTJPZLKyRXjIhdR7inO1L+QuCRARwM/gShCfxBaW0Sc=; b=2JgpDY3tdvQOxF HmU3XsIpQZgO7HLaUYchrXdGUjroH2TXFoo574xu6OKrFycuP2umjxPu9AjEl/2gUaGOsXzDa/U2l unco7ef2y/kst+qkI8DKB14k08uIoWVGDd/UIF1XbQGoNsTIbS1k6DwPynDwM4NfyDTmHPeXaNBPa MuFomWFanS4okEy8P+gfoRYhS3WeDIB/fko8EUvlkmcgoVsmmIwkRhBCSV2ZxBpbCEn61RDdNujw0 IWrzwWCgZar8/7v2lkWTOrRAZf5gt+d8J17tdCRc3a7mgaPnGb3wCR1FE1OKzo1vkwkvgsD7o2u6N jzyaWj4433j4iLT2C6Hg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pClBN-003SIv-Eq; Tue, 03 Jan 2023 17:34:39 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pCj9I-002PE7-Am for linux-arm-kernel@lists.infradead.org; Tue, 03 Jan 2023 15:24:22 +0000 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=oZxDj67clABGqk6QiAxQ1JKQPGByRK02SwvUmbeTMn8=; b=gREsp7c/pgSY0ZE4usD2NOCJHO oakwK+2yr6xyLWA/n6WwecO5MWP+So0e3jK4uW5vlVn4pnZt0N2jwyemoFxJVXLILwmBsYrduKlai enUaiwdeiyz6uUoiqTNYv9/mudm2i/Afu3QhEbpoHNc9ILJr5bMRnNabf8SvKIae57M0HbBEik2+v S5e1H7OiYX8cyXTzHGbsUxGC74L6l8G384u4ixpWRHEwsGPVCpET6914qx87Yeuxh9vi+xGDf5m65 NE5MARMnmmlVsn2LxdC6V5JAz1/va9m1E+ExWMRlMDtSC6iaUYxPyIA+ZEFIDpQAHLny6dRuYzggu b0JPYPBQ==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:35942) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pCj9F-0005Ux-SQ; Tue, 03 Jan 2023 15:24:17 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1pCj9E-0002Ak-C3; Tue, 03 Jan 2023 15:24:16 +0000 Date: Tue, 3 Jan 2023 15:24:16 +0000 From: "Russell King (Oracle)" To: Hector Martin Cc: Srinivas Kandagatla , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Maxime Ripard , Greg Kroah-Hartman Subject: Re: [PATCH v2] nvmem: fix registration vs use race Message-ID: References: <169464ed-34c2-08d3-efee-686c9a5eb15d@marcan.st> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <169464ed-34c2-08d3-efee-686c9a5eb15d@marcan.st> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230103_072420_538582_CC0FD7FA X-CRM114-Status: GOOD ( 24.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jan 04, 2023 at 12:20:15AM +0900, Hector Martin wrote: > On 03/01/2023 23.42, Russell King (Oracle) wrote: > > The i.MX6 CPU frequency driver sometimes fails to register at boot time > > due to nvmem_cell_read_u32() sporadically returning -ENOENT. > > > > This happens because there is a window where __nvmem_device_get() in > > of_nvmem_cell_get() is able to return the nvmem device, but as cells > > have been setup, nvmem_find_cell_entry_by_node() returns NULL. > > > > The occurs because the nvmem core registration code violates one of the > > fundamental principles of kernel programming: do not publish data > > structures before their setup is complete. > > > > Fix this by making nvmem core code conform with this principle. > > > > Fixes: eace75cfdcf7 ("nvmem: Add a simple NVMEM framework for nvmem providers") > > Signed-off-by: Russell King (Oracle) > > --- > > v2: add fixes tag > > > > drivers/nvmem/core.c | 18 ++++++++---------- > > 1 file changed, 8 insertions(+), 10 deletions(-) > > > > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > > index 321d7d63e068..6b89fb6fa582 100644 > > --- a/drivers/nvmem/core.c > > +++ b/drivers/nvmem/core.c > > @@ -835,22 +835,16 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) > > nvmem->dev.groups = nvmem_dev_groups; > > #endif > > > > - dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); > > - > > - rval = device_register(&nvmem->dev); > > - if (rval) > > - goto err_put_device; > > - > > if (nvmem->nkeepout) { > > rval = nvmem_validate_keepouts(nvmem); > > if (rval) > > - goto err_device_del; > > + goto err_put_device; > > You can't call put_device() on a device that hasn't gone through > device_initialize() yet. Right, which is what I just realised while writing the previous reply. We need to use device_initialize() and device_add(), so we can call put_device() on it. Error paths are difficult to properly test. :( -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel