From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BD1D606EE95 for ; Sat, 7 Nov 2026 10:16:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=TFGf85E+; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=iPO3Q8az 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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=liX6+t4PoxGLp/jkCESZSQ7x8N9jECwGG4zYgbb4NkM=; b=TFGf85E+s7UQWXeB4qgYZZ1wK/ skWr/3HKKqiKjX8upMfBaiAqhG+YeqsSQSlqFS5vRP2tvhnunjGFMo/1gDfQAFIsV0kpaLHE5biIV XZhFdZlvZGj4Szw0uSrUr2F9DmQ4hkLrm1TimLFn9oom+8lRVfKwIiRYkh84GnoW5+ic9t1Cr5Xli l0rh9QYfsHcpHgujoQoqbYWdbAot7b5cMEfj8DSJF3uU+RQKk8OZn2cXTvMixZYZU4U6Mc3ajG4// V8PMJ01SXbiFJZSAGp5jW5u5kEoQ7DNNg2QQh9efGBcyBdtD4auyt4WIu6LX3Znv32cNbZ6Du9NMK Wf8aAa6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xPdTR-0000000ESjs-2RTp; Sat, 07 Nov 2026 10:16:37 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xPdTL-0000000ESbU-14Rw for linux-amlogic@lists.infradead.org; Sat, 07 Nov 2026 10:16:34 +0000 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-854b6e2e41fso752566a34.3 for ; Sat, 07 Nov 2026 02:16:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794046590; x=1794651390; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Ir8ocEsY2ITCHB73OM8DOt1TO1FexBL3HI8zDqPQjm4=; b=iPO3Q8aznChSpbcpayKtlbfZXNvfZq4VMtCS3eo0vnmpnKwkHavHMfZx4HF9zx2HHW I6aOmVmuWtFT/xu8LmPvXh5gPsBLKpWPopARnH9e+UfWdlgD1Co8ufxgaFxVZILQ4VmA 7IIu0/MgXm/NR1FmOZfk0IY4nRn3KT9Lk3hgsccgArlDGINEEXPus28sY9xFvif6jjhg VezBJzoDlRyt8opUKaNdluFd+kiW6meY18pPVaU+h5lzHDeHplcOYTLk4BdqTxI7rX6/ /uGs2FQ43KzBPwDf10CMDrVABN3JFL7KJ8LMcEQq4pH5C8vPBskPlTUXlPJXxEyYQ6Ec Snrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794046590; x=1794651390; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Ir8ocEsY2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zypPLy0xJLIjqjH6dg7YO4vdw+ZDdmYGTBExi1g8QucPsykBlnf43tYftAlRiWNV2Tq N5r25r+XZwD1IuUtbeDiQgGRa/wvbsP3ak4hC5VzFHHrtaLNf56BTbalYajAn5r3f2afFMkWGs8 bOPNoJnZNn96vGe10IjXgC4F3HZ5CfRCJ5Qaqd3cd1clvlU/Jy4qLHw3aR2c5WFIQaOsWjNCKTJ ELB1GaeG97AmVZv5tbBi1AF5FQvoK4OTn6mgOcYZwK3nKjoXeBate9JHS5dguuUw22hiOeeSbV9 G4bz1ooyWh4FQefB8q4zf3TE+sleITbEvLjtWLrQZ40RHLJRytZvc+ X-Received: by 2002:a05:6830:4c05:b0:822:e9bf:6445 with SMTP id 46e09a7af769-85f1cf838e3mr5603674a34.9.1794046590411; Sat, 07 Nov 2026 02:16:30 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-85f1dbef224sm3990269a34.12.2026.11.07.02.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Nov 2026 02:16:29 -0800 (PST) From: James Hilliard Date: Sat, 07 Nov 2026 03:15:59 -0700 Subject: [PATCH 02/58] nvmem: retain provider context through final device release X-Archived-By: MIME-Version: 1.0 Message-Id: <20261107-submit-rawnand-retained-handle-lifetime-v1-v1-2-0181ef0cc4c8@gmail.com> References: <20261107-submit-rawnand-retained-handle-lifetime-v1-v1-0-0181ef0cc4c8@gmail.com> In-Reply-To: <20261107-submit-rawnand-retained-handle-lifetime-v1-v1-0-0181ef0cc4c8@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Brian Norris , Boris Brezillon , Arseniy Krasnov , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Thomas Gleixner , Vitaly Wool , David Woodhouse , Russell King , David Woodhouse , Mike Rapoport , Maxime Coquelin , Alexandre Torgue , Christophe Kerello , Jason Roberts , Michal Simek , Boris Brezillon , Mason Yang , Ramuthevar Vadivel Murugan , Stefan Agner , Lucas Stach , Thierry Reding , Jonathan Hunter , Dmitry Osipenko , Matthias Brugger , AngeloGioacchino Del Regno , Jorge Ramirez-Ortiz , Heiko Stuebner , Yifeng Zhao , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Keguang Zhang , Jacky Huang , Shan-Chun Hung , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Han Xu , Liang Yang , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Manivannan Sadhasivam , Kamal Dasu , Broadcom internal kernel review list , Vladimir Zapolskiy , Piotr Wojtaszczyk , Paul Cercueil , Harvey Hunt , Maxim Levitsky , Michael Walle , Srinivas Kandagatla Cc: Tze Yee Ng , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-mips@vger.kernel.org, imx@lists.linux.dev, linux-renesas-soc@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-msm@vger.kernel.org, James Hilliard X-Mailer: b4 0.15.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261107_021631_912338_49052E1F X-CRM114-Status: GOOD ( 18.18 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-amlogic" X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 An NVMEM provider can keep its read/write context in an object separate from its parent device. Retaining the parent does not keep that object alive, and nvmem_unregister() can return while consumers still hold the provider. A device reference can also delay release after the last consumer is gone. Add optional paired callbacks to take a reference to the private context before publishing the provider and drop it from the final device release callback. Balance the reference on registration errors as well. Require both callbacks together and document the associated module lifetime requirement. MTD OTP providers need this ownership because they are children of the physical flash device, while their callback context is the separately allocated MTD master. Signed-off-by: James Hilliard --- drivers/nvmem/core.c | 12 +++++++++++- drivers/nvmem/internals.h | 1 + include/linux/nvmem-provider.h | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 0556d140170a..851fa5cabecb 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -541,6 +541,8 @@ static void nvmem_release(struct device *dev) ida_free(&nvmem_ida, nvmem->id); gpiod_put(nvmem->wp_gpio); + if (nvmem->ops->priv_put) + nvmem->ops->priv_put(nvmem->priv); kfree(nvmem->ops); kfree(nvmem); } @@ -896,6 +898,9 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (!config->reg_read && !config->reg_write) return ERR_PTR(-EINVAL); + if (!!config->priv_get != !!config->priv_put) + return ERR_PTR(-EINVAL); + nvmem = kzalloc_obj(*nvmem); if (!nvmem) return ERR_PTR(-ENOMEM); @@ -922,6 +927,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) device_initialize(&nvmem->dev); + nvmem->priv = config->priv; + if (config->priv_get) { + config->priv_get(config->priv); + ops->priv_put = config->priv_put; + } + if (!config->ignore_wp) nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", GPIOD_OUT_HIGH); @@ -945,7 +956,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->word_size = config->word_size ?: 1; nvmem->size = config->size; nvmem->root_only = config->root_only; - nvmem->priv = config->priv; nvmem->type = config->type; nvmem->keepout = config->keepout; nvmem->nkeepout = config->nkeepout; diff --git a/drivers/nvmem/internals.h b/drivers/nvmem/internals.h index 4e610deeaa7b..dcf5d81ca1b9 100644 --- a/drivers/nvmem/internals.h +++ b/drivers/nvmem/internals.h @@ -11,6 +11,7 @@ struct nvmem_operations { nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; + void (*priv_put)(void *priv); }; struct nvmem_device { diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 6063fe5b7784..03e8522bab17 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -98,6 +98,8 @@ struct nvmem_cell_info { * @word_size: Minimum read/write access granularity. * @stride: Minimum read/write access stride. * @priv: User context passed to read/write callbacks. + * @priv_get: Optional callback taking a reference to @priv before publication. + * @priv_put: Matching callback releasing @priv at final device release. * @ignore_wp: Write Protect pin is managed by the provider. * @layout: Fixed layout associated with this nvmem device. * @@ -107,6 +109,12 @@ struct nvmem_cell_info { * * Note: Specifying name and setting id to -1 implies a unique device * whose name is provided as-is (kept unaltered). + * + * Note: @priv_get and @priv_put must be supplied together. Each @priv_get + * call is balanced by one @priv_put, including on registration failure. + * The put can run after nvmem_unregister() returns, when consumers and + * device references have gone away. These callbacks must also retain any + * module needed to execute @priv_put until it returns. */ struct nvmem_config { struct device *dev; @@ -132,6 +140,8 @@ struct nvmem_config { int word_size; int stride; void *priv; + void (*priv_get)(void *priv); + void (*priv_put)(void *priv); /* To be only used by old driver/misc/eeprom drivers */ bool compat; struct device *base_dev; -- 2.53.0 _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic