Use dput() after d_find_alias().
Subsystems (6)
cover Use dput() after d_find_alias().
Hello,
A call to d_find_alias() needs a corresponding call to dput() in order to avoid resource leaks.
The first patch is a Coccinelle scripts that looks for missing calls to dput(). The other two patches add calls to dput() where needed.
WBR,
Cyril Roelandt.
PATCH 1/3 Coccinelle: Add api/d_find_alias.cocci.
Ensure that calls to d_find_alias() have a corresponding dput().
--- scripts/coccinelle/api/d_find_alias.cocci | 80 +++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 scripts/coccinelle/api/d_find_alias.cocci
scripts/coccinelle/api/d_find_alias.cocci new file +80 -0
@@ -0,0 +1,80 @@ +/// Make sure calls to d_find_alias() have a corresponding call to dput(). +// +// Keywords: d_find_alias, dput +// +// Confidence: Moderate +// URL: http://coccinelle.lip6.fr/ +// Options: -include_headers + +virtual context +virtual org +virtual patch +virtual report + + at r exists@ +local idexpression struct dentry *dent; +expression E, E1; +statement S1, S2; +position p1, p2; +@@ +( + if (!(dent at p1 = d_find_alias(...))) S1 +| + dent at p1 = d_find_alias(...) +) + +<...when != dput(dent) + when != if (...) { <+... dput(dent) ...+> } + when != true !dent || ... + when != dent = E + when != E = dent +if (!dent || ...) S2 +...> +( + return <+...dent...+>; +| + return @p2 ...; +| + dent at p2 = E1; +| + E1 = dent; +) + + at depends on context@ +local idexpression struct dentry *r.dent; +position r.p1,r.p2; +@@ +* dent at p1 = ... + ... +( +* return at p2 ...; +| +* dent at p2 +) + + + at script:python depends on org@ +p1 << r.p1; +p2 << r.p2; +@@ +cocci.print_main("Missing call to dput()",p1) +cocci.print_secs("",p2) + + at depends on patch@ +local idexpression struct dentry *r.dent; +position r.p2; +@@ +( ++ dput(dent); + return @p2 ...; +| ++ dput(dent); + dent at p2 = ...; +) + + at script:python depends on report@ +p1 << r.p1; +p2 << r.p2; +@@ +msg = "Missing call to dput()@line %s." +coccilib.report.print_report(p1[0], msg % (p2[0].line))
Signature · 1 line
1.7.10.4
PATCH 2/3 iommu/tegra-smmu.c: fix dentry reference leak in smmu_debugfs_stats_show().
In reply to Cyril RoelandtCall to d_find_alias() needs a corresponding dput().
--- drivers/iommu/tegra-smmu.c | 1 + 1 file changed, 1 insertion(+)
drivers/iommu/tegra-smmu.c +1 -0
@@ -1052,6 +1052,7 @@ static int smmu_debugfs_stats_show(struct seq_file *s, void *v) stats[i], val, offs); }seq_printf (s,"\n" ); +dput (dent);return 0 ; }
Signature · 1 line
1.7.10.4
PATCH 3/3 ceph: fix dentry reference leak in ceph_encode_fh().
In reply to Cyril Roelandtdput() was not called in the error path.
--- fs/ceph/export.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/export.c +3 -1
@@ -56,13 +56,15 @@ static int ceph_encode_fh(struct inode *inode, u32 *rawfh, int *max_len,struct ceph_nfs_confh *cfh = (void *)rawfh;int connected_handle_length =sizeof (*cfh)/4 ;int handle_length =sizeof (*fh)/4 ; -struct dentry *dentry =d_find_alias (inode); +struct dentry *dentry;struct dentry *parent;/* don't re-export snaps */ if (ceph_snap (inode) !=CEPH_NOSNAP )return -EINVAL ; + dentry =d_find_alias (inode); +/* if we found an alias, generate a connectable fh */ if (*max_len >= connected_handle_length && dentry) {dout ("encode_fh %p connectable\n" , dentry);
Signature · 1 line
1.7.10.4
Re: [PATCH 2/3] iommu/tegra-smmu.c: fix dentry reference leak in smmu_debugfs_stats_show().
In reply to Cyril RoelandtCyril Roelandt <[email protected]> wrote @ Sun, 11 Nov 2012 21:49:30 +0100:
Quoted 4 lines
Call to
d_find_alias()needs a correspondingdput().Signed-off-by Cyril Roelandt <[email protected]>---
Thanks. Looks ok for me. Acked-by Hiroshi Doyu <[email protected]>
Re: [PATCH 2/3] iommu/tegra-smmu.c: fix dentry reference leak in smmu_debugfs_stats_show().
In reply to Cyril RoelandtQuoted 3 lines · Cyril Roelandt
Call to
d_find_alias()needs a correspondingdput().Signed-off-by Cyril Roelandt <[email protected]>
Applied to iommu/fixes, thanks.
Re: [PATCH 3/3] ceph: fix dentry reference leak in ceph_encode_fh().
In reply to Cyril RoelandtQuoted 3 lines · Cyril Roelandt
dput()was not called in the error path.Signed-off-by Cyril Roelandt <[email protected]>
This looks good, thanks a lot. I'll apply it.
Quoted 26 lines
--- fs/ceph/export.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/ceph/export.c +3
-1@@ -56,13 +56,15 @@ static int ceph_encode_fh(struct inode *inode, u32 *rawfh, int *max_len,struct ceph_nfs_confh *cfh = (void *)rawfh;int connected_handle_length =sizeof (*cfh)/4 ;int handle_length =sizeof (*fh)/4 ; -struct dentry *dentry =d_find_alias (inode); +struct dentry *dentry;struct dentry *parent;/* don't re-export snaps */ if (ceph_snap (inode) !=CEPH_NOSNAP )return -EINVAL ; + dentry =d_find_alias (inode); +/* if we found an alias, generate a connectable fh */ if (*max_len >= connected_handle_length && dentry) {dout ("encode_fh %p connectable\n" , dentry);