diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/message/fusion | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'drivers/message/fusion')
| -rw-r--r-- | drivers/message/fusion/mptbase.c | 5 | ||||
| -rw-r--r-- | drivers/message/fusion/mptfc.c | 6 | ||||
| -rw-r--r-- | drivers/message/fusion/mptlan.c | 15 | ||||
| -rw-r--r-- | drivers/message/fusion/mptsas.c | 38 | ||||
| -rw-r--r-- | drivers/message/fusion/mptspi.c | 8 |
5 files changed, 34 insertions, 38 deletions
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c index e60a8d3947c9..de771eb6facd 100644 --- a/drivers/message/fusion/mptbase.c +++ b/drivers/message/fusion/mptbase.c @@ -1771,7 +1771,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id) struct proc_dir_entry *dent; #endif - ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_KERNEL); + ioc = kzalloc_obj(MPT_ADAPTER, GFP_KERNEL); if (ioc == NULL) { printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n"); return -ENOMEM; @@ -5700,8 +5700,7 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *ioc, u8 channel, u8 id) buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0) continue; - if ((component_info = kmalloc(sizeof (*component_info), - GFP_KERNEL)) == NULL) + if ((component_info = kmalloc_obj(*component_info, GFP_KERNEL)) == NULL) continue; component_info->volumeID = id; diff --git a/drivers/message/fusion/mptfc.c b/drivers/message/fusion/mptfc.c index cd52db6fe76c..b65bc679106a 100644 --- a/drivers/message/fusion/mptfc.c +++ b/drivers/message/fusion/mptfc.c @@ -484,7 +484,7 @@ mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0) } } if (new_ri) { /* allocate one */ - ri = kzalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL); + ri = kzalloc_obj(struct mptfc_rport_info, GFP_KERNEL); if (!ri) return; list_add_tail(&ri->list, &ioc->fc_rports); @@ -572,7 +572,7 @@ mptfc_target_alloc(struct scsi_target *starget) struct mptfc_rport_info *ri; int rc; - vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL); + vtarget = kzalloc_obj(VirtTarget, GFP_KERNEL); if (!vtarget) return -ENOMEM; starget->hostdata = vtarget; @@ -650,7 +650,7 @@ mptfc_sdev_init(struct scsi_device *sdev) hd = shost_priv(sdev->host); ioc = hd->ioc; - vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL); + vdevice = kzalloc_obj(VirtDevice, GFP_KERNEL); if (!vdevice) { printk(MYIOC_s_ERR_FMT "sdev_init kmalloc(%zd) FAILED!\n", ioc->name, sizeof(VirtDevice)); diff --git a/drivers/message/fusion/mptlan.c b/drivers/message/fusion/mptlan.c index de2e7bcf4784..0da0d472aaff 100644 --- a/drivers/message/fusion/mptlan.c +++ b/drivers/message/fusion/mptlan.c @@ -391,14 +391,13 @@ mpt_lan_open(struct net_device *dev) "a moment.\n"); } - priv->mpt_txfidx = kmalloc_array(priv->tx_max_out, sizeof(int), - GFP_KERNEL); + priv->mpt_txfidx = kmalloc_objs(int, priv->tx_max_out, GFP_KERNEL); if (priv->mpt_txfidx == NULL) goto out; priv->mpt_txfidx_tail = -1; - priv->SendCtl = kcalloc(priv->tx_max_out, sizeof(struct BufferControl), - GFP_KERNEL); + priv->SendCtl = kzalloc_objs(struct BufferControl, priv->tx_max_out, + GFP_KERNEL); if (priv->SendCtl == NULL) goto out_mpt_txfidx; for (i = 0; i < priv->tx_max_out; i++) @@ -406,15 +405,13 @@ mpt_lan_open(struct net_device *dev) dlprintk((KERN_INFO MYNAM "@lo: Finished initializing SendCtl\n")); - priv->mpt_rxfidx = kmalloc_array(priv->max_buckets_out, sizeof(int), - GFP_KERNEL); + priv->mpt_rxfidx = kmalloc_objs(int, priv->max_buckets_out, GFP_KERNEL); if (priv->mpt_rxfidx == NULL) goto out_SendCtl; priv->mpt_rxfidx_tail = -1; - priv->RcvCtl = kcalloc(priv->max_buckets_out, - sizeof(struct BufferControl), - GFP_KERNEL); + priv->RcvCtl = kzalloc_objs(struct BufferControl, priv->max_buckets_out, + GFP_KERNEL); if (priv->RcvCtl == NULL) goto out_mpt_rxfidx; for (i = 0; i < priv->max_buckets_out; i++) diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c index 5276bdb7acc2..0b9e787ae3d5 100644 --- a/drivers/message/fusion/mptsas.c +++ b/drivers/message/fusion/mptsas.c @@ -603,7 +603,7 @@ mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id, } } - sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL); + sas_info = kzalloc_obj(struct mptsas_device_info, GFP_KERNEL); if (!sas_info) goto out; @@ -756,7 +756,7 @@ mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc, } } - sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL); + sas_info = kzalloc_obj(struct mptsas_device_info, GFP_KERNEL); if (sas_info) { sas_info->fw.id = starget->id; sas_info->os.id = starget->id; @@ -907,8 +907,8 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info) * Forming a port */ if (!port_details) { - port_details = kzalloc(sizeof(struct - mptsas_portinfo_details), GFP_KERNEL); + port_details = kzalloc_obj(struct mptsas_portinfo_details, + GFP_KERNEL); if (!port_details) goto out; port_details->num_phys = 1; @@ -1038,7 +1038,7 @@ mptsas_queue_rescan(MPT_ADAPTER *ioc) { struct fw_event_work *fw_event; - fw_event = kzalloc(sizeof(*fw_event), GFP_ATOMIC); + fw_event = kzalloc_obj(*fw_event, GFP_ATOMIC); if (!fw_event) { printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", ioc->name, __func__, __LINE__); @@ -1150,8 +1150,8 @@ mptsas_target_reset_queue(MPT_ADAPTER *ioc, vtarget->deleted = 1; /* block IO */ } - target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event), - GFP_ATOMIC); + target_reset_list = kzalloc_obj(struct mptsas_target_reset_event, + GFP_ATOMIC); if (!target_reset_list) { dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, failed to allocate mem @%d..!!\n", @@ -1751,7 +1751,7 @@ mptsas_target_alloc(struct scsi_target *starget) int i; MPT_ADAPTER *ioc = hd->ioc; - vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL); + vtarget = kzalloc_obj(VirtTarget, GFP_KERNEL); if (!vtarget) return -ENOMEM; @@ -1878,7 +1878,7 @@ mptsas_sdev_init(struct scsi_device *sdev) int i; MPT_ADAPTER *ioc = hd->ioc; - vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL); + vdevice = kzalloc_obj(VirtDevice, GFP_KERNEL); if (!vdevice) { printk(MYIOC_s_ERR_FMT "sdev_init kzalloc(%zd) FAILED!\n", ioc->name, sizeof(VirtDevice)); @@ -2428,8 +2428,8 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info) goto out_free_consistent; port_info->num_phys = buffer->NumPhys; - port_info->phy_info = kcalloc(port_info->num_phys, - sizeof(struct mptsas_phyinfo), GFP_KERNEL); + port_info->phy_info = kzalloc_objs(struct mptsas_phyinfo, + port_info->num_phys, GFP_KERNEL); if (!port_info->phy_info) { error = -ENOMEM; goto out_free_consistent; @@ -2719,8 +2719,8 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info, /* save config data */ port_info->num_phys = (buffer->NumPhys) ? buffer->NumPhys : 1; - port_info->phy_info = kcalloc(port_info->num_phys, - sizeof(struct mptsas_phyinfo), GFP_KERNEL); + port_info->phy_info = kzalloc_objs(struct mptsas_phyinfo, + port_info->num_phys, GFP_KERNEL); if (!port_info->phy_info) { error = -ENOMEM; goto out_free_consistent; @@ -3309,7 +3309,7 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc) struct mptsas_portinfo *port_info, *hba; int error = -ENOMEM, i; - hba = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL); + hba = kzalloc_obj(struct mptsas_portinfo, GFP_KERNEL); if (! hba) goto out; @@ -3444,12 +3444,12 @@ mptsas_expander_event_add(MPT_ADAPTER *ioc, int i; __le64 sas_address; - port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL); + port_info = kzalloc_obj(struct mptsas_portinfo, GFP_KERNEL); BUG_ON(!port_info); port_info->num_phys = (expander_data->NumPhys) ? expander_data->NumPhys : 1; - port_info->phy_info = kcalloc(port_info->num_phys, - sizeof(struct mptsas_phyinfo), GFP_KERNEL); + port_info->phy_info = kzalloc_objs(struct mptsas_phyinfo, + port_info->num_phys, GFP_KERNEL); BUG_ON(!port_info->phy_info); memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64)); for (i = 0; i < port_info->num_phys; i++) { @@ -3677,7 +3677,7 @@ mptsas_expander_add(MPT_ADAPTER *ioc, u16 handle) MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle))) return NULL; - port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL); + port_info = kzalloc_obj(struct mptsas_portinfo, GFP_KERNEL); if (!port_info) { dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "%s: exit at line=%d\n", ioc->name, @@ -3945,7 +3945,7 @@ mptsas_probe_expanders(MPT_ADAPTER *ioc) continue; } - port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL); + port_info = kzalloc_obj(struct mptsas_portinfo, GFP_KERNEL); if (!port_info) { dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "%s: exit at line=%d\n", ioc->name, diff --git a/drivers/message/fusion/mptspi.c b/drivers/message/fusion/mptspi.c index 14707d19fbbd..62cf9d582386 100644 --- a/drivers/message/fusion/mptspi.c +++ b/drivers/message/fusion/mptspi.c @@ -405,7 +405,7 @@ static int mptspi_target_alloc(struct scsi_target *starget) return -ENODEV; ioc = hd->ioc; - vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL); + vtarget = kzalloc_obj(VirtTarget, GFP_KERNEL); if (!vtarget) return -ENOMEM; @@ -725,7 +725,7 @@ static int mptspi_sdev_init(struct scsi_device *sdev) mptscsih_is_phys_disk(ioc, 0, sdev->id) == 0) return -ENXIO; - vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL); + vdevice = kzalloc_obj(VirtDevice, GFP_KERNEL); if (!vdevice) { printk(MYIOC_s_ERR_FMT "sdev_init kmalloc(%zd) FAILED!\n", ioc->name, sizeof(VirtDevice)); @@ -1152,7 +1152,7 @@ static void mpt_work_wrapper(struct work_struct *work) static void mpt_dv_raid(struct _MPT_SCSI_HOST *hd, int disk) { - struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC); + struct work_queue_wrapper *wqw = kmalloc_obj(*wqw, GFP_ATOMIC); MPT_ADAPTER *ioc = hd->ioc; if (!wqw) { @@ -1288,7 +1288,7 @@ mptspi_dv_renegotiate_work(struct work_struct *work) static void mptspi_dv_renegotiate(struct _MPT_SCSI_HOST *hd) { - struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC); + struct work_queue_wrapper *wqw = kmalloc_obj(*wqw, GFP_ATOMIC); if (!wqw) return; |
