Skip to contentSkip to conversation

staging: rdma: Use kcalloc instead of kzalloc

PATCH Superseded Janani Ravichandran 2 participants 3 messages Feb 9, 2016 1 message not in the archive Staging

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rdma: Use kcalloc instead of kzalloc

Use kcalloc rather than kzalloc when multiplied with size to prevent integer overflows. This change also makes code nicer to read.

---
 drivers/staging/rdma/hfi1/efivar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rdma/hfi1/efivar.c +1 -1
index 7dc5bae..feef163 100644
@@ -83,7 +83,7 @@ static int read_efi_var(const char *name, unsigned long *size,
 	if (!efi_enabled(EFI_RUNTIME_SERVICES))
 		return -EOPNOTSUPP;
 
-	uni_name = kzalloc(sizeof(efi_char16_t) * (strlen(name) + 1),
+	uni_name = kcalloc((strlen(name) + 1), sizeof(efi_char16_t),
 			   GFP_KERNEL);
 	temp_buffer = kzalloc(EFI_DATA_SIZE, GFP_KERNEL);
 
Signature · 1 line
2.5.0
#1 lore raw
Quoted 13 lines · Janani Ravichandran

Use kcalloc rather than kzalloc when multiplied with size to prevent integer overflows. This change also makes code nicer to read.

---
 drivers/staging/rdma/hfi1/efivar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rdma/hfi1/efivar.c +0 -0
index 7dc5bae..feef163 100644

drivers/staging/rdma/hfi1/efivar.c static int read_efi_var(const char *name, unsigned long *size, · line 87

Quoted 6 lines
drivers/staging/rdma/hfi1/efivar.c +1 -1
@@ -83,7 +83,7 @@ static int read_efi_var(const char *name, unsigned long *size,
        if (!efi_enabled(EFI_RUNTIME_SERVICES))
                return -EOPNOTSUPP;
 
-       uni_name = kzalloc(sizeof(efi_char16_t) * (strlen(name) + 1),
+       uni_name = kcalloc((strlen(name) + 1), sizeof(efi_char16_t),
                           GFP_KERNEL);

there is no need for parenthesis around first parameter:
-> (strlen(name) + 1 ).

Quoted 1 line
drivers/staging/rdma/hfi1/efivar.c +0 -0
        temp_buffer = kzalloc(EFI_DATA_SIZE, GFP_KERNEL);

A message that is not in the archive (sent off-list or not yet received): CANnt6XmdYvrRJGPoPxtUr0TZcfF8nE02fh3NrvENCN2WK7xv9g@mail.gmail.com

#3 lore raw
Quoted 5 lines · Janani Ravichandran
Quoted 1 line · Daniel Baluta
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines · Janani Ravichandran

Use kcalloc rather than kzalloc when multiplied with size to prevent integer overflows. This change also makes code nicer to read.

---

When sending v2 add here a line documenting the history of this patch e.g:

Changes since v1:
* removed parenthesis around kzalloc first parameter

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
 drivers/staging/rdma/hfi1/efivar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rdma/hfi1/efivar.c +0 -0
index 7dc5bae..feef163 100644
@@ -83,7 +83,7 @@ static int read_efi_var(const char *name, unsigned
 long *size,
        if (!efi_enabled(EFI_RUNTIME_SERVICES))
                return -EOPNOTSUPP;
 
Quoted 8 lines
Quoted 6 lines

drivers/staging/rdma/hfi1/efivar.c static int read_efi_var(const char *name, unsigned long *size, · line 87

Quoted 3 lines
drivers/staging/rdma/hfi1/efivar.c +1 -1
-       uni_name = kzalloc(sizeof(efi_char16_t) * (strlen(name) + 1),
+       uni_name = kcalloc((strlen(name) + 1), sizeof(efi_char16_t),
                           GFP_KERNEL);

there is no need for parenthesis around first parameter:
-> (strlen(name) + 1 ).

Can I send a version 2 of this?

Yes sure. Please keep the Cc list and also make sure you add v2 near the PATCH tag.

e.g [PATCH v2] staging: rdma: Use kcalloc instead of kzalloc

You can either editor our .patch file or use --subject-prefix="PATCH v2" parameter of git format-patch :).

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/staging/rdma/hfi1/efivar.c +0 -0
        temp_buffer = kzalloc(EFI_DATA_SIZE, GFP_KERNEL);