Skip to contentSkip to conversation

pinctrl: freescale: Fine-tuning for ten function implementations

PATCH New SF Markus Elfring 1 participant 11 messages Apr 14, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover pinctrl: freescale: Fine-tuning for ten function implementations

From: Markus Elfring <[email protected]>
Date: Fri, 14 Apr 2017 10:45:43 +0200

Some update suggestions were taken into account
from static source code analysis.

Markus Elfring (10):
imx: Use kmalloc_array() in imx_dt_node_to_map()
imx: Use devm_kcalloc() in two functions
imx: Return directly after a failed devm_kcalloc() in imx_pinctrl_parse_functions()
imx: Improve another size determination in imx_pinctrl_parse_functions()
imx: Use devm_kmalloc_array() in imx_pinctrl_probe()
imx: Use seq_putc() in imx_pinconf_group_dbg_show()
imx: Use seq_puts() in imx_pinconf_dbg_show()
imx1-core: Use kmalloc_array() in imx_dt_node_to_map()
mxs: Use devm_kcalloc() in two functions
mxs: Use kcalloc() in mxs_dt_node_to_map()

 drivers/pinctrl/freescale/pinctrl-imx.c       | 31 +++++++++++++++------------
 drivers/pinctrl/freescale/pinctrl-imx1-core.c |  2 +-
 drivers/pinctrl/freescale/pinctrl-mxs.c       | 13 +++++------
 3 files changed, 25 insertions(+), 21 deletions(-)
Signature · 1 line
2.12.2
#1 lore raw

PATCH 1/10 pinctrl: imx: Use kmalloc_array() in imx_dt_node_to_map()

From: Markus Elfring <[email protected]>
Date: Thu, 13 Apr 2017 10:50:11 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/pinctrl/freescale/pinctrl-imx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/freescale/pinctrl-imx.c +1 -1
index a7ace9e1ad81..563d24e7989d 100644
@@ -98,7 +98,7 @@ static int imx_dt_node_to_map(struct pinctrl_dev *pctldev,
 			map_num++;
 	}
 
-	new_map = kmalloc(sizeof(struct pinctrl_map) * map_num, GFP_KERNEL);
+	new_map = kmalloc_array(map_num, sizeof(*new_map), GFP_KERNEL);
 	if (!new_map)
 		return -ENOMEM;
 
Signature · 1 line
2.12.2
#2 lore raw

PATCH 2/10 pinctrl: imx: Use devm_kcalloc() in two functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 13 Apr 2017 14:13:00 +0200

* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "devm_kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of data types by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/pinctrl/freescale/pinctrl-imx.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/pinctrl/freescale/pinctrl-imx.c +7 -6
index 563d24e7989d..975ed40cb774 100644
@@ -509,10 +509,10 @@ static int imx_pinctrl_parse_groups(struct device_node *np,
 	}
 
 	grp->num_pins = size / pin_size;
-	grp->data = devm_kzalloc(info->dev, grp->num_pins *
+	grp->data = devm_kcalloc(info->dev, grp->num_pins,
 				 sizeof(struct imx_pin), GFP_KERNEL);
-	grp->pins = devm_kzalloc(info->dev, grp->num_pins *
-				 sizeof(unsigned int), GFP_KERNEL);
+	grp->pins = devm_kcalloc(info->dev, grp->num_pins,
+				 sizeof(*grp->pins), GFP_KERNEL);
 	if (!grp->pins || !grp->data)
 		return -ENOMEM;
 
@@ -581,9 +581,10 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
 		dev_err(info->dev, "no groups defined in %s\n", np->full_name);
 		return -EINVAL;
 	}
-	func->group_names = devm_kzalloc(info->dev,
-					 func->num_group_names *
-					 sizeof(char *), GFP_KERNEL);
+	func->group_names = devm_kcalloc(info->dev,
+					 func->num_group_names,
+					 sizeof(*func->group_names),
+					 GFP_KERNEL);
 
 	for_each_child_of_node(np, child) {
 		func->group_names[i] = child->name;
Signature · 1 line
2.12.2
#3 lore raw

PATCH 3/10 pinctrl: imx: Return directly after a failed devm_kcalloc() in imx_pinctrl_parse_functions()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 13 Apr 2017 15:12:20 +0200

Add a check for a null pointer and return an error code after a memory allocation failure was detected.

---
 drivers/pinctrl/freescale/pinctrl-imx.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pinctrl/freescale/pinctrl-imx.c +2 -0
index 975ed40cb774..f835e8210ace 100644
@@ -585,6 +585,8 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
 					 func->num_group_names,
 					 sizeof(*func->group_names),
 					 GFP_KERNEL);
+	if (!func->group_names)
+		return -ENOMEM;
 
 	for_each_child_of_node(np, child) {
 		func->group_names[i] = child->name;
Signature · 1 line
2.12.2
#4 lore raw

PATCH 4/10 pinctrl: imx: Improve another size determination in imx_pinctrl_parse_functions()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 13 Apr 2017 15:20:43 +0200

Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/pinctrl/freescale/pinctrl-imx.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pinctrl/freescale/pinctrl-imx.c +1 -3
index f835e8210ace..44dbf6e38d79 100644
@@ -590,9 +590,7 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
 
 	for_each_child_of_node(np, child) {
 		func->group_names[i] = child->name;
-
-		grp = devm_kzalloc(info->dev, sizeof(struct group_desc),
-				   GFP_KERNEL);
+		grp = devm_kzalloc(info->dev, sizeof(*grp), GFP_KERNEL);
 		if (!grp)
 			return -ENOMEM;
 
Signature · 1 line
2.12.2
#5 lore raw

PATCH 5/10 pinctrl: imx: Use devm_kmalloc_array() in imx_pinctrl_probe()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 13 Apr 2017 15:35:27 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "devm_kmalloc_array".

This issue was detected by using the Coccinelle software.

---
 drivers/pinctrl/freescale/pinctrl-imx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pinctrl/freescale/pinctrl-imx.c +4 -2
index 44dbf6e38d79..078875361d76 100644
@@ -726,8 +726,10 @@ int imx_pinctrl_probe(struct platform_device *pdev,
 	if (!ipctl)
 		return -ENOMEM;
 
-	info->pin_regs = devm_kmalloc(&pdev->dev, sizeof(*info->pin_regs) *
-				      info->npins, GFP_KERNEL);
+	info->pin_regs = devm_kmalloc_array(&pdev->dev,
+					    info->npins,
+					    sizeof(*info->pin_regs),
+					    GFP_KERNEL);
 	if (!info->pin_regs)
 		return -ENOMEM;
 
Signature · 1 line
2.12.2
#6 lore raw

PATCH 6/10 pinctrl: imx: Use seq_putc() in imx_pinconf_group_dbg_show()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 13 Apr 2017 15:43:55 +0200

A single character (line break) should be put into a sequence. Thus use the corresponding function "seq_putc".

This issue was detected by using the Coccinelle software.

---
 drivers/pinctrl/freescale/pinctrl-imx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/freescale/pinctrl-imx.c +1 -1
index 078875361d76..71dbba892e70 100644
@@ -443,7 +443,7 @@ static void imx_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
 	if (group > pctldev->num_groups)
 		return;
 
-	seq_printf(s, "\n");
+	seq_putc(s, '\n');
 	grp = pinctrl_generic_get_group(pctldev, group);
 	if (!grp)
 		return;
Signature · 1 line
2.12.2
#7 lore raw

PATCH 7/10 pinctrl: imx: Use seq_puts() in imx_pinconf_dbg_show()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 13 Apr 2017 15:50:58 +0200

A string which did not contain a data format specification should be put into a sequence. Thus use the corresponding function "seq_puts".

This issue was detected by using the Coccinelle software.

---
 drivers/pinctrl/freescale/pinctrl-imx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/freescale/pinctrl-imx.c +1 -1
index 71dbba892e70..c6bfabcd577a 100644
@@ -424,7 +424,7 @@ static void imx_pinconf_dbg_show(struct pinctrl_dev *pctldev,
 	unsigned long config;
 
 	if (!pin_reg || pin_reg->conf_reg = -1) {
-		seq_printf(s, "N/A");
+		seq_puts(s, "N/A");
 		return;
 	}
 
Signature · 1 line
2.12.2
#8 lore raw

PATCH 8/10 pinctrl: imx1-core: Use kmalloc_array() in imx_dt_node_to_map()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 13 Apr 2017 16:10:33 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/pinctrl/freescale/pinctrl-imx1-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/freescale/pinctrl-imx1-core.c +1 -1
index a4e9f430d452..5a0d221ed09d 100644
@@ -246,7 +246,7 @@ static int imx1_dt_node_to_map(struct pinctrl_dev *pctldev,
 	for (i = 0; i < grp->npins; i++)
 		map_num++;
 
-	new_map = kmalloc(sizeof(struct pinctrl_map) * map_num, GFP_KERNEL);
+	new_map = kmalloc_array(map_num, sizeof(*new_map), GFP_KERNEL);
 	if (!new_map)
 		return -ENOMEM;
 
Signature · 1 line
2.12.2
#9 lore raw

PATCH 9/10 pinctrl: mxs: Use devm_kcalloc() in two functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 13 Apr 2017 16:28:48 +0200

Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "devm_kcalloc".

This issue was detected by using the Coccinelle software.

---
 drivers/pinctrl/freescale/pinctrl-mxs.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/pinctrl/freescale/pinctrl-mxs.c +6 -5
index 41b5b07d5a2b..9e6dc0038c35 100644
@@ -369,12 +369,12 @@ static int mxs_pinctrl_parse_group(struct platform_device *pdev,
 		return -EINVAL;
 	g->npins = length / sizeof(u32);
 
-	g->pins = devm_kzalloc(&pdev->dev, g->npins * sizeof(*g->pins),
+	g->pins = devm_kcalloc(&pdev->dev, g->npins, sizeof(*g->pins),
 			       GFP_KERNEL);
 	if (!g->pins)
 		return -ENOMEM;
 
-	g->muxsel = devm_kzalloc(&pdev->dev, g->npins * sizeof(*g->muxsel),
+	g->muxsel = devm_kcalloc(&pdev->dev, g->npins, sizeof(*g->muxsel),
 				 GFP_KERNEL);
 	if (!g->muxsel)
 		return -ENOMEM;
@@ -425,12 +425,12 @@ static int mxs_pinctrl_probe_dt(struct platform_device *pdev,
 		}
 	}
 
-	soc->functions = devm_kzalloc(&pdev->dev, soc->nfunctions *
+	soc->functions = devm_kcalloc(&pdev->dev, soc->nfunctions,
 				      sizeof(*soc->functions), GFP_KERNEL);
 	if (!soc->functions)
 		return -ENOMEM;
 
-	soc->groups = devm_kzalloc(&pdev->dev, soc->ngroups *
+	soc->groups = devm_kcalloc(&pdev->dev, soc->ngroups,
 				   sizeof(*soc->groups), GFP_KERNEL);
 	if (!soc->groups)
 		return -ENOMEM;
@@ -491,7 +491,8 @@ static int mxs_pinctrl_probe_dt(struct platform_device *pdev,
 
 		if (strcmp(fn, child->name)) {
 			f = &soc->functions[idxf++];
-			f->groups = devm_kzalloc(&pdev->dev, f->ngroups *
+			f->groups = devm_kcalloc(&pdev->dev,
+						 f->ngroups,
 						 sizeof(*f->groups),
 						 GFP_KERNEL);
 			if (!f->groups)
Signature · 1 line
2.12.2
#10 lore raw

PATCH 10/10 pinctrl: mxs: Use kcalloc() in mxs_dt_node_to_map()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 14 Apr 2017 10:32:29 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

---
 drivers/pinctrl/freescale/pinctrl-mxs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/freescale/pinctrl-mxs.c +1 -1
index 9e6dc0038c35..1479610091d5 100644
@@ -96,7 +96,7 @@ static int mxs_dt_node_to_map(struct pinctrl_dev *pctldev,
 	if (!purecfg && config)
 		new_num = 2;
 
-	new_map = kzalloc(sizeof(*new_map) * new_num, GFP_KERNEL);
+	new_map = kcalloc(new_num, sizeof(*new_map), GFP_KERNEL);
 	if (!new_map)
 		return -ENOMEM;
 
Signature · 1 line
2.12.2