* [PATCH][next] scsi: fnic: Replace vmalloc() + memset() with vzalloc() and use array_size()
@ 2020-06-15 22:54 Gustavo A. R. Silva
2020-06-16 0:19 ` Satish Kharat (satishkh)
0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2020-06-15 22:54 UTC (permalink / raw)
To: Satish Kharat, Sesidhar Baddela, Karan Tilak Kumar,
James E.J. Bottomley, Martin K. Petersen
Cc: linux-scsi, linux-kernel, Gustavo A. R. Silva
Use vzalloc() instead of the vmalloc() and memset. Also, use array_size()
instead of the open-coded version.
This issue was found with the help of Coccinelle and, audited and fixed
manually.
Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/scsi/fnic/fnic_trace.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/scsi/fnic/fnic_trace.c b/drivers/scsi/fnic/fnic_trace.c
index 9d52d83161ed..be266d1611bb 100644
--- a/drivers/scsi/fnic/fnic_trace.c
+++ b/drivers/scsi/fnic/fnic_trace.c
@@ -488,7 +488,7 @@ int fnic_trace_buf_init(void)
}
fnic_trace_entries.page_offset =
- vmalloc(array_size(fnic_max_trace_entries,
+ vzalloc(array_size(fnic_max_trace_entries,
sizeof(unsigned long)));
if (!fnic_trace_entries.page_offset) {
printk(KERN_ERR PFX "Failed to allocate memory for"
@@ -500,8 +500,6 @@ int fnic_trace_buf_init(void)
err = -ENOMEM;
goto err_fnic_trace_buf_init;
}
- memset((void *)fnic_trace_entries.page_offset, 0,
- (fnic_max_trace_entries * sizeof(unsigned long)));
fnic_trace_entries.wr_idx = fnic_trace_entries.rd_idx = 0;
fnic_buf_head = fnic_trace_buf_p;
@@ -559,10 +557,10 @@ int fnic_fc_trace_init(void)
int err = 0;
int i;
- fc_trace_max_entries = (fnic_fc_trace_max_pages * PAGE_SIZE)/
+ fc_trace_max_entries = array_size(fnic_fc_trace_max_pages, PAGE_SIZE)/
FC_TRC_SIZE_BYTES;
fnic_fc_ctlr_trace_buf_p =
- (unsigned long)vmalloc(array_size(PAGE_SIZE,
+ (unsigned long)vzalloc(array_size(PAGE_SIZE,
fnic_fc_trace_max_pages));
if (!fnic_fc_ctlr_trace_buf_p) {
pr_err("fnic: Failed to allocate memory for "
@@ -571,12 +569,9 @@ int fnic_fc_trace_init(void)
goto err_fnic_fc_ctlr_trace_buf_init;
}
- memset((void *)fnic_fc_ctlr_trace_buf_p, 0,
- fnic_fc_trace_max_pages * PAGE_SIZE);
-
/* Allocate memory for page offset */
fc_trace_entries.page_offset =
- vmalloc(array_size(fc_trace_max_entries,
+ vzalloc(array_size(fc_trace_max_entries,
sizeof(unsigned long)));
if (!fc_trace_entries.page_offset) {
pr_err("fnic:Failed to allocate memory for page_offset\n");
@@ -588,9 +583,6 @@ int fnic_fc_trace_init(void)
err = -ENOMEM;
goto err_fnic_fc_ctlr_trace_buf_init;
}
- memset((void *)fc_trace_entries.page_offset, 0,
- (fc_trace_max_entries * sizeof(unsigned long)));
-
fc_trace_entries.rd_idx = fc_trace_entries.wr_idx = 0;
fc_trace_buf_head = fnic_fc_ctlr_trace_buf_p;
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] scsi: fnic: Replace vmalloc() + memset() with vzalloc() and use array_size()
2020-06-15 22:54 [PATCH][next] scsi: fnic: Replace vmalloc() + memset() with vzalloc() and use array_size() Gustavo A. R. Silva
@ 2020-06-16 0:19 ` Satish Kharat (satishkh)
2020-06-16 4:42 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: Satish Kharat (satishkh) @ 2020-06-16 0:19 UTC (permalink / raw)
To: Gustavo A. R. Silva, Sesidhar Baddela (sebaddel),
Karan Tilak Kumar (kartilak),
James E.J. Bottomley, Martin K. Petersen
Cc: linux-scsi, linux-kernel, Gustavo A. R. Silva
Reviewed-by: Satish Kharat <satishkh@cisco.com>
On 6/15/20, 3:49 PM, "Gustavo A. R. Silva" <gustavoars@kernel.org> wrote:
Use vzalloc() instead of the vmalloc() and memset. Also, use array_size()
instead of the open-coded version.
This issue was found with the help of Coccinelle and, audited and fixed
manually.
Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/scsi/fnic/fnic_trace.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/scsi/fnic/fnic_trace.c b/drivers/scsi/fnic/fnic_trace.c
index 9d52d83161ed..be266d1611bb 100644
--- a/drivers/scsi/fnic/fnic_trace.c
+++ b/drivers/scsi/fnic/fnic_trace.c
@@ -488,7 +488,7 @@ int fnic_trace_buf_init(void)
}
fnic_trace_entries.page_offset =
- vmalloc(array_size(fnic_max_trace_entries,
+ vzalloc(array_size(fnic_max_trace_entries,
sizeof(unsigned long)));
if (!fnic_trace_entries.page_offset) {
printk(KERN_ERR PFX "Failed to allocate memory for"
@@ -500,8 +500,6 @@ int fnic_trace_buf_init(void)
err = -ENOMEM;
goto err_fnic_trace_buf_init;
}
- memset((void *)fnic_trace_entries.page_offset, 0,
- (fnic_max_trace_entries * sizeof(unsigned long)));
fnic_trace_entries.wr_idx = fnic_trace_entries.rd_idx = 0;
fnic_buf_head = fnic_trace_buf_p;
@@ -559,10 +557,10 @@ int fnic_fc_trace_init(void)
int err = 0;
int i;
- fc_trace_max_entries = (fnic_fc_trace_max_pages * PAGE_SIZE)/
+ fc_trace_max_entries = array_size(fnic_fc_trace_max_pages, PAGE_SIZE)/
FC_TRC_SIZE_BYTES;
fnic_fc_ctlr_trace_buf_p =
- (unsigned long)vmalloc(array_size(PAGE_SIZE,
+ (unsigned long)vzalloc(array_size(PAGE_SIZE,
fnic_fc_trace_max_pages));
if (!fnic_fc_ctlr_trace_buf_p) {
pr_err("fnic: Failed to allocate memory for "
@@ -571,12 +569,9 @@ int fnic_fc_trace_init(void)
goto err_fnic_fc_ctlr_trace_buf_init;
}
- memset((void *)fnic_fc_ctlr_trace_buf_p, 0,
- fnic_fc_trace_max_pages * PAGE_SIZE);
-
/* Allocate memory for page offset */
fc_trace_entries.page_offset =
- vmalloc(array_size(fc_trace_max_entries,
+ vzalloc(array_size(fc_trace_max_entries,
sizeof(unsigned long)));
if (!fc_trace_entries.page_offset) {
pr_err("fnic:Failed to allocate memory for page_offset\n");
@@ -588,9 +583,6 @@ int fnic_fc_trace_init(void)
err = -ENOMEM;
goto err_fnic_fc_ctlr_trace_buf_init;
}
- memset((void *)fc_trace_entries.page_offset, 0,
- (fc_trace_max_entries * sizeof(unsigned long)));
-
fc_trace_entries.rd_idx = fc_trace_entries.wr_idx = 0;
fc_trace_buf_head = fnic_fc_ctlr_trace_buf_p;
--
2.27.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] scsi: fnic: Replace vmalloc() + memset() with vzalloc() and use array_size()
2020-06-16 0:19 ` Satish Kharat (satishkh)
@ 2020-06-16 4:42 ` Joe Perches
0 siblings, 0 replies; 3+ messages in thread
From: Joe Perches @ 2020-06-16 4:42 UTC (permalink / raw)
To: Satish Kharat (satishkh),
Gustavo A. R. Silva, Sesidhar Baddela (sebaddel),
Karan Tilak Kumar (kartilak),
James E.J. Bottomley, Martin K. Petersen
Cc: linux-scsi, linux-kernel, Gustavo A. R. Silva
On Tue, 2020-06-16 at 00:19 +0000, Satish Kharat (satishkh) wrote:
> Reviewed-by: Satish Kharat <satishkh@cisco.com>
>
>
> On 6/15/20, 3:49 PM, "Gustavo A. R. Silva" <gustavoars@kernel.org> wrote:
>
> Use vzalloc() instead of the vmalloc() and memset. Also, use array_size()
> instead of the open-coded version.
>
> This issue was found with the help of Coccinelle and, audited and fixed
> manually.
>
> Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> drivers/scsi/fnic/fnic_trace.c | 16 ++++------------
> 1 file changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/scsi/fnic/fnic_trace.c b/drivers/scsi/fnic/fnic_trace.c
[]
> @@ -488,7 +488,7 @@ int fnic_trace_buf_init(void)
> }
>
> fnic_trace_entries.page_offset =
> - vmalloc(array_size(fnic_max_trace_entries,
> + vzalloc(array_size(fnic_max_trace_entries,
> sizeof(unsigned long)));
Perhaps better as
kvcalloc(fnic_max_trace_entries, sizeof(unsigned long),
GFP_KERNEL);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-16 4:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 22:54 [PATCH][next] scsi: fnic: Replace vmalloc() + memset() with vzalloc() and use array_size() Gustavo A. R. Silva
2020-06-16 0:19 ` Satish Kharat (satishkh)
2020-06-16 4:42 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).