[PATCH] scsi: hpsa: kzalloc + kcalloc to kzalloc_flex

From: Rosen Penev

Date: Fri Mar 20 2026 - 00:18:53 EST


Simplifies allocation and freeing the struct.

Removed hpda_free_ctlr_info as it's now just a single kfree.

Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
---
drivers/scsi/hpsa.c | 17 +++--------------
drivers/scsi/hpsa.h | 2 +-
2 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index a1b116cd4723..608c45f4f749 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -8621,25 +8621,14 @@ static struct workqueue_struct *hpsa_create_controller_wq(struct ctlr_info *h,
return wq;
}

-static void hpda_free_ctlr_info(struct ctlr_info *h)
-{
- kfree(h->reply_map);
- kfree(h);
-}
-
static struct ctlr_info *hpda_alloc_ctlr_info(void)
{
struct ctlr_info *h;

- h = kzalloc_obj(*h);
+ h = kzalloc_flex(*h, reply_map, nr_cpu_ids, GFP_KERNEL);
if (!h)
return NULL;

- h->reply_map = kcalloc(nr_cpu_ids, sizeof(*h->reply_map), GFP_KERNEL);
- if (!h->reply_map) {
- kfree(h);
- return NULL;
- }
return h;
}

@@ -8909,7 +8898,7 @@ static int hpsa_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
destroy_workqueue(h->monitor_ctlr_wq);
h->monitor_ctlr_wq = NULL;
}
- hpda_free_ctlr_info(h);
+ kfree(h);
return rc;
}

@@ -9093,7 +9082,7 @@ static void hpsa_remove_one(struct pci_dev *pdev)
free_percpu(h->lockup_detected); /* init_one 2 */
h->lockup_detected = NULL; /* init_one 2 */

- hpda_free_ctlr_info(h); /* init_one 1 */
+ kfree(h); /* init_one 1 */
}

static int __maybe_unused hpsa_suspend(
diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
index 99b0750850b2..935c2e1a840d 100644
--- a/drivers/scsi/hpsa.h
+++ b/drivers/scsi/hpsa.h
@@ -162,7 +162,6 @@ struct bmic_controller_parameters {
#pragma pack()

struct ctlr_info {
- unsigned int *reply_map;
int ctlr;
char devname[8];
char *product_name;
@@ -311,6 +310,7 @@ struct ctlr_info {
u8 reset_in_progress;
struct hpsa_sas_node *sas_host;
spinlock_t reset_lock;
+ unsigned int reply_map[];
};

struct offline_device_entry {
--
2.53.0