Message ID | 20190520055731.24538-4-hch@lst.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/4] mm: fix an overly long line in read_cache_page | expand |
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...
diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c index 7d8654a1472e..f8fb89b10227 100644 --- a/fs/jffs2/file.c +++ b/fs/jffs2/file.c @@ -109,9 +109,9 @@ static int jffs2_do_readpage_nolock (struct inode *inode, struct page *pg) return ret; } -int jffs2_do_readpage_unlock(struct inode *inode, struct page *pg) +int jffs2_do_readpage_unlock(void *data, struct page *pg) { - int ret = jffs2_do_readpage_nolock(inode, pg); + int ret = jffs2_do_readpage_nolock(data, pg); unlock_page(pg); return ret; } diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c index 112d85849db1..8a20ddd25f2d 100644 --- a/fs/jffs2/fs.c +++ b/fs/jffs2/fs.c @@ -687,7 +687,7 @@ unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c, struct page *pg; pg = read_cache_page(inode->i_mapping, offset >> PAGE_SHIFT, - (void *)jffs2_do_readpage_unlock, inode); + jffs2_do_readpage_unlock, inode); if (IS_ERR(pg)) return (void *)pg; diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h index a2dbbb3f4c74..bd3d5f0ddc34 100644 --- a/fs/jffs2/os-linux.h +++ b/fs/jffs2/os-linux.h @@ -155,7 +155,7 @@ extern const struct file_operations jffs2_file_operations; extern const struct inode_operations jffs2_file_inode_operations; extern const struct address_space_operations jffs2_file_address_operations; int jffs2_fsync(struct file *, loff_t, loff_t, int); -int jffs2_do_readpage_unlock (struct inode *inode, struct page *pg); +int jffs2_do_readpage_unlock(void *data, struct page *pg); /* ioctl.c */ long jffs2_ioctl(struct file *, unsigned int, unsigned long);