summaryrefslogtreecommitdiff
path: root/drivers/ata
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-20 23:49:23 -0800
committerKees Cook <kees@kernel.org>2026-02-21 01:02:28 -0800
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/ata
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlinux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz
linux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.zip
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/ata')
-rw-r--r--drivers/ata/libahci_platform.c3
-rw-r--r--drivers/ata/libata-acpi.c4
-rw-r--r--drivers/ata/libata-core.c8
-rw-r--r--drivers/ata/libata-pmp.c4
-rw-r--r--drivers/ata/libata-sata.c2
-rw-r--r--drivers/ata/libata-transport.c2
-rw-r--r--drivers/ata/libata-zpodd.c2
-rw-r--r--drivers/ata/pata_parport/pata_parport.c2
-rw-r--r--drivers/ata/sata_dwc_460ex.c2
-rw-r--r--drivers/ata/sata_fsl.c4
10 files changed, 17 insertions, 16 deletions
diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c
index 91d44302eac9..12c3a0330f67 100644
--- a/drivers/ata/libahci_platform.c
+++ b/drivers/ata/libahci_platform.c
@@ -594,7 +594,8 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
* We cannot use devm_ here, since ahci_platform_put_resources() uses
* target_pwrs after devm_ have freed memory
*/
- hpriv->target_pwrs = kcalloc(hpriv->nports, sizeof(*hpriv->target_pwrs), GFP_KERNEL);
+ hpriv->target_pwrs = kzalloc_objs(*hpriv->target_pwrs, hpriv->nports,
+ GFP_KERNEL);
if (!hpriv->target_pwrs) {
rc = -ENOMEM;
goto err_out;
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index 15e18d50dcc6..a618313dea03 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -194,7 +194,7 @@ void ata_acpi_bind_port(struct ata_port *ap)
if (!adev || adev->hp)
return;
- context = kzalloc(sizeof(*context), GFP_KERNEL);
+ context = kzalloc_obj(*context, GFP_KERNEL);
if (!context)
return;
@@ -236,7 +236,7 @@ void ata_acpi_bind_dev(struct ata_device *dev)
if (!adev || adev->hp)
return;
- context = kzalloc(sizeof(*context), GFP_KERNEL);
+ context = kzalloc_obj(*context, GFP_KERNEL);
if (!context)
return;
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index beb6984b379a..02dde2517122 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -2557,7 +2557,7 @@ static int ata_dev_init_cdl_resources(struct ata_device *dev)
unsigned int err_mask;
if (!cdl) {
- cdl = kzalloc(sizeof(*cdl), GFP_KERNEL);
+ cdl = kzalloc_obj(*cdl, GFP_KERNEL);
if (!cdl)
return -ENOMEM;
dev->cdl = cdl;
@@ -2832,7 +2832,7 @@ static void ata_dev_config_cpr(struct ata_device *dev)
if (!nr_cpr)
goto out;
- cpr_log = kzalloc(struct_size(cpr_log, cpr, nr_cpr), GFP_KERNEL);
+ cpr_log = kzalloc_flex(*cpr_log, cpr, nr_cpr, GFP_KERNEL);
if (!cpr_log)
goto out;
@@ -5638,7 +5638,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
struct ata_port *ap;
int id;
- ap = kzalloc(sizeof(*ap), GFP_KERNEL);
+ ap = kzalloc_obj(*ap, GFP_KERNEL);
if (!ap)
return NULL;
@@ -6714,7 +6714,7 @@ static void __init ata_parse_force_param(void)
if (*p == ',')
size++;
- ata_force_tbl = kcalloc(size, sizeof(ata_force_tbl[0]), GFP_KERNEL);
+ ata_force_tbl = kzalloc_objs(ata_force_tbl[0], size, GFP_KERNEL);
if (!ata_force_tbl) {
printk(KERN_WARNING "ata: failed to extend force table, "
"libata.force ignored\n");
diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
index 57023324a56f..e3adc008fed1 100644
--- a/drivers/ata/libata-pmp.c
+++ b/drivers/ata/libata-pmp.c
@@ -339,8 +339,8 @@ static int sata_pmp_init_links (struct ata_port *ap, int nr_ports)
int i, err;
if (!pmp_link) {
- pmp_link = kcalloc(SATA_PMP_MAX_PORTS, sizeof(pmp_link[0]),
- GFP_NOIO);
+ pmp_link = kzalloc_objs(pmp_link[0], SATA_PMP_MAX_PORTS,
+ GFP_NOIO);
if (!pmp_link)
return -ENOMEM;
diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c
index 04e1e774645e..04a0ad66958e 100644
--- a/drivers/ata/libata-sata.c
+++ b/drivers/ata/libata-sata.c
@@ -849,7 +849,7 @@ int ata_slave_link_init(struct ata_port *ap)
WARN_ON(ap->slave_link);
WARN_ON(ap->flags & ATA_FLAG_PMP);
- link = kzalloc(sizeof(*link), GFP_KERNEL);
+ link = kzalloc_obj(*link, GFP_KERNEL);
if (!link)
return -ENOMEM;
diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
index 62415fe67a11..85340ef98be3 100644
--- a/drivers/ata/libata-transport.c
+++ b/drivers/ata/libata-transport.c
@@ -758,7 +758,7 @@ struct scsi_transport_template *ata_attach_transport(void)
struct ata_internal *i;
int count;
- i = kzalloc(sizeof(struct ata_internal), GFP_KERNEL);
+ i = kzalloc_obj(struct ata_internal, GFP_KERNEL);
if (!i)
return NULL;
diff --git a/drivers/ata/libata-zpodd.c b/drivers/ata/libata-zpodd.c
index 799531218ea2..e550327e7bd9 100644
--- a/drivers/ata/libata-zpodd.c
+++ b/drivers/ata/libata-zpodd.c
@@ -274,7 +274,7 @@ void zpodd_init(struct ata_device *dev)
if (mech_type == ODD_MECH_TYPE_UNSUPPORTED)
return;
- zpodd = kzalloc(sizeof(struct zpodd), GFP_KERNEL);
+ zpodd = kzalloc_obj(struct zpodd, GFP_KERNEL);
if (!zpodd)
return;
diff --git a/drivers/ata/pata_parport/pata_parport.c b/drivers/ata/pata_parport/pata_parport.c
index 22bd3ff6b7ae..93ca62cc6390 100644
--- a/drivers/ata/pata_parport/pata_parport.c
+++ b/drivers/ata/pata_parport/pata_parport.c
@@ -511,7 +511,7 @@ static struct pi_adapter *pi_init_one(struct parport *parport,
if (id < 0)
return NULL;
- pi = kzalloc(sizeof(struct pi_adapter), GFP_KERNEL);
+ pi = kzalloc_obj(struct pi_adapter, GFP_KERNEL);
if (!pi) {
ida_free(&pata_parport_bus_dev_ids, id);
return NULL;
diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c
index 7a4f59202156..e4fe47c8fa75 100644
--- a/drivers/ata/sata_dwc_460ex.c
+++ b/drivers/ata/sata_dwc_460ex.c
@@ -850,7 +850,7 @@ static int sata_dwc_port_start(struct ata_port *ap)
}
/* Allocate Port Struct */
- hsdevp = kzalloc(sizeof(*hsdevp), GFP_KERNEL);
+ hsdevp = kzalloc_obj(*hsdevp, GFP_KERNEL);
if (!hsdevp) {
err = -ENOMEM;
goto CLEANUP;
diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
index 84da8d6ef28e..703febbe0c03 100644
--- a/drivers/ata/sata_fsl.c
+++ b/drivers/ata/sata_fsl.c
@@ -706,7 +706,7 @@ static int sata_fsl_port_start(struct ata_port *ap)
void __iomem *hcr_base = host_priv->hcr_base;
u32 temp;
- pp = kzalloc(sizeof(*pp), GFP_KERNEL);
+ pp = kzalloc_obj(*pp, GFP_KERNEL);
if (!pp)
return -ENOMEM;
@@ -1451,7 +1451,7 @@ static int sata_fsl_probe(struct platform_device *ofdev)
dev_dbg(&ofdev->dev, "@reset i/o = 0x%x\n",
ioread32(csr_base + TRANSCFG));
- host_priv = kzalloc(sizeof(struct sata_fsl_host_priv), GFP_KERNEL);
+ host_priv = kzalloc_obj(struct sata_fsl_host_priv, GFP_KERNEL);
if (!host_priv)
goto error_exit_with_cleanup;