Skip to contentSkip to conversation

pinctrl: free allocated pinctrl_map structure only once and use kernel facilities for IMX_PMX_DUMP

PATCH Superseded Devendra Naga 3 participants 7 messages Jun 2, 2012 – Jun 7, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 pinctrl: free allocated pinctrl_map structure only once and use kernel facilities for IMX_PMX_DUMP

a) as we allocate the pinctrl_map structure at imx_dt_node_to_map at line 167, anyway if its an element, or a num_elements * (sizeof(type)) elements allocated to one single pointer must be freed only once.

CASE. A)

as new_map is not moved and allocated like,

for (i = 0; i < MAX_ELEMS; i++) {
	new_map[i] = kmalloc(numelems * size, GFP_KERNEL);
}

its freed as

for (i = 0; i < MAX_ELEMS; i++) {
	kfree(new_map[i]);
}

CASE. B)
and its allocated like

	new_map = kmalloc(numelems * size, GFP_KERNEL);

it just needs kfree not as case A's.

b) use KERN_DEBUG facility for the IMX_PMX_DUMP macro.

---
 drivers/pinctrl/pinctrl-imx.c |   23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
drivers/pinctrl/pinctrl-imx.c +11 -12
index f6e7c67..553ed95 100644
@@ -27,16 +27,16 @@
 #include "core.h"
 #include "pinctrl-imx.h"
 
-#define IMX_PMX_DUMP(info, p, m, c, n)		\
-{						\
-	int i, j;				\
-	printk("Format: Pin Mux Config\n");	\
-	for (i = 0; i < n; i++) {		\
-		j = p[i];			\
-		printk("%s %d 0x%lx\n",		\
-			info->pins[j].name,	\
-			m[i], c[i]);		\
-	}					\
+#define IMX_PMX_DUMP(info, p, m, c, n)			\
+{							\
+	int i, j;					\
+	printk(KERN_DEBUG "Format: Pin Mux Config\n");	\
+	for (i = 0; i < n; i++) {			\
+		j = p[i];				\
+		printk(KERN_DEBUG "%s %d 0x%lx\n",	\
+			info->pins[j].name,		\
+			m[i], c[i]);			\
+	}						\
 }
 
 /* The bits in CONFIG cell defined in binding doc*/
@@ -203,8 +203,7 @@ static void imx_dt_free_map(struct pinctrl_dev *pctldev,
 {
 	int i;
 
-	for (i = 0; i < num_maps; i++)
-		kfree(map);
+	kfree(map);
 }
 
 static struct pinctrl_ops imx_pctrl_ops = {
Signature · 1 line
1.7.9.5
#1 lore raw

Anybody Please??

Quoted 75 lines · Devendra Naga

a) as we allocate the pinctrl_map structure at imx_dt_node_to_map at  line 167, anyway if its an element, or a num_elements * (sizeof(type)) elements allocated to one single pointer must be freed only once.

CASE. A)

as new_map is not moved and allocated like,

for (i = 0; i < MAX_ELEMS; i++) {
       new_map[i] = kmalloc(numelems * size, GFP_KERNEL); }

its freed as

for (i = 0; i < MAX_ELEMS; i++) {
       kfree(new_map[i]);
}

CASE. B)
and its allocated like
       new_map = kmalloc(numelems * size, GFP_KERNEL);

it just needs kfree not as case A's.

b) use KERN_DEBUG facility for the IMX_PMX_DUMP macro.

---
 drivers/pinctrl/pinctrl-imx.c |   23 +++++++++++------------

 1 file changed, 11 insertions(+), 12 deletions(-)
drivers/pinctrl/pinctrl-imx.c +11 -13
index f6e7c67..553ed95 100644
@@ -27,16 +27,16 @@
  #include "core.h"
  #include "pinctrl-imx.h"
 
-#define IMX_PMX_DUMP(info, p, m, c, n)         \
-{                                              \
-       int i, j;                               \
-       printk("Format: Pin Mux Config\n");     \
-       for (i = 0; i < n; i++) {               \
-               j = p[i];                       \
-               printk("%s %d 0x%lx\n",         \
-                       info->pins[j].name,     \
-                       m[i], c[i]);            \
-       }                                       \
+#define IMX_PMX_DUMP(info, p, m, c, n)                 \
+{                                                      \
+       int i, j;                                       \
+       printk(KERN_DEBUG "Format: Pin Mux Config\n");  \
+       for (i = 0; i < n; i++) {                       \
+               j = p[i];                               \
+               printk(KERN_DEBUG "%s %d 0x%lx\n",      \
+                       info->pins[j].name,             \
+                       m[i], c[i]);                    \
+       }                                               \
  }
 
  /* The bits in CONFIG cell defined in binding doc*/
@@ -203,8 +203,7 @@ static void imx_dt_free_map(struct pinctrl_dev *pctldev,
  {
        int i;
 
-       for (i = 0; i < num_maps; i++)
-               kfree(map);
+       kfree(map);
  }
 
  static struct pinctrl_ops imx_pctrl_ops = {
--

1.7.9.5

#2 lore raw
Quoted 1 line · devendra.aaru

Anybody Please??

Take it easy. Give the Freescalers some time to review...

If nothing happens for a week I'll just apply it so they can shout if there's something wrong with it :-D

Linus

#3 lore raw

Hi Linus,

Thanks for the reply,

Quoted 9 lines · Linus Walleij
Quoted 1 line · devendra.aaru

Anybody Please??

Take it easy. Give the Freescalers some time to review...

If nothing happens for a week I'll just apply it so they can shout if there's something wrong with it :-D

Sorry for shouting ... :(

Quoted 1 line

Linus

Thanks,
Devendra.

#4 lore raw
In reply to Devendra Naga
Quoted 22 lines · Devendra Naga

a) as we allocate the pinctrl_map structure at imx_dt_node_to_map at  line 167, anyway if its an element, or a num_elements * (sizeof(type)) elements allocated to one single pointer must be freed only once.

CASE. A)

as new_map is not moved and allocated like,

for (i = 0; i < MAX_ELEMS; i++) {
       new_map[i] = kmalloc(numelems * size, GFP_KERNEL); }

its freed as

for (i = 0; i < MAX_ELEMS; i++) {
       kfree(new_map[i]);
}

CASE. B)
and its allocated like
       new_map = kmalloc(numelems * size, GFP_KERNEL);

Quoted 8 lines

it just needs kfree not as case A's.

b) use KERN_DEBUG facility for the IMX_PMX_DUMP macro.

---
 drivers/pinctrl/pinctrl-imx.c |   23 +++++++++++------------

 1 file changed, 11 insertions(+), 12 deletions(-)

Shawn/Dong: can you look at this patch too?

Yours,
Linus Walleij

Acked-by on v1 1/2
#5 lore raw
In reply to Devendra Naga
Quoted 22 lines · Devendra Naga

a) as we allocate the pinctrl_map structure at imx_dt_node_to_map at line 167, anyway if its an element, or a num_elements * (sizeof(type)) elements allocated to one single pointer must be freed only once.

CASE. A)

as new_map is not moved and allocated like,

for (i = 0; i < MAX_ELEMS; i++) {
	new_map[i] = kmalloc(numelems * size, GFP_KERNEL);
}

its freed as

for (i = 0; i < MAX_ELEMS; i++) {
	kfree(new_map[i]);
}

CASE. B)
and its allocated like

	new_map = kmalloc(numelems * size, GFP_KERNEL);
Quoted 9 lines

it just needs kfree not as case A's.

b) use KERN_DEBUG facility for the IMX_PMX_DUMP macro.

---
 drivers/pinctrl/pinctrl-imx.c |   23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

Sorry for late reply.
I missed this patch series.
You can CC me next time. :)

Quoted 18 lines
drivers/pinctrl/pinctrl-imx.c +0 -10
index f6e7c67..553ed95 100644
@@ -27,16 +27,16 @@
 #include "core.h"
 #include "pinctrl-imx.h"
 
-#define IMX_PMX_DUMP(info, p, m, c, n)		\
-{						\
-	int i, j;				\
-	printk("Format: Pin Mux Config\n");	\
-	for (i = 0; i < n; i++) {		\
-		j = p[i];			\
-		printk("%s %d 0x%lx\n",		\
-			info->pins[j].name,	\
-			m[i], c[i]);		\
-	}					\

drivers/pinctrl/pinctrl-imx.c line 39

Quoted 10 lines
drivers/pinctrl/pinctrl-imx.c +10 -0
+#define IMX_PMX_DUMP(info, p, m, c, n)			\
+{							\
+	int i, j;					\
+	printk(KERN_DEBUG "Format: Pin Mux Config\n");	\
+	for (i = 0; i < n; i++) {			\
+		j = p[i];				\
+		printk(KERN_DEBUG "%s %d 0x%lx\n",	\
+			info->pins[j].name,		\
+			m[i], c[i]);			\
+	}						\

I can't remember clearly but i encountered a strange issue before that the format was not what i want with KERN_DEBUG... But i just tried your patch and it did not appear.
So i'm ok with this change.

drivers/pinctrl/pinctrl-imx.c static void imx_dt_free_map(struct pinctrl_dev *pctldev, · line 204

Quoted 6 lines
drivers/pinctrl/pinctrl-imx.c +0 -0
 }
 
 /* The bits in CONFIG cell defined in binding doc*/
@@ -203,8 +203,7 @@ static void imx_dt_free_map(struct pinctrl_dev *pctldev,
 {
 	int i;

Also need removed?

drivers/pinctrl/pinctrl-imx.c static void imx_dt_free_map(struct pinctrl_dev *pctldev, · line 206

Quoted 4 lines
drivers/pinctrl/pinctrl-imx.c +1 -2
-	for (i = 0; i < num_maps; i++)
-		kfree(map);
+	kfree(map);

BTW, it would be better if the change the patch title to:
"pinctrl: pinctrl-imx: ...."

Otherwise,

Regards
Dong Aisheng

#6 lore raw

Hi Dong,

Thanks for the review.

Quoted 69 lines · Dong Aisheng
Quoted 22 lines · Devendra Naga

a) as we allocate the pinctrl_map structure at imx_dt_node_to_map at  line 167, anyway if its an element, or a num_elements * (sizeof(type)) elements allocated to one single pointer must be freed only once.

CASE. A)

as new_map is not moved and allocated like,

for (i = 0; i < MAX_ELEMS; i++) {
      new_map[i] = kmalloc(numelems * size, GFP_KERNEL); }

its freed as

for (i = 0; i < MAX_ELEMS; i++) {
      kfree(new_map[i]);
}

CASE. B)
and its allocated like
      new_map = kmalloc(numelems * size, GFP_KERNEL);

Quoted 9 lines

it just needs kfree not as case A's.

b) use KERN_DEBUG facility for the IMX_PMX_DUMP macro.

---
 drivers/pinctrl/pinctrl-imx.c |   23 +++++++++++------------

 1 file changed, 11 insertions(+), 12 deletions(-)

Sorry for late reply.
I missed this patch series.
You can CC me next time. :)

Quoted 18 lines
drivers/pinctrl/pinctrl-imx.c +0 -10
index f6e7c67..553ed95 100644
@@ -27,16 +27,16 @@
  #include "core.h"
  #include "pinctrl-imx.h"
 
-#define IMX_PMX_DUMP(info, p, m, c, n)               \
-{                                            \
-     int i, j;                               \
-     printk("Format: Pin Mux Config\n");     \
-     for (i = 0; i < n; i++) {               \
-             j = p[i];                       \
-             printk("%s %d 0x%lx\n",         \
-                     info->pins[j].name,     \
-                     m[i], c[i]);            \
-     }                                       \

drivers/pinctrl/pinctrl-imx.c line 39

Quoted 10 lines
drivers/pinctrl/pinctrl-imx.c +10 -0
+#define IMX_PMX_DUMP(info, p, m, c, n)                       \
+{                                                    \
+     int i, j;                                       \
+     printk(KERN_DEBUG "Format: Pin Mux Config\n");  \
+     for (i = 0; i < n; i++) {                       \
+             j = p[i];                               \
+             printk(KERN_DEBUG "%s %d 0x%lx\n",      \
+                     info->pins[j].name,             \
+                     m[i], c[i]);                    \
+     }                                               \

I can't remember clearly but i encountered a strange issue before that the format was not what i want with KERN_DEBUG... But i just tried your patch and it did not appear.
So i'm ok with this change.

Quoted 8 lines

drivers/pinctrl/pinctrl-imx.c static void imx_dt_free_map(struct pinctrl_dev *pctldev, · line 204

Quoted 6 lines
drivers/pinctrl/pinctrl-imx.c +0 -0
  }
 
  /* The bits in CONFIG cell defined in binding doc*/
@@ -203,8 +203,7 @@ static void imx_dt_free_map(struct pinctrl_dev *pctldev,
  {
       int i;

Also need removed?

Yeah. sorry , will send again with you Ack.

Quoted 7 lines

drivers/pinctrl/pinctrl-imx.c static void imx_dt_free_map(struct pinctrl_dev *pctldev, · line 206

Quoted 4 lines
drivers/pinctrl/pinctrl-imx.c +1 -2
-     for (i = 0; i < num_maps; i++)
-             kfree(map);
+     kfree(map);

BTW, it would be better if the change the patch title to:
"pinctrl: pinctrl-imx: ...."

Ok sure.

Quoted 7 lines

Otherwise,

Regards
Dong Aisheng

Thanks,
Devendra.