ovl: properly print correct variable
PATCH 1/1 ovl: properly print correct variable
In case of ovl_lookup_temp() failure, we currently print err which is actually not initialized at all.
Instead, properly print PTR_ERR(whiteout) which is where the actual error really is.
Address-Coverity-ID: 1647983 ("Uninitialized variables (UNINIT)")
--- fs/overlayfs/dir.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/overlayfs/dir.c +3 -2
@@ -117,8 +117,9 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)if (!IS_ERR (whiteout))return whiteout;if (PTR_ERR (whiteout) != -EMLINK ) { -pr_warn ("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%i)\n" , - ofs->whiteout->d_inode->i_nlink, err); +pr_warn ("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%lu)\n" , + ofs->whiteout->d_inode->i_nlink, +PTR_ERR (whiteout)); ofs->no_shared_whiteout = true; } }
Signature · 1 line
2.49.1
Quoted 9 lines · Antonio Quartulli
In case of
ovl_lookup_temp()failure, we currently printerrwhich is actually not initialized at all.Instead, properly print
PTR_ERR(whiteout)which is where the actual error really is.Address-Coverity-ID: 1647983 ("Uninitialized variables (UNINIT)")
Fixes 8afa0a7367138 ("ovl: narrow locking in ovl_whiteout()")Signed-off-by Antonio Quartulli <[email protected]>
Thanks for this. I would probably go a step further and make the "err" variable local to the two blocks that it appears in - then this error would be detected by the compiler.
That isn't necessary though - this patch is good as it is.
Thanks,
NeilBrown
Quoted 24 lines
--- fs/overlayfs/dir.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/overlayfs/dir.c +3
-2@@ -117,8 +117,9 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)if (!IS_ERR (whiteout))return whiteout;if (PTR_ERR (whiteout) != -EMLINK ) { -pr_warn ("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%i)\n" , - ofs->whiteout->d_inode->i_nlink, err); +pr_warn ("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%lu)\n" , + ofs->whiteout->d_inode->i_nlink, +PTR_ERR (whiteout)); ofs->no_shared_whiteout = true; } }Signature · 1 line
2.49.1
Christian Brauner
AppliedQuoted 8 lines · Antonio Quartulli
In case of
ovl_lookup_temp()failure, we currently printerrwhich is actually not initialized at all.Instead, properly print
PTR_ERR(whiteout)which is where the actual error really is.[...]
Applied to the vfs-6.17.ovl branch of the vfs/vfs.git tree. Patches in the vfs-6.17.ovl branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.17.ovl
[1/1] ovl: properly print correct variable
https://git.kernel.org/vfs/vfs/c/672820a070ea
Hi,
Quoted 18 lines · Antonio Quartulli
In case of
ovl_lookup_temp()failure, we currently printerrwhich is actually not initialized at all.Instead, properly print
PTR_ERR(whiteout)which is where the actual error really is.Address-Coverity-ID: 1647983 ("Uninitialized variables (UNINIT)")
Fixes 8afa0a7367138 ("ovl: narrow locking in ovl_whiteout()")Signed-off-by Antonio Quartulli <[email protected]>--- fs/overlayfs/dir.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/overlayfs/dir.c +0
-0
fs/overlayfs/dir.c static struct dentry *ovl_whiteout(struct ovl_fs *ofs) · line 120
Quoted 6 lines
fs/overlayfs/dir.c +1
-2@@ -117,8 +117,9 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)if (!IS_ERR (whiteout))return whiteout;if (PTR_ERR (whiteout) != -EMLINK ) { -pr_warn ("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%i)\n" , - ofs->whiteout->d_inode->i_nlink, err); + pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%lu)\n",
while re-reading this patch, I realized that the format string for PTR_ERR(..) was supposed to be %ld, not %lu...
Sorry about that :(
Neil should I send yet another patch or maybe this can be sneaked into another change you are about to send?
Regards,
Quoted 5 lines
fs/overlayfs/dir.c +2
-0+ ofs->whiteout->d_inode->i_nlink, + PTR_ERR(whiteout)); ofs->no_shared_whiteout = true; } }
Signature · 5 lines
Antonio Quartulli CEO and Co-Founder Mandelbit Srl https://www.mandelbit.com
Amir Goldstein
maintainerQuoted 32 lines · Antonio Quartulli
Hi,
Quoted 18 lines · Antonio Quartulli
In case of
ovl_lookup_temp()failure, we currently printerrwhich is actually not initialized at all.Instead, properly print
PTR_ERR(whiteout)which is where the actual error really is.Address-Coverity-ID: 1647983 ("Uninitialized variables (UNINIT)")
Fixes 8afa0a7367138 ("ovl: narrow locking in ovl_whiteout()")Signed-off-by Antonio Quartulli <[email protected]>--- fs/overlayfs/dir.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/overlayfs/dir.c +0
-0fs/overlayfs/dir.c static struct dentry *ovl_whiteout(struct ovl_fs *ofs) · line 120
Quoted 6 lines
fs/overlayfs/dir.c +1
-2@@ -117,8 +117,9 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)if (!IS_ERR (whiteout))return whiteout;if (PTR_ERR (whiteout) != -EMLINK ) { -pr_warn ("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%i)\n" , - ofs->whiteout->d_inode->i_nlink, err); + pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%lu)\n",while re-reading this patch, I realized that the format string for
PTR_ERR(..)was supposed to be %ld, not %lu...
Quoted 1 line
Sorry about that :(
No worries, but its not %ld either. the error is an int.
Quoted 3 lines
Neil should I send yet another patch or maybe this can be sneaked into another change you are about to send?
Please test this fix suggested by Neil and send a patch to Christian.
fs/overlayfs/dir.c +0 -2
@@ -116,10 +116,10 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)inode_unlock (wdir);if (!IS_ERR (whiteout))return whiteout; -if (PTR_ERR (whiteout) != -EMLINK ) { - pr_warn("Failed to link whiteout - disabling
whiteout inode sharing(nlink=%u, err=%lu)\n",
- ofs->whiteout->d_inode->i_nlink,
- PTR_ERR(whiteout));
+ err = PTR_ERR(whiteout);
+ if (err != -EMLINK) {
+ pr_warn("Failed to link whiteout - disabling
whiteout inode sharing(nlink=%u, err=%i)\n",
+ ofs->whiteout->d_inode->i_nlink, err);
ofs->no_shared_whiteout = true;
}
}Thanks,
Amir.
Hi,
Quoted 34 lines · Amir Goldstein
Quoted 32 lines · Antonio Quartulli
Hi,
Quoted 18 lines · Antonio Quartulli
In case of
ovl_lookup_temp()failure, we currently printerrwhich is actually not initialized at all.Instead, properly print
PTR_ERR(whiteout)which is where the actual error really is.Address-Coverity-ID: 1647983 ("Uninitialized variables (UNINIT)")
Fixes 8afa0a7367138 ("ovl: narrow locking in ovl_whiteout()")Signed-off-by Antonio Quartulli <[email protected]>--- fs/overlayfs/dir.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/overlayfs/dir.c +0
-0fs/overlayfs/dir.c static struct dentry *ovl_whiteout(struct ovl_fs *ofs) · line 120
Quoted 6 lines
fs/overlayfs/dir.c +1
-2@@ -117,8 +117,9 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)if (!IS_ERR (whiteout))return whiteout;if (PTR_ERR (whiteout) != -EMLINK ) { -pr_warn ("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%i)\n" , - ofs->whiteout->d_inode->i_nlink, err); + pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%lu)\n",while re-reading this patch, I realized that the format string for
PTR_ERR(..)was supposed to be %ld, not %lu...
Quoted 3 lines
Quoted 1 line
Sorry about that :(
No worries, but its not %ld either. the error is an int.
PTR_ERR() returns long - this is what the patch is printing.
Quoted 24 lines
Quoted 4 lines
Neil should I send yet another patch or maybe this can be sneaked into another change you are about to send?
Please test this fix suggested by Neil and send a patch to Christian.
fs/overlayfs/dir.c +4
-4@@ -116,10 +116,10 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)inode_unlock (wdir);if (!IS_ERR (whiteout))return whiteout; -if (PTR_ERR (whiteout) != -EMLINK ) { - pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%lu)\n", - ofs->whiteout->d_inode->i_nlink, -PTR_ERR (whiteout)); + err =PTR_ERR (whiteout); +if (err != -EMLINK ) { + pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%i)\n", + ofs->whiteout->d_inode->i_nlink, err); ofs->no_shared_whiteout = true;
Quoted 2 lines
}
}Actually I think Neil was suggesting to make err local to the two blocks where it is currently used.
This way the compiler would have caught its usage out of scope in the first place.
It should be as listed below (including the format string fix). If you guys are fine with it, I'll send it as PATCH.
Thanks!
fs/overlayfs/dir.c +4 -4
@@ -80,7 +80,6 @@ struct dentry *ovl_lookup_temp(struct ovl_fs *ofs, struct dentry *workdir)static struct dentry *ovl_whiteout (struct ovl_fs *ofs) { -int err;struct dentry *whiteout;struct dentry *workdir = ofs->workdir;struct inode *wdir = workdir->d_inode;
@@ -91,7 +90,7 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)inode_lock_nested (wdir,I_MUTEX_PARENT ); whiteout =ovl_lookup_temp (ofs, workdir);if (!IS_ERR (whiteout)) { - err =ovl_do_whiteout (ofs, wdir, whiteout); +int err =ovl_do_whiteout (ofs, wdir, whiteout);if (err) {dput (whiteout); whiteout =ERR_PTR (err);
@@ -107,7 +106,8 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)inode_lock_nested (wdir,I_MUTEX_PARENT ); whiteout =ovl_lookup_temp (ofs, workdir);if (!IS_ERR (whiteout)) { - err =ovl_do_link (ofs, ofs->whiteout, wdir, whiteout); +int err =ovl_do_link (ofs, ofs->whiteout, wdir, + whiteout);if (err) {dput (whiteout); whiteout =ERR_PTR (err);
@@ -117,7 +117,7 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)if (!IS_ERR (whiteout))return whiteout;if (PTR_ERR (whiteout) != -EMLINK ) { -pr_warn ("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%lu)\n" , +pr_warn ("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%ld)\n" , ofs->whiteout->d_inode->i_nlink,PTR_ERR (whiteout)); ofs->no_shared_whiteout = true;
Signature · 5 lines
Antonio Quartulli CEO and Co-Founder Mandelbit Srl https://www.mandelbit.com
Amir Goldstein
maintainerQuoted 38 lines · Antonio Quartulli
Hi,
Quoted 34 lines · Amir Goldstein
Quoted 32 lines · Antonio Quartulli
Hi,
Quoted 18 lines · Antonio Quartulli
In case of
ovl_lookup_temp()failure, we currently printerrwhich is actually not initialized at all.Instead, properly print
PTR_ERR(whiteout)which is where the actual error really is.Address-Coverity-ID: 1647983 ("Uninitialized variables (UNINIT)")
Fixes 8afa0a7367138 ("ovl: narrow locking in ovl_whiteout()")Signed-off-by Antonio Quartulli <[email protected]>--- fs/overlayfs/dir.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/overlayfs/dir.c +0
-0fs/overlayfs/dir.c static struct dentry *ovl_whiteout(struct ovl_fs *ofs) · line 120
Quoted 6 lines
fs/overlayfs/dir.c +1
-2@@ -117,8 +117,9 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)if (!IS_ERR (whiteout))return whiteout;if (PTR_ERR (whiteout) != -EMLINK ) { -pr_warn ("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%i)\n" , - ofs->whiteout->d_inode->i_nlink, err); + pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%lu)\n",while re-reading this patch, I realized that the format string for
PTR_ERR(..)was supposed to be %ld, not %lu...
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Sorry about that :(
No worries, but its not %ld either. the error is an int.
PTR_ERR()returns long - this is what the patch is printing.
Doesn't matter what PTR_ERR returns, this is conceptually an int error code.
Quoted 31 lines
Quoted 25 lines
Quoted 5 lines
Neil should I send yet another patch or maybe this can be sneaked into another change you are about to send?
Please test this fix suggested by Neil and send a patch to Christian.
fs/overlayfs/dir.c +4
-4@@ -116,10 +116,10 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)inode_unlock (wdir);if (!IS_ERR (whiteout))return whiteout; -if (PTR_ERR (whiteout) != -EMLINK ) { - pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%lu)\n", - ofs->whiteout->d_inode->i_nlink, -PTR_ERR (whiteout)); + err =PTR_ERR (whiteout); +if (err != -EMLINK ) { + pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%i)\n", + ofs->whiteout->d_inode->i_nlink, err); ofs->no_shared_whiteout = true;Quoted 2 lines
} }Actually I think Neil was suggesting to make
errlocal to the two blocks where it is currently used.
Quoted 6 lines
This way the compiler would have caught its usage out of scope in the first place.
It should be as listed below (including the format string fix). If you guys are fine with it, I'll send it as PATCH.
Sorry I do not like this suggestion.
I prefer not to reduce the scope of err var
and not have to define it twice.
Thanks,
Amir.
Quoted 54 lines
Thanks!
fs/overlayfs/dir.c +0
-1@@ -80,7 +80,6 @@ struct dentry *ovl_lookup_temp(struct ovl_fs *ofs, struct dentry *workdir)static struct dentry *ovl_whiteout (struct ovl_fs *ofs) { -int err;struct dentry *whiteout;struct dentry *workdir = ofs->workdir;struct inode *wdir = workdir->d_inode;fs/overlayfs/dir.c +3
-2@@ -91,7 +90,7 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)inode_lock_nested (wdir,I_MUTEX_PARENT ); whiteout =ovl_lookup_temp (ofs, workdir);if (!IS_ERR (whiteout)) { - err =ovl_do_whiteout (ofs, wdir, whiteout); +int err =ovl_do_whiteout (ofs, wdir, whiteout);if (err) {dput (whiteout); whiteout =ERR_PTR (err);@@ -107,7 +106,8 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)inode_lock_nested (wdir,I_MUTEX_PARENT ); whiteout =ovl_lookup_temp (ofs, workdir);if (!IS_ERR (whiteout)) { - err =ovl_do_link (ofs, ofs->whiteout, wdir, whiteout); +int err =ovl_do_link (ofs, ofs->whiteout, wdir, + whiteout);if (err) {dput (whiteout);whiteout = ERR_PTR(err);fs/overlayfs/dir.c +1
-1@@ -117,7 +117,7 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)if (!IS_ERR (whiteout))return whiteout;if (PTR_ERR (whiteout) != -EMLINK ) { - pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%lu)\n", + pr_warn("Failed to link whiteout - disabling whiteout inode sharing(nlink=%u, err=%ld)\n", ofs->whiteout->d_inode->i_nlink,PTR_ERR(whiteout)); ofs->no_shared_whiteout = true;--
Antonio QuartulliCEO and Co-Founder
Mandelbit Srl
https://www.mandelbit.com