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/scsi/libsas | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | linux-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/scsi/libsas')
| -rw-r--r-- | drivers/scsi/libsas/sas_ata.c | 2 | ||||
| -rw-r--r-- | drivers/scsi/libsas/sas_expander.c | 2 | ||||
| -rw-r--r-- | drivers/scsi/libsas/sas_init.c | 4 | ||||
| -rw-r--r-- | drivers/scsi/libsas/sas_internal.h | 2 |
4 files changed, 5 insertions, 5 deletions
diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c index bcecb4911da9..0d24d6cc2dd8 100644 --- a/drivers/scsi/libsas/sas_ata.c +++ b/drivers/scsi/libsas/sas_ata.c @@ -579,7 +579,7 @@ int sas_ata_init(struct domain_device *found_dev) struct ata_port *ap; int rc; - ata_host = kzalloc(sizeof(*ata_host), GFP_KERNEL); + ata_host = kzalloc_obj(*ata_host, GFP_KERNEL); if (!ata_host) { pr_err("ata host alloc failed.\n"); return -ENOMEM; diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c index d953225f6cc2..e48b5233c2e9 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c @@ -433,7 +433,7 @@ static int sas_expander_discover(struct domain_device *dev) struct expander_device *ex = &dev->ex_dev; int res; - ex->ex_phy = kcalloc(ex->num_phys, sizeof(*ex->ex_phy), GFP_KERNEL); + ex->ex_phy = kzalloc_objs(*ex->ex_phy, ex->num_phys, GFP_KERNEL); if (!ex->ex_phy) return -ENOMEM; diff --git a/drivers/scsi/libsas/sas_init.c b/drivers/scsi/libsas/sas_init.c index 6b15ad1bcada..08e641374c85 100644 --- a/drivers/scsi/libsas/sas_init.c +++ b/drivers/scsi/libsas/sas_init.c @@ -39,7 +39,7 @@ struct sas_task *sas_alloc_task(gfp_t flags) struct sas_task *sas_alloc_slow_task(gfp_t flags) { struct sas_task *task = sas_alloc_task(flags); - struct sas_task_slow *slow = kmalloc(sizeof(*slow), flags); + struct sas_task_slow *slow = kmalloc_obj(*slow, flags); if (!task || !slow) { if (task) @@ -505,7 +505,7 @@ static void phy_enable_work(struct work_struct *work) static int sas_phy_setup(struct sas_phy *phy) { - struct sas_phy_data *d = kzalloc(sizeof(*d), GFP_KERNEL); + struct sas_phy_data *d = kzalloc_obj(*d, GFP_KERNEL); if (!d) return -ENOMEM; diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h index d104c87f04f5..fafcefcf722a 100644 --- a/drivers/scsi/libsas/sas_internal.h +++ b/drivers/scsi/libsas/sas_internal.h @@ -192,7 +192,7 @@ static inline void sas_phy_set_target(struct asd_sas_phy *p, struct domain_devic static inline struct domain_device *sas_alloc_device(void) { - struct domain_device *dev = kzalloc(sizeof(*dev), GFP_KERNEL); + struct domain_device *dev = kzalloc_obj(*dev, GFP_KERNEL); if (dev) { INIT_LIST_HEAD(&dev->siblings); |
