Skip to contentSkip to conversation

staging: ozwpan: use kmalloc_array over kmalloc with multiply

PATCH Adrian Nicoara 3 participants 3 messages Sep 8, 2014 – Sep 9, 2014 Staging

lore
Share & tools
lore
#0 lore raw

Cleanup checkpatch.pl warnings.

---

Somehow I missed the comment Tobias made on the line indentation. I fixed the patch, and added here as a reply - the previous patch should be ignored.

 drivers/staging/ozwpan/ozhcd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/ozwpan/ozhcd.c +2 -2
index ba2168f..e880452 100644
@@ -1315,8 +1315,8 @@ static int oz_build_endpoints_for_config(struct usb_hcd *hcd,
 	if (num_iface) {
 		struct oz_interface *iface;
 
-		iface = kmalloc(num_iface*sizeof(struct oz_interface),
-				mem_flags | __GFP_ZERO);
+		iface = kmalloc_array(num_iface, sizeof(struct oz_interface),
+					mem_flags | __GFP_ZERO);
 		if (!iface)
 			return -ENOMEM;
 		spin_lock_bh(&ozhcd->hcd_lock);

--
2.0.1

#1 lore raw
Quoted 1 line · Adrian Nicoara

Cleanup checkpatch.pl warnings.

Please state which warning this is fixing. Same goes for patches 1-3.

Quoted 14 lines

---

Somehow I missed the comment Tobias made on the line indentation. I fixed the patch, and added here as a reply - the previous patch should be ignored.

 drivers/staging/ozwpan/ozhcd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/ozwpan/ozhcd.c +0 -0
index ba2168f..e880452 100644

drivers/staging/ozwpan/ozhcd.c static int oz_build_endpoints_for_config(struct usb_hcd *hcd, · line 1319

Quoted 7 lines
drivers/staging/ozwpan/ozhcd.c +2 -2
@@ -1315,8 +1315,8 @@ static int oz_build_endpoints_for_config(struct usb_hcd *hcd,
 	if (num_iface) {
 		struct oz_interface *iface;
 
-		iface = kmalloc(num_iface*sizeof(struct oz_interface),
-				mem_flags | __GFP_ZERO);
+		iface = kmalloc_array(num_iface, sizeof(struct oz_interface),
+					mem_flags | __GFP_ZERO);

This still isn't entirely correct. It should rather look like this:

		iface = kmalloc_array(num_iface, sizeof(struct oz_interface),
				      mem_flags | __GFP_ZERO);

Assume a tab width of 8 (as per CodingStyle) and use spaces to get the alignment right.

Quoted 6 lines
drivers/staging/ozwpan/ozhcd.c +0 -1
 		if (!iface)
 			return -ENOMEM;
 		spin_lock_bh(&ozhcd->hcd_lock);
--

2.0.1

#2 lore raw
In reply to Adrian Nicoara
Quoted 16 lines · Adrian Nicoara

Cleanup checkpatch.pl warnings.

---

Somehow I missed the comment Tobias made on the line indentation. I fixed the patch, and added here as a reply - the previous patch should be ignored.

 drivers/staging/ozwpan/ozhcd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/ozwpan/ozhcd.c +0 -0
index ba2168f..e880452 100644

drivers/staging/ozwpan/ozhcd.c static int oz_build_endpoints_for_config(struct usb_hcd *hcd, · line 1319

Quoted 7 lines
drivers/staging/ozwpan/ozhcd.c +2 -2
@@ -1315,8 +1315,8 @@ static int oz_build_endpoints_for_config(struct usb_hcd *hcd,
 	if (num_iface) {
 		struct oz_interface *iface;
 
-		iface = kmalloc(num_iface*sizeof(struct oz_interface),
-				mem_flags | __GFP_ZERO);
+		iface = kmalloc_array(num_iface, sizeof(struct oz_interface),
+					mem_flags | __GFP_ZERO);

Still not lined up correctly. The spacing should be:

		iface = kmalloc_array(num_iface, sizeof(struct oz_interface),
				      mem_flags | __GFP_ZERO);

[tab][tab][tab][tab][space][space][space][space][space][space]mem_flags...

regards,
dan carpenter