From: Andreas Gruenbacher <agruenba@redhat.com>
To: gfs2@lists.linux.dev
Cc: Andreas Gruenbacher <agruenba@redhat.com>,
Adrian Garcia Casado <adriangarciacasado42@gmail.com>
Subject: [PATCH 1/6] gfs2: Avoid ip->i_gl dereferences in gfs2_inode_lookup and gfs2_create_inode
Date: Thu, 20 Aug 2026 16:21:22 +0200 [thread overview]
Message-ID: <20260820142129.1327413-2-agruenba@redhat.com> (raw)
In-Reply-To: <20260820142129.1327413-1-agruenba@redhat.com>
Store the inode glock in a separate variable instead of repeatedly retrieving
it as ip->i_gl.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/gfs2/inode.c | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index f361876c5583..438519bc06d4 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -130,6 +130,7 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
{
struct inode *inode;
struct gfs2_inode *ip;
+ struct gfs2_glock *gl = NULL;
struct gfs2_holder i_gh;
int error;
@@ -147,9 +148,10 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
gfs2_setup_inode(inode);
error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE,
- &ip->i_gl);
+ &gl);
if (unlikely(error))
goto fail;
+ ip->i_gl = gl;
error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE,
&io_gl);
@@ -178,14 +180,14 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
* block. We read the inode when instantiating it
* after possibly checking the block type.
*/
- error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE,
+ error = gfs2_glock_nq_init(gl, LM_ST_EXCLUSIVE,
GL_SKIP, &i_gh);
if (error)
goto fail;
error = -ESTALE;
if (no_formal_ino &&
- gfs2_inode_already_deleted(ip->i_gl, no_formal_ino))
+ gfs2_inode_already_deleted(gl, no_formal_ino))
goto fail;
if (blktype != GFS2_BLKST_FREE) {
@@ -196,20 +198,20 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
}
}
- set_bit(GLF_INSTANTIATE_NEEDED, &ip->i_gl->gl_flags);
+ set_bit(GLF_INSTANTIATE_NEEDED, &gl->gl_flags);
/* Lowest possible timestamp; will be overwritten in gfs2_dinode_in. */
inode_set_atime(inode,
1LL << (8 * sizeof(inode_get_atime_sec(inode)) - 1),
0);
- glock_set_object(ip->i_gl, ip);
+ glock_set_object(gl, ip);
if (type == DT_UNKNOWN) {
/* Inode glock must be locked already */
error = gfs2_instantiate(&i_gh);
if (error) {
- glock_clear_object(ip->i_gl, ip);
+ glock_clear_object(gl, ip);
goto fail;
}
} else {
@@ -240,8 +242,8 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
gfs2_glock_dq_uninit(&ip->i_iopen_gh);
if (gfs2_holder_initialized(&i_gh))
gfs2_glock_dq_uninit(&i_gh);
- if (ip->i_gl) {
- gfs2_glock_put(ip->i_gl);
+ if (gl) {
+ gfs2_glock_put(gl);
ip->i_gl = NULL;
}
iget_failed(inode);
@@ -708,7 +710,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
struct inode *inode = NULL;
struct gfs2_inode *dip = GFS2_I(dir), *ip;
struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
- struct gfs2_glock *io_gl;
+ struct gfs2_glock *gl = NULL, *io_gl;
int error, dealloc_error;
u32 aflags = 0;
unsigned blocks = 1;
@@ -832,9 +834,10 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
gfs2_set_inode_blocks(inode, blocks);
- error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
+ error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_inode_glops, CREATE, &gl);
if (error)
goto fail_dealloc_inode;
+ ip->i_gl = gl;
error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
if (error)
@@ -854,10 +857,10 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
if (error)
goto fail_gunlock2;
- error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, &gh);
+ error = gfs2_glock_nq_init(gl, LM_ST_EXCLUSIVE, GL_SKIP, &gh);
if (error)
goto fail_gunlock3;
- clear_bit(GLF_INSTANTIATE_NEEDED, &ip->i_gl->gl_flags);
+ clear_bit(GLF_INSTANTIATE_NEEDED, &gl->gl_flags);
error = gfs2_trans_begin(sdp, blocks, 0);
if (error)
@@ -870,7 +873,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
init_dinode(dip, ip, symname);
gfs2_trans_end(sdp);
- glock_set_object(ip->i_gl, ip);
+ glock_set_object(gl, ip);
glock_set_object(io_gl, ip);
gfs2_set_iop(inode);
@@ -914,7 +917,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
return error;
fail_gunlock4:
- glock_clear_object(ip->i_gl, ip);
+ glock_clear_object(gl, ip);
glock_clear_object(io_gl, ip);
fail_gunlock3:
gfs2_glock_dq_uninit(&ip->i_iopen_gh);
@@ -932,8 +935,8 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
fs_warn(sdp, "%s: %d\n", __func__, dealloc_error);
ip->i_no_addr = 0;
fail_free_inode:
- if (ip->i_gl) {
- gfs2_glock_put(ip->i_gl);
+ if (gl) {
+ gfs2_glock_put(gl);
ip->i_gl = NULL;
}
gfs2_rs_deltree(&ip->i_res);
--
2.55.0
next prev parent reply other threads:[~2026-08-20 14:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 14:21 [PATCH 0/6] gfs2: silence sparse Andreas Gruenbacher
2026-08-20 14:21 ` Andreas Gruenbacher [this message]
2026-08-20 14:21 ` [PATCH 2/6] gfs2: Get to super block from inode in tracepoints Andreas Gruenbacher
2026-08-20 14:21 ` [PATCH 3/6] gfs2: Add inode variables Andreas Gruenbacher
2026-08-20 14:21 ` [PATCH 4/6] gfs2: Introduce gfs2_inode_glock Andreas Gruenbacher
2026-08-20 14:21 ` [PATCH 5/6] gfs2: annotate i_gl with __rcu Andreas Gruenbacher
2026-08-20 14:21 ` [PATCH 6/6] gfs2: Silence sparse signedness warning Andreas Gruenbacher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260820142129.1327413-2-agruenba@redhat.com \
--to=agruenba@redhat.com \
--cc=adriangarciacasado42@gmail.com \
--cc=gfs2@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox