mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergey Shtylyov <s.shtylyov@omp.ru>
To: Jan Kara <jack@suse.cz>, <linux-kernel@vger.kernel.org>,
	<stable@vger.kernel.org>
Cc: <lvc-project@linuxtesting.org>
Subject: [PATCH v2 5.10.y] udf: Fold udf_getblk() into udf_bread()
Date: Thu, 19 Sep 2024 22:55:18 +0300	[thread overview]
Message-ID: <5b8bce06-de7c-e600-557b-6885abac0f43@omp.ru> (raw)

Subject: [PATCH v2 5.10.y] udf: Fold udf_getblk() into udf_bread()

From: Jan Kara <jack@suse.cz>

[ Upstream commit 32f123a3f34283f9c6446de87861696f0502b02e ]

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@suse.cz>
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>

---
This patch prevents NULL pointer dereference in case sb_getblk() fails...

Changes in version 2:
- mentioned the original commit.

 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;

                 reply	other threads:[~2024-09-19 19:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5b8bce06-de7c-e600-557b-6885abac0f43@omp.ru \
    --to=s.shtylyov@omp.ru \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®