[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20190618202721.GD17978@ZenIV.linux.org.uk>
Date: Tue, 18 Jun 2019 21:27:21 +0100
From: Al Viro <viro@...iv.linux.org.uk>
To: Christoph Hellwig <hch@....de>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Sami Tolvanen <samitolvanen@...gle.com>,
Kees Cook <keescook@...omium.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
linux-mtd@...ts.infradead.org, linux-nfs@...r.kernel.org,
linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 3/4] jffs2: pass the correct prototype to read_cache_page
On Mon, May 20, 2019 at 07:57:30AM +0200, Christoph Hellwig wrote:
> Fix the callback jffs2 passes to read_cache_page to actually have the
> proper type expected. Casting around function pointers can easily
> hide typing bugs, and defeats control flow protection.
FWIW, this
unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c,
struct jffs2_inode_info *f,
unsigned long offset,
unsigned long *priv)
{
struct inode *inode = OFNI_EDONI_2SFFJ(f);
struct page *pg;
pg = read_cache_page(inode->i_mapping, offset >> PAGE_SHIFT,
(void *)jffs2_do_readpage_unlock, inode);
if (IS_ERR(pg))
return (void *)pg;
*priv = (unsigned long)pg;
return kmap(pg);
}
looks like crap. And so does this:
void jffs2_gc_release_page(struct jffs2_sb_info *c,
unsigned char *ptr,
unsigned long *priv)
{
struct page *pg = (void *)*priv;
kunmap(pg);
put_page(pg);
}
First of all, there's only one caller for each of those, and both
are direct calls. So passing struct page * around that way is ridiculous.
What's more, there is no reason not to do kmap() in caller (i.e. in
jffs2_garbage_collect_dnode()). That way jffs2_gc_fetch_page() would
simply be return read_cache_page(....), and in the caller we'd have
struct page *pg;
unsigned char *pg_ptr;
...
mutex_unlock(&f->sem);
pg = jffs2_gc_fetch_page(c, f, start);
if (IS_ERR(pg)) {
mutex_lock(&f->sem);
pr_warn("read_cache_page() returned error: %ld\n", PTR_ERR(pg));
return PTR_ERR(pg);
}
pg_ptr = kmap(pg);
mutex_lock(&f->sem);
...
kunmap(pg);
put_page(pg);
and that's it, preserving the current locking and with saner types...
Powered by blists - more mailing lists