Re: [PATCH v6 02/17] nvmem: add DEFINE_FREE for nvmem_cell_put cleanup
Jonathan Cameron <[email protected]>
| Newsgroups | org.kernel.vger.linux-kernel,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-iio |
|---|---|
| Message-ID | <20260815205238.6fbfb2f8@jic23-huawei> |
On Thu, 6 Aug 2026 13:10:09 +0530 Varshini Rajendran <[email protected]> wrote: > Add cleanup.h helper for nvmem_cell_put() to enable automatic resource > cleanup using __free(nvmem_cell_put) annotation. > > Use IS_ERR_OR_NULL() since nvmem_cell_get() can return error pointers, > and passing an ERR_PTR to nvmem_cell_put() would cause issues. > > Signed-off-by: Varshini Rajendran <[email protected]> > --- Srinivas, if you are happy with this header addition please could I have an Ack to take this through the IIO tree? If it's useful for other series, I can provide an immutable branch that you can pull into the nvmem tree. I'll probably spin one of those on rc1 once available anyway just in case someone else needs it later in the cycle. No huge rush - just good to keep this moving! Jonathan > include/linux/nvmem-consumer.h | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h > index 34c0e58dfa26..5315bd862f5f 100644 > --- a/include/linux/nvmem-consumer.h > +++ b/include/linux/nvmem-consumer.h > @@ -9,6 +9,7 @@ > #ifndef _LINUX_NVMEM_CONSUMER_H > #define _LINUX_NVMEM_CONSUMER_H > > +#include <linux/cleanup.h> > #include <linux/err.h> > #include <linux/errno.h> > #include <linux/notifier.h> > @@ -243,6 +244,8 @@ static inline struct nvmem_device *nvmem_device_find(void *data, > > #endif /* CONFIG_NVMEM */ > > +DEFINE_FREE(nvmem_cell_put, struct nvmem_cell *, if (!IS_ERR_OR_NULL(_T)) nvmem_cell_put(_T)) > + > #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) > struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, > const char *id);