Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp12012883rwl; Tue, 3 Jan 2023 07:51:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXv0koBwCwOCbXy9+LgcXf4b7faVOjUCYHPgcbEvHgGVYk8xD3dgq3skaeJwkMbNsGsRkQN5 X-Received: by 2002:a17:907:7f04:b0:7c0:a4e9:615b with SMTP id qf4-20020a1709077f0400b007c0a4e9615bmr48475803ejc.61.1672761103271; Tue, 03 Jan 2023 07:51:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672761103; cv=none; d=google.com; s=arc-20160816; b=hqR9dBYQZMG0yMnlEZFJyKsIxKhv2enczjUGpeMBWTEvaCPiFmXPHAINCe9R49TutH AMcB2Hrob8k4BmOPK9ExZlZ1Ada/IU7qO6c+JDWgr8aoZXVkR2ZyTBrtkvydPRuKlTYh PBGcCUhYeBiCwiT/IvUIL2UQLQhNsNtUy9sxdN/1XffOtJOswI0dnrvt2Ez7GRADZPLB H1o6PCYVs4ch1hUrHE0NVdIRp8wY4CcfMn0mVJkTzNaoRE6Q4S9ZLPcpl5UsvQQl7lSa sKS87wcuz+ZGRsFvhso+8eiRXfO10vyBpoYtZ89rSPkPDyeqCVe+nu3IYrEA88q+tLlt 8EqA== 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=oZxDj67clABGqk6QiAxQ1JKQPGByRK02SwvUmbeTMn8=; b=Txx71wP3/u1TUsrZ73P/2bUW1rHzhaTPKTNLg2yWNWdoiQioWtDpTQojIIjsNubDPP PMMGu29CdbV7rQWwL74nUti5R+tLG2LLddqeoPwXxTfPZIaTtP7bnnfP4RAQ0LtcnRVD kmzzttW8pCXmg5CUk0ymbcEfoG93oMQT27t2z0f6vyGTlode2jRsVHVdZ5K5NMcNA/h/ VLzqo3ZHKfunF4aqiuwKSSG47TiP5RYIJuQZyK0X74B3BhS9k/Xovqej9qogge1ZVDaU XQurkGyeGTepEUZ1bJ2L0ndqMwtUyeg9eEand7dQLeQV+6G7vtThZ+uyo81m1bsU7Mgk yJEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b="gREsp7c/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a056402128400b00488d21b9fa6si13352481edv.159.2023.01.03.07.51.29; Tue, 03 Jan 2023 07:51:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b="gREsp7c/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233398AbjACPYW (ORCPT + 60 others); Tue, 3 Jan 2023 10:24:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233189AbjACPYV (ORCPT ); Tue, 3 Jan 2023 10:24:21 -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 5155C25F0 for ; Tue, 3 Jan 2023 07:24:20 -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=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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <169464ed-34c2-08d3-efee-686c9a5eb15d@marcan.st> Sender: Russell King (Oracle) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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!