]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
authorKees Cook <kees@kernel.org>
Sun, 22 Feb 2026 22:41:11 +0000 (14:41 -0800)
committerAndrey Albershteyn <aalbersh@kernel.org>
Wed, 8 Apr 2026 19:39:56 +0000 (21:39 +0200)
Source kernel commit: 69050f8d6d075dc01af7a5f2f550a8067510366f

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>
libxfs/xfs_ag.c
libxfs/xfs_defer.c
libxfs/xfs_dir2.c
libxfs/xfs_refcount.c
libxfs/xfs_rtgroup.c

index 8ccd67672b4e00768294f2e9e10dd15c20e038f9..0f1eaf5d6e39b89e769087521c2e244c9fff1b94 100644 (file)
@@ -222,7 +222,7 @@ xfs_perag_alloc(
        struct xfs_perag        *pag;
        int                     error;
 
-       pag = kzalloc(sizeof(*pag), GFP_KERNEL);
+       pag = kzalloc_obj(*pag, GFP_KERNEL);
        if (!pag)
                return -ENOMEM;
 
index c0d3aa401cbab5f8d1f7a71eed448e6a5ea761d1..e4d17177f67fafa53485aa17315479211d639026 100644 (file)
@@ -975,7 +975,7 @@ xfs_defer_ops_capture(
                return ERR_PTR(error);
 
        /* Create an object to capture the defer ops. */
-       dfc = kzalloc(sizeof(*dfc), GFP_KERNEL | __GFP_NOFAIL);
+       dfc = kzalloc_obj(*dfc, GFP_KERNEL | __GFP_NOFAIL);
        INIT_LIST_HEAD(&dfc->dfc_list);
        INIT_LIST_HEAD(&dfc->dfc_dfops);
 
index 2ca6bf198ba54ff4d81015c39098eef1d3643872..1a13fec25e15b3d65793e8ad28fd2b1775174934 100644 (file)
@@ -115,10 +115,10 @@ xfs_da_mount(
        ASSERT(mp->m_sb.sb_versionnum & XFS_SB_VERSION_DIRV2BIT);
        ASSERT(xfs_dir2_dirblock_bytes(&mp->m_sb) <= XFS_MAX_BLOCKSIZE);
 
-       mp->m_dir_geo = kzalloc(sizeof(struct xfs_da_geometry),
-                               GFP_KERNEL | __GFP_RETRY_MAYFAIL);
-       mp->m_attr_geo = kzalloc(sizeof(struct xfs_da_geometry),
-                               GFP_KERNEL | __GFP_RETRY_MAYFAIL);
+       mp->m_dir_geo = kzalloc_obj(struct xfs_da_geometry,
+                                   GFP_KERNEL | __GFP_RETRY_MAYFAIL);
+       mp->m_attr_geo = kzalloc_obj(struct xfs_da_geometry,
+                                    GFP_KERNEL | __GFP_RETRY_MAYFAIL);
        if (!mp->m_dir_geo || !mp->m_attr_geo) {
                kfree(mp->m_dir_geo);
                kfree(mp->m_attr_geo);
@@ -247,7 +247,7 @@ xfs_dir_init(
        if (error)
                return error;
 
-       args = kzalloc(sizeof(*args), GFP_KERNEL | __GFP_NOFAIL);
+       args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
        if (!args)
                return -ENOMEM;
 
@@ -340,7 +340,7 @@ xfs_dir_createname(
                XFS_STATS_INC(dp->i_mount, xs_dir_create);
        }
 
-       args = kzalloc(sizeof(*args), GFP_KERNEL | __GFP_NOFAIL);
+       args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
        if (!args)
                return -ENOMEM;
 
@@ -436,8 +436,7 @@ xfs_dir_lookup(
        ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
        XFS_STATS_INC(dp->i_mount, xs_dir_lookup);
 
-       args = kzalloc(sizeof(*args),
-                       GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
+       args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
        args->geo = dp->i_mount->m_dir_geo;
        args->name = name->name;
        args->namelen = name->len;
@@ -502,7 +501,7 @@ xfs_dir_removename(
        ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
        XFS_STATS_INC(dp->i_mount, xs_dir_remove);
 
-       args = kzalloc(sizeof(*args), GFP_KERNEL | __GFP_NOFAIL);
+       args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
        if (!args)
                return -ENOMEM;
 
@@ -562,7 +561,7 @@ xfs_dir_replace(
        if (rval)
                return rval;
 
-       args = kzalloc(sizeof(*args), GFP_KERNEL | __GFP_NOFAIL);
+       args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
        if (!args)
                return -ENOMEM;
 
index 5c362e0e901124677726cb0d0c4c9ab870fb9724..036497dbb22b702ebf5b78d07a94fca60302a8c0 100644 (file)
@@ -2031,8 +2031,8 @@ xfs_refcount_recover_extent(
                return -EFSCORRUPTED;
        }
 
-       rr = kmalloc(sizeof(struct xfs_refcount_recovery),
-                       GFP_KERNEL | __GFP_NOFAIL);
+       rr = kmalloc_obj(struct xfs_refcount_recovery,
+                        GFP_KERNEL | __GFP_NOFAIL);
        INIT_LIST_HEAD(&rr->rr_list);
        xfs_refcount_btrec_to_irec(rec, &rr->rr_rrec);
 
index af4eafb20bc138b57518c38755174b1175f56cfd..69e71494057a1e6488ede6cbea88328cc00ea905 100644 (file)
@@ -95,7 +95,7 @@ xfs_rtgroup_alloc(
        struct xfs_rtgroup      *rtg;
        int                     error;
 
-       rtg = kzalloc(sizeof(struct xfs_rtgroup), GFP_KERNEL);
+       rtg = kzalloc_obj(struct xfs_rtgroup, GFP_KERNEL);
        if (!rtg)
                return -ENOMEM;