[<prev] [next>] [day] [month] [year] [list]
Message-ID: <62f7666d-0a66-9ba5-61fd-a998e4169867@omp.ru>
Date: Wed, 18 Sep 2024 22:49:09 +0300
From: Sergey Shtylyov <s.shtylyov@....ru>
To: Jan Kara <jack@...e.cz>, <linux-kernel@...r.kernel.org>,
<stable@...r.kernel.org>
CC: <lvc-project@...uxtesting.org>
Subject: [PATCH 5.10.y] udf: Fold udf_getblk() into udf_bread()
From: Jan Kara <jack@...e.cz>
udf_getblk() has a single call site. Fold it there.
[Sergey: moved back to using udf_get_block() and buffer_{mapped|new}().]
Signed-off-by: Jan Kara <jack@...e.cz>
Signed-off-by: Sergey Shtylyov <s.shtylyov@....ru>
---
This patch prevents NULL pointer dereference in case sb_getblk() fails...
fs/udf/inode.c | 45 +++++++++++++++++++--------------------------
1 file changed, 19 insertions(+), 26 deletions(-)
Index: linux-stable/fs/udf/inode.c
===================================================================
--- linux-stable.orig/fs/udf/inode.c
+++ linux-stable/fs/udf/inode.c
@@ -458,30 +458,6 @@ abort:
return err;
}
-static struct buffer_head *udf_getblk(struct inode *inode, udf_pblk_t block,
- int create, int *err)
-{
- struct buffer_head *bh;
- struct buffer_head dummy;
-
- dummy.b_state = 0;
- dummy.b_blocknr = -1000;
- *err = udf_get_block(inode, block, &dummy, create);
- if (!*err && buffer_mapped(&dummy)) {
- bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
- if (buffer_new(&dummy)) {
- lock_buffer(bh);
- memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
- set_buffer_uptodate(bh);
- unlock_buffer(bh);
- mark_buffer_dirty_inode(bh, inode);
- }
- return bh;
- }
-
- return NULL;
-}
-
/* Extend the file with new blocks totaling 'new_block_bytes',
* return the number of extents added
*/
@@ -1197,10 +1173,27 @@ struct buffer_head *udf_bread(struct ino
int create, int *err)
{
struct buffer_head *bh = NULL;
+ struct buffer_head dummy;
+
+ dummy.b_state = 0;
+ dummy.b_blocknr = -1000;
+ *err = udf_get_block(inode, block, &dummy, create);
+ if (*err || !buffer_mapped(&dummy))
+ return NULL;
- bh = udf_getblk(inode, block, create, err);
- if (!bh)
+ bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
+ if (!bh) {
+ *err = -ENOMEM;
return NULL;
+ }
+ if (buffer_new(&dummy)) {
+ lock_buffer(bh);
+ memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
+ set_buffer_uptodate(bh);
+ unlock_buffer(bh);
+ mark_buffer_dirty_inode(bh, inode);
+ return bh;
+ }
if (buffer_uptodate(bh))
return bh;
Powered by blists - more mailing lists