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 AEB29C44510 for ; Wed, 15 Jul 2026 19:55:42 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OWy0AnI3JQRbHyRpJ1f0gmnsYu3zNd0MvjP9Wld7epo=; b=vkktS5GzHNUfDE jcLiZyvt4kIrdY3bn78HhYnO+PbgYdKOEApwdRd6j7R5zE+NREHkMMU5T7lySdO27Gyb/2j/SBxPy uVJsjo6Wsa2/y4gqq9jsIiMog0EAtZNQBpg2F4M7mg8mfnsj+lyZfBWkOm5NWaUqlfvRUlMt5H8yi k0EBiblTvzL5UbzeFV0XyudAZoxX4UgCNXljPsZleDVV1iOhpKo4gmEIltL4ZcKwEVcZFrfj18SA+ 6pmyIo13d3/5RwzhhqOnBlOmgmOSocs/tJMdVV+YwpltPtz6IqeYKLf8yjD7jGtxBE4N/tF6ygF/l pwuRXHe0zjAV5s+v4lpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wk5hj-0000000FpbH-2tH6; Wed, 15 Jul 2026 19:55:39 +0000 Received: from [2a01:e0a:1040:9780:49:5ff:fe41:d261] (helo=luna.linkmauve.fr) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wk5hg-0000000FpYC-1G9Z; Wed, 15 Jul 2026 19:55:38 +0000 Received: by luna.linkmauve.fr (Postfix, from userid 1000) id EC76DF40D2F; Wed, 15 Jul 2026 21:55:24 +0200 (CEST) From: Link Mauve To: Srinivas Kandagatla Cc: Link Mauve , Andy Shevchenko , Sven Peter , Janne Grunau , Neal Gompa , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Vladimir Zapolskiy , =?UTF-8?q?Andr=C3=A9=20Draszik?= , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Orson Zhai , Baolin Wang , Chunyan Zhang , Maxime Coquelin , Alexandre Torgue , Kalyani Akula , Michal Simek , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?UTF-8?q?Onur=20=C3=96zkan?= , asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-amlogic@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, rust-for-linux@vger.kernel.org Subject: [PATCH v2 1/2] nvmem: core: deprecate reg_write callback and add reg_write_const Date: Wed, 15 Jul 2026 21:55:17 +0200 Message-ID: <20260715195520.25410-2-linkmauve@linkmauve.fr> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260715195520.25410-1-linkmauve@linkmauve.fr> References: <20260715195520.25410-1-linkmauve@linkmauve.fr> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260715_125537_072266_200750FD X-CRM114-Status: GOOD ( 19.44 ) X-BeenThere: linux-amlogic@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-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org This callback used to take a mutable void * for no reason, which causes the compiler to be unaware that the val buffer should never be modified by the callback. This was found while drafting the nvmem-provider Rust abstraction. Signed-off-by: Link Mauve --- drivers/nvmem/core.c | 26 +++++++++++++++++--------- drivers/nvmem/internals.h | 1 + include/linux/nvmem-provider.h | 6 +++++- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index e871181751f3..24c9e6f953c6 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -62,13 +62,20 @@ static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, } static int __nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset, - void *val, size_t bytes) + const void *val, size_t bytes) { int ret; + if (nvmem->reg_write_const) { + gpiod_set_value_cansleep(nvmem->wp_gpio, 0); + ret = nvmem->reg_write_const(nvmem->priv, offset, val, bytes); + gpiod_set_value_cansleep(nvmem->wp_gpio, 1); + return ret; + } + if (nvmem->reg_write) { gpiod_set_value_cansleep(nvmem->wp_gpio, 0); - ret = nvmem->reg_write(nvmem->priv, offset, val, bytes); + ret = nvmem->reg_write(nvmem->priv, offset, (void *)val, bytes); gpiod_set_value_cansleep(nvmem->wp_gpio, 1); return ret; } @@ -264,7 +271,7 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj, count = round_down(count, nvmem->word_size); - if (!nvmem->reg_write || nvmem->read_only) + if (!nvmem->reg_write || !nvmem->reg_write_const || nvmem->read_only) return -EPERM; rc = nvmem_reg_write(nvmem, pos, buf, count); @@ -285,7 +292,7 @@ static umode_t nvmem_bin_attr_get_umode(struct nvmem_device *nvmem) if (!nvmem->read_only) mode |= 0200; - if (!nvmem->reg_write) + if (!nvmem->reg_write || !nvmem->reg_write_const) mode &= ~0200; if (!nvmem->reg_read) @@ -321,13 +328,13 @@ static umode_t nvmem_attr_is_visible(struct kobject *kobj, struct nvmem_device *nvmem = to_nvmem_device(dev); /* - * If the device has no .reg_write operation, do not allow - * configuration as read-write. + * If the device has no .reg_write or .reg_write_const operation, do + * not allow configuration as read-write. * If the device is set as read-only by configuration, it * can be forced into read-write mode using the 'force_ro' * attribute. */ - if (attr == &dev_attr_force_ro.attr && !nvmem->reg_write) + if (attr == &dev_attr_force_ro.attr && !nvmem->reg_write && !nvmem->reg_write_const) return 0; /* Attribute not visible */ return attr->mode; @@ -905,7 +912,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (!config->dev) return ERR_PTR(-EINVAL); - if (!config->reg_read && !config->reg_write) + if (!config->reg_read && !config->reg_write && !config->reg_write_const) return ERR_PTR(-EINVAL); nvmem = kzalloc_obj(*nvmem); @@ -950,6 +957,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->type = config->type; nvmem->reg_read = config->reg_read; nvmem->reg_write = config->reg_write; + nvmem->reg_write_const = config->reg_write_const; nvmem->keepout = config->keepout; nvmem->nkeepout = config->nkeepout; if (config->of_node) @@ -975,7 +983,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) goto err_put_device; nvmem->read_only = device_property_present(config->dev, "read-only") || - config->read_only || !nvmem->reg_write; + config->read_only || !nvmem->reg_write || !nvmem->reg_write_const; #ifdef CONFIG_NVMEM_SYSFS nvmem->dev.groups = nvmem_dev_groups; diff --git a/drivers/nvmem/internals.h b/drivers/nvmem/internals.h index 18fed57270e5..184711dfd6a6 100644 --- a/drivers/nvmem/internals.h +++ b/drivers/nvmem/internals.h @@ -29,6 +29,7 @@ struct nvmem_device { unsigned int nkeepout; nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; + nvmem_reg_write_const_t reg_write_const; struct gpio_desc *wp_gpio; struct nvmem_layout *layout; void *priv; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index f3b13da78aac..c6e77ba1a8c1 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -20,6 +20,8 @@ typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset, void *val, size_t bytes); typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, void *val, size_t bytes); +typedef int (*nvmem_reg_write_const_t)(void *priv, unsigned int offset, + const void *val, size_t bytes); /* used for vendor specific post processing of cell data */ typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index, unsigned int offset, void *buf, @@ -93,7 +95,8 @@ struct nvmem_cell_info { * @root_only: Device is accessibly to root only. * @of_node: If given, this will be used instead of the parent's of_node. * @reg_read: Callback to read data; return zero if successful. - * @reg_write: Callback to write data; return zero if successful. + * @reg_write: **DEPRECATED** - please use reg_write_const instead. + * @reg_write_const: Callback to write data; return zero if successful. * @size: Device size. * @word_size: Minimum read/write access granularity. * @stride: Minimum read/write access stride. @@ -128,6 +131,7 @@ struct nvmem_config { struct device_node *of_node; nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; + nvmem_reg_write_const_t reg_write_const; int size; int word_size; int stride; -- 2.55.0 _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic