summaryrefslogtreecommitdiff
path: root/fs/ceph
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-21 10:49:23 +0300
committerKees Cook <kees@kernel.org>2026-02-21 12:02:28 +0300
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /fs/ceph
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlinux-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.xz
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 'fs/ceph')
-rw-r--r--fs/ceph/addr.c8
-rw-r--r--fs/ceph/caps.c2
-rw-r--r--fs/ceph/crypto.c4
-rw-r--r--fs/ceph/file.c6
-rw-r--r--fs/ceph/inode.c2
-rw-r--r--fs/ceph/mds_client.c17
-rw-r--r--fs/ceph/mdsmap.c4
-rw-r--r--fs/ceph/quota.c2
-rw-r--r--fs/ceph/snap.c4
-rw-r--r--fs/ceph/super.c6
-rw-r--r--fs/ceph/xattr.c10
11 files changed, 31 insertions, 34 deletions
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index ce09ff3e020f..e87b3bb94ee8 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -470,7 +470,7 @@ static int ceph_init_request(struct netfs_io_request *rreq, struct file *file)
if (rreq->origin != NETFS_READAHEAD)
return 0;
- priv = kzalloc(sizeof(*priv), GFP_NOFS);
+ priv = kzalloc_obj(*priv, GFP_NOFS);
if (!priv)
return -ENOMEM;
@@ -1186,9 +1186,7 @@ static inline
void __ceph_allocate_page_array(struct ceph_writeback_ctl *ceph_wbc,
unsigned int max_pages)
{
- ceph_wbc->pages = kmalloc_array(max_pages,
- sizeof(*ceph_wbc->pages),
- GFP_NOFS);
+ ceph_wbc->pages = kmalloc_objs(*ceph_wbc->pages, max_pages, GFP_NOFS);
if (!ceph_wbc->pages) {
ceph_wbc->from_pool = true;
ceph_wbc->pages = mempool_alloc(ceph_wb_pagevec_pool, GFP_NOFS);
@@ -2506,7 +2504,7 @@ static int __ceph_pool_perm_get(struct ceph_inode_info *ci,
}
pool_ns_len = pool_ns ? pool_ns->len : 0;
- perm = kmalloc(struct_size(perm, pool_ns, pool_ns_len + 1), GFP_NOFS);
+ perm = kmalloc_flex(*perm, pool_ns, pool_ns_len + 1, GFP_NOFS);
if (!perm) {
err = -ENOMEM;
goto out_unlock;
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 2f663972da99..5d7c2ffae8fa 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -2395,7 +2395,7 @@ static int flush_mdlog_and_wait_inode_unsafe_requests(struct inode *inode)
mutex_lock(&mdsc->mutex);
max_sessions = mdsc->max_sessions;
- sessions = kcalloc(max_sessions, sizeof(s), GFP_KERNEL);
+ sessions = kzalloc_objs(s, max_sessions, GFP_KERNEL);
if (!sessions) {
mutex_unlock(&mdsc->mutex);
err = -ENOMEM;
diff --git a/fs/ceph/crypto.c b/fs/ceph/crypto.c
index 9a115282f67d..643c8ba28ae7 100644
--- a/fs/ceph/crypto.c
+++ b/fs/ceph/crypto.c
@@ -50,7 +50,7 @@ static int ceph_crypt_set_context(struct inode *inode, const void *ctx,
if (len > FSCRYPT_SET_CONTEXT_MAX_SIZE)
return -EINVAL;
- cfa = kzalloc(sizeof(*cfa), GFP_KERNEL);
+ cfa = kzalloc_obj(*cfa, GFP_KERNEL);
if (!cfa)
return -ENOMEM;
@@ -112,7 +112,7 @@ int ceph_fscrypt_prepare_context(struct inode *dir, struct inode *inode,
if (!encrypted)
return 0;
- as->fscrypt_auth = kzalloc(sizeof(*as->fscrypt_auth), GFP_KERNEL);
+ as->fscrypt_auth = kzalloc_obj(*as->fscrypt_auth, GFP_KERNEL);
if (!as->fscrypt_auth)
return -ENOMEM;
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index 72cc67ab4ead..fdbf4aeaa408 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -140,7 +140,7 @@ static ssize_t iter_get_bvecs_alloc(struct iov_iter *iter, size_t maxsize,
* __iter_get_bvecs() may populate only part of the array -- zero it
* out.
*/
- bv = kvmalloc_array(npages, sizeof(*bv), GFP_KERNEL | __GFP_ZERO);
+ bv = kvmalloc_objs(*bv, npages, GFP_KERNEL | __GFP_ZERO);
if (!bv)
return -ENOMEM;
@@ -1344,7 +1344,7 @@ static void ceph_aio_complete_req(struct ceph_osd_request *req)
struct ceph_aio_work *aio_work;
BUG_ON(!aio_req->write);
- aio_work = kmalloc(sizeof(*aio_work), GFP_NOFS);
+ aio_work = kmalloc_obj(*aio_work, GFP_NOFS);
if (aio_work) {
INIT_WORK(&aio_work->work, ceph_aio_retry_work);
aio_work->req = req;
@@ -1572,7 +1572,7 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter,
*/
if (pos == iocb->ki_pos && !is_sync_kiocb(iocb) &&
(len == count || pos + count <= i_size_read(inode))) {
- aio_req = kzalloc(sizeof(*aio_req), GFP_KERNEL);
+ aio_req = kzalloc_obj(*aio_req, GFP_KERNEL);
if (aio_req) {
aio_req->iocb = iocb;
aio_req->write = write;
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 2966f88310e3..d76f9a79dc0c 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -321,7 +321,7 @@ static struct ceph_inode_frag *__get_or_create_frag(struct ceph_inode_info *ci,
return frag;
}
- frag = kmalloc(sizeof(*frag), GFP_NOFS);
+ frag = kmalloc_obj(*frag, GFP_NOFS);
if (!frag)
return ERR_PTR(-ENOMEM);
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index c45bd19d4b1c..8933f05f5144 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -973,7 +973,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
if (mds >= mdsc->mdsmap->possible_max_rank)
return ERR_PTR(-EINVAL);
- s = kzalloc(sizeof(*s), GFP_NOFS);
+ s = kzalloc_obj(*s, GFP_NOFS);
if (!s)
return ERR_PTR(-ENOMEM);
@@ -4230,9 +4230,8 @@ static void handle_session(struct ceph_mds_session *session,
goto skip_cap_auths;
}
- cap_auths = kcalloc(cap_auths_num,
- sizeof(struct ceph_mds_cap_auth),
- GFP_KERNEL);
+ cap_auths = kzalloc_objs(struct ceph_mds_cap_auth,
+ cap_auths_num, GFP_KERNEL);
if (!cap_auths) {
pr_err_client(cl, "No memory for cap_auths\n");
return;
@@ -4731,9 +4730,9 @@ encode_again:
num_flock_locks = 0;
}
if (num_fcntl_locks + num_flock_locks > 0) {
- flocks = kmalloc_array(num_fcntl_locks + num_flock_locks,
- sizeof(struct ceph_filelock),
- GFP_NOFS);
+ flocks = kmalloc_objs(struct ceph_filelock,
+ num_fcntl_locks + num_flock_locks,
+ GFP_NOFS);
if (!flocks) {
err = -ENOMEM;
goto out_err;
@@ -5534,12 +5533,12 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)
struct ceph_mds_client *mdsc;
int err;
- mdsc = kzalloc(sizeof(struct ceph_mds_client), GFP_NOFS);
+ mdsc = kzalloc_obj(struct ceph_mds_client, GFP_NOFS);
if (!mdsc)
return -ENOMEM;
mdsc->fsc = fsc;
mutex_init(&mdsc->mutex);
- mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS);
+ mdsc->mdsmap = kzalloc_obj(*mdsc->mdsmap, GFP_NOFS);
if (!mdsc->mdsmap) {
err = -ENOMEM;
goto err_mdsc;
diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c
index b228e5ecfb92..d8e46eb7e5eb 100644
--- a/fs/ceph/mdsmap.c
+++ b/fs/ceph/mdsmap.c
@@ -127,7 +127,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(struct ceph_mds_client *mdsc, void **p,
u16 mdsmap_ev;
u32 target;
- m = kzalloc(sizeof(*m), GFP_NOFS);
+ m = kzalloc_obj(*m, GFP_NOFS);
if (!m)
return ERR_PTR(-ENOMEM);
@@ -169,7 +169,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(struct ceph_mds_client *mdsc, void **p,
*/
m->possible_max_rank = max(m->m_num_active_mds, m->m_max_mds);
- m->m_info = kcalloc(m->possible_max_rank, sizeof(*m->m_info), GFP_NOFS);
+ m->m_info = kzalloc_objs(*m->m_info, m->possible_max_rank, GFP_NOFS);
if (!m->m_info)
goto nomem;
diff --git a/fs/ceph/quota.c b/fs/ceph/quota.c
index d90eda19bcc4..514da29469b8 100644
--- a/fs/ceph/quota.c
+++ b/fs/ceph/quota.c
@@ -103,7 +103,7 @@ find_quotarealm_inode(struct ceph_mds_client *mdsc, u64 ino)
}
if (!qri || (qri->ino != ino)) {
/* Not found, create a new one and insert it */
- qri = kmalloc(sizeof(*qri), GFP_KERNEL);
+ qri = kmalloc_obj(*qri, GFP_KERNEL);
if (qri) {
qri->ino = ino;
qri->inode = NULL;
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index 521507ea8260..52b4c2684f92 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -118,7 +118,7 @@ static struct ceph_snap_realm *ceph_create_snap_realm(
lockdep_assert_held_write(&mdsc->snap_rwsem);
- realm = kzalloc(sizeof(*realm), GFP_NOFS);
+ realm = kzalloc_obj(*realm, GFP_NOFS);
if (!realm)
return ERR_PTR(-ENOMEM);
@@ -1216,7 +1216,7 @@ struct ceph_snapid_map* ceph_get_snapid_map(struct ceph_mds_client *mdsc,
return exist;
}
- sm = kmalloc(sizeof(*sm), GFP_NOFS);
+ sm = kmalloc_obj(*sm, GFP_NOFS);
if (!sm)
return NULL;
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 7c1c1dac320d..57320e830eda 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -809,7 +809,7 @@ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
struct ceph_fs_client *fsc;
int err;
- fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
+ fsc = kzalloc_obj(*fsc, GFP_KERNEL);
if (!fsc) {
err = -ENOMEM;
goto fail;
@@ -1429,7 +1429,7 @@ static int ceph_init_fs_context(struct fs_context *fc)
struct ceph_parse_opts_ctx *pctx;
struct ceph_mount_options *fsopt;
- pctx = kzalloc(sizeof(*pctx), GFP_KERNEL);
+ pctx = kzalloc_obj(*pctx, GFP_KERNEL);
if (!pctx)
return -ENOMEM;
@@ -1437,7 +1437,7 @@ static int ceph_init_fs_context(struct fs_context *fc)
if (!pctx->copts)
goto nomem;
- pctx->opts = kzalloc(sizeof(*pctx->opts), GFP_KERNEL);
+ pctx->opts = kzalloc_obj(*pctx->opts, GFP_KERNEL);
if (!pctx->opts)
goto nomem;
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index ad1f30bea175..5f87f62091a1 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -819,15 +819,15 @@ start:
xattr_version = ci->i_xattrs.version;
spin_unlock(&ci->i_ceph_lock);
- xattrs = kcalloc(numattr, sizeof(struct ceph_inode_xattr *),
- GFP_NOFS);
+ xattrs = kzalloc_objs(struct ceph_inode_xattr *, numattr,
+ GFP_NOFS);
err = -ENOMEM;
if (!xattrs)
goto bad_lock;
for (i = 0; i < numattr; i++) {
- xattrs[i] = kmalloc(sizeof(struct ceph_inode_xattr),
- GFP_NOFS);
+ xattrs[i] = kmalloc_obj(struct ceph_inode_xattr,
+ GFP_NOFS);
if (!xattrs[i])
goto bad_lock;
}
@@ -1220,7 +1220,7 @@ int __ceph_setxattr(struct inode *inode, const char *name,
goto out;
}
- xattr = kmalloc(sizeof(struct ceph_inode_xattr), GFP_NOFS);
+ xattr = kmalloc_obj(struct ceph_inode_xattr, GFP_NOFS);
if (!xattr)
goto out;