scsi: megaraid_sas: Use a variable for repeated mem_size computation
Commit Message
Use a variable to upfront compute memory size to be allocated,
instead of repeatedly computing it at different instructions.
The reduced instruction length also allows to tidy up the code.
Issue identified using the array_size_dup Coccinelle semantic
patch.
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
drivers/scsi/megaraid/megaraid_sas_fusion.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
Comments
On Thu, Jan 12, 2023 at 12:17:27AM +0530, Deepak R Varma wrote:
> Use a variable to upfront compute memory size to be allocated,
> instead of repeatedly computing it at different instructions.
> The reduced instruction length also allows to tidy up the code.
> Issue identified using the array_size_dup Coccinelle semantic
> patch.
>
> Signed-off-by: Deepak R Varma <drv@mailo.com>
> ---
Hello,
May I request a review and feedback comments on this patch proposal please?
Thank you,
./drv
> drivers/scsi/megaraid/megaraid_sas_fusion.c | 17 +++++++----------
> 1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> index fe70f8f11435..efb25af80664 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> @@ -5287,6 +5287,7 @@ int
> megasas_alloc_fusion_context(struct megasas_instance *instance)
> {
> struct fusion_context *fusion;
> + size_t sz;
>
> instance->ctrl_context = kzalloc(sizeof(struct fusion_context),
> GFP_KERNEL);
> @@ -5298,15 +5299,13 @@ megasas_alloc_fusion_context(struct megasas_instance *instance)
>
> fusion = instance->ctrl_context;
>
> - fusion->log_to_span_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
> - sizeof(LD_SPAN_INFO));
> + sz = array_size(MAX_LOGICAL_DRIVES_EXT, sizeof(LD_SPAN_INFO));
> + fusion->log_to_span_pages = get_order(sz);
> fusion->log_to_span =
> (PLD_SPAN_INFO)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
> fusion->log_to_span_pages);
> if (!fusion->log_to_span) {
> - fusion->log_to_span =
> - vzalloc(array_size(MAX_LOGICAL_DRIVES_EXT,
> - sizeof(LD_SPAN_INFO)));
> + fusion->log_to_span = vzalloc(sz);
> if (!fusion->log_to_span) {
> dev_err(&instance->pdev->dev, "Failed from %s %d\n",
> __func__, __LINE__);
> @@ -5314,15 +5313,13 @@ megasas_alloc_fusion_context(struct megasas_instance *instance)
> }
> }
>
> - fusion->load_balance_info_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
> - sizeof(struct LD_LOAD_BALANCE_INFO));
> + sz = array_size(MAX_LOGICAL_DRIVES_EXT, sizeof(struct LD_LOAD_BALANCE_INFO));
> + fusion->load_balance_info_pages = get_order(sz);
> fusion->load_balance_info =
> (struct LD_LOAD_BALANCE_INFO *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
> fusion->load_balance_info_pages);
> if (!fusion->load_balance_info) {
> - fusion->load_balance_info =
> - vzalloc(array_size(MAX_LOGICAL_DRIVES_EXT,
> - sizeof(struct LD_LOAD_BALANCE_INFO)));
> + fusion->load_balance_info = vzalloc(sz);
> if (!fusion->load_balance_info)
> dev_err(&instance->pdev->dev, "Failed to allocate load_balance_info, "
> "continuing without Load Balance support\n");
> --
> 2.34.1
>
>
>
@@ -5287,6 +5287,7 @@ int
megasas_alloc_fusion_context(struct megasas_instance *instance)
{
struct fusion_context *fusion;
+ size_t sz;
instance->ctrl_context = kzalloc(sizeof(struct fusion_context),
GFP_KERNEL);
@@ -5298,15 +5299,13 @@ megasas_alloc_fusion_context(struct megasas_instance *instance)
fusion = instance->ctrl_context;
- fusion->log_to_span_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
- sizeof(LD_SPAN_INFO));
+ sz = array_size(MAX_LOGICAL_DRIVES_EXT, sizeof(LD_SPAN_INFO));
+ fusion->log_to_span_pages = get_order(sz);
fusion->log_to_span =
(PLD_SPAN_INFO)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
fusion->log_to_span_pages);
if (!fusion->log_to_span) {
- fusion->log_to_span =
- vzalloc(array_size(MAX_LOGICAL_DRIVES_EXT,
- sizeof(LD_SPAN_INFO)));
+ fusion->log_to_span = vzalloc(sz);
if (!fusion->log_to_span) {
dev_err(&instance->pdev->dev, "Failed from %s %d\n",
__func__, __LINE__);
@@ -5314,15 +5313,13 @@ megasas_alloc_fusion_context(struct megasas_instance *instance)
}
}
- fusion->load_balance_info_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
- sizeof(struct LD_LOAD_BALANCE_INFO));
+ sz = array_size(MAX_LOGICAL_DRIVES_EXT, sizeof(struct LD_LOAD_BALANCE_INFO));
+ fusion->load_balance_info_pages = get_order(sz);
fusion->load_balance_info =
(struct LD_LOAD_BALANCE_INFO *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
fusion->load_balance_info_pages);
if (!fusion->load_balance_info) {
- fusion->load_balance_info =
- vzalloc(array_size(MAX_LOGICAL_DRIVES_EXT,
- sizeof(struct LD_LOAD_BALANCE_INFO)));
+ fusion->load_balance_info = vzalloc(sz);
if (!fusion->load_balance_info)
dev_err(&instance->pdev->dev, "Failed to allocate load_balance_info, "
"continuing without Load Balance support\n");