Thread (18 messages) read the whole thread 18 messages, 4 authors, 3d ago

Re: [PATCH v3 06/11] nvmem: imx-ocotp-ele: Use __free(kfree) in imx_ocotp_reg_read()

From: Frieder Schrempf <hidden>
Date: 2026-07-27 11:51:36
Also in: imx, linux-devicetree, lkml

On 23.07.26 20:42, Frank Li wrote:
On Thu, Jul 23, 2026 at 09:27:28AM +0200, Frieder Schrempf wrote:
quoted
From: Frieder Schrempf <redacted>

This is useful to make sure the buffer is always freed when
its scope ends and makes the code slightly easier to read.

Signed-off-by: Frieder Schrempf <redacted>
---
 drivers/nvmem/imx-ocotp-ele.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c
index 9d3f94e35508..47ee6bd176a3 100644
--- a/drivers/nvmem/imx-ocotp-ele.c
+++ b/drivers/nvmem/imx-ocotp-ele.c
@@ -5,6 +5,7 @@
  * Copyright 2023 NXP
  */

+#include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/io.h>
 #include <linux/module.h>
@@ -68,10 +69,10 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz
 {
 	struct imx_ocotp_priv *priv = context;
 	void __iomem *reg = priv->base + priv->data->reg_off;
+	void *p __free(kfree) = NULL;
according to cleanup.h, it should declare at where assign

void *p __free(free) =  kzalloc(num_bytes, GFP_KERNEL);
As far as I can see, NULL should be perfectly fine as an initializer, as
we need to calculate num_bytes first.
quoted
 	u32 count, index, num_bytes;
 	enum fuse_type type;
 	u32 *buf;
-	void *p;
 	int i;
 	u8 skipbytes;
@@ -108,8 +109,6 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz

 	mutex_unlock(&priv->lock);

-	kfree(p);
-
 	return 0;
 };


--
2.55.0
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help