pinctrl: pinctrl-imx: free allocated pinctrl_map structure only once and use kernel facilities for IMX_PMX_DUMP
Subsystems (2)
PATCH v2 1/2 pinctrl: pinctrl-imx: 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 | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)
drivers/pinctrl/pinctrl-imx.c +11 -14
@@ -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*/
@@ -201,10 +201,7 @@ static int imx_dt_node_to_map(struct pinctrl_dev *pctldev,static void imx_dt_free_map (struct pinctrl_dev *pctldev,struct pinctrl_map *map,unsigned num_maps) { -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
Quoted 52 lines · Devendra Naga
a) as we allocate the
pinctrl_mapstructure atimx_dt_node_to_mapat line 167, anyway if its an element, or anum_elements* (sizeof(type)) elements allocated to one single pointer must be freed only once.CASE. A)
as
new_mapis 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 likenew_map = kmalloc(numelems * size, GFP_KERNEL);it just needs kfree not as case A's.
b) use
KERN_DEBUGfacility for theIMX_PMX_DUMPmacro.Signed-off-by Devendra Naga <[email protected]>Acked-by Dong Aisheng <[email protected]>--- drivers/pinctrl/pinctrl-imx.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)drivers/pinctrl/pinctrl-imx.c +2
-10@@ -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) \ +{ \
drivers/pinctrl/pinctrl-imx.c line 41
Quoted 10 lines
drivers/pinctrl/pinctrl-imx.c +8
-0+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]); \ + } \ }
Sorry i missed one more comment.
I think you may also need add below changes since the #ifdef DEBUG is not needed anymore after using KERN_DEBUG.
drivers/pinctrl/pinctrl-imx.c +1 -2
@@ -475,9 +475,8 @@ static int __devinit imx_pinctrl_parse_groups(struct device_node *np, grp->configs[j] = config & ~IMX_PAD_SION ; } -#ifdef DEBUG IMX_PMX_DUMP (info, grp->pins, grp->mux_mode, grp->configs, grp->npins); -#endif +return 0 ; }
Regards
Dong Aisheng