From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Darrick J. Wong" <djwong@kernel.org>,
Luis Chamberlain <mcgrof@kernel.org>,
Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
Sasha Levin <sashal@kernel.org>,
linux-block@vger.kernel.org
Subject: [PATCH AUTOSEL 6.14 36/39] block: hoist block size validation code to a separate function
Date: Tue, 29 Apr 2025 19:50:03 -0400 [thread overview]
Message-ID: <20250429235006.536648-36-sashal@kernel.org> (raw)
In-Reply-To: <20250429235006.536648-1-sashal@kernel.org>
From: "Darrick J. Wong" <djwong@kernel.org>
[ Upstream commit e03463d247ddac66e71143468373df3d74a3a6bd ]
Hoist the block size validation code to bdev_validate_blocksize so that
we can call it from filesystems that don't care about the bdev pagecache
manipulations of set_blocksize.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/174543795720.4139148.840349813093799165.stgit@frogsfrogsfrogs
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
block/bdev.c | 33 +++++++++++++++++++++++++++------
include/linux/blkdev.h | 1 +
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/block/bdev.c b/block/bdev.c
index 06b8cab31d759..e5af18bc43082 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -150,18 +150,39 @@ static void set_init_blocksize(struct block_device *bdev)
BD_INODE(bdev)->i_blkbits = blksize_bits(bsize);
}
-int set_blocksize(struct file *file, int size)
+/**
+ * bdev_validate_blocksize - check that this block size is acceptable
+ * @bdev: blockdevice to check
+ * @block_size: block size to check
+ *
+ * For block device users that do not use buffer heads or the block device
+ * page cache, make sure that this block size can be used with the device.
+ *
+ * Return: On success zero is returned, negative error code on failure.
+ */
+int bdev_validate_blocksize(struct block_device *bdev, int block_size)
{
- struct inode *inode = file->f_mapping->host;
- struct block_device *bdev = I_BDEV(inode);
-
- if (blk_validate_block_size(size))
+ if (blk_validate_block_size(block_size))
return -EINVAL;
/* Size cannot be smaller than the size supported by the device */
- if (size < bdev_logical_block_size(bdev))
+ if (block_size < bdev_logical_block_size(bdev))
return -EINVAL;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(bdev_validate_blocksize);
+
+int set_blocksize(struct file *file, int size)
+{
+ struct inode *inode = file->f_mapping->host;
+ struct block_device *bdev = I_BDEV(inode);
+ int ret;
+
+ ret = bdev_validate_blocksize(bdev, size);
+ if (ret)
+ return ret;
+
if (!file->private_data)
return -EINVAL;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index d37751789bf58..ef98bcca7f5f7 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1593,6 +1593,7 @@ static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time)
return bio_end_io_acct_remapped(bio, start_time, bio->bi_bdev);
}
+int bdev_validate_blocksize(struct block_device *bdev, int block_size);
int set_blocksize(struct file *file, int size);
int lookup_bdev(const char *pathname, dev_t *dev);
--
2.39.5
next prev parent reply other threads:[~2025-04-29 23:51 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-29 23:49 [PATCH AUTOSEL 6.14 01/39] cpufreq: Add SM8650 to cpufreq-dt-platdev blocklist Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 02/39] cpufreq: Do not enable by default during compile testing Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 03/39] nvmem: rockchip-otp: Move read-offset into variant-data Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 04/39] nvmem: rockchip-otp: add rk3576 variant data Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 05/39] nvmem: core: fix bit offsets of more than one byte Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 06/39] nvmem: core: verify cell's raw_len Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 07/39] nvmem: core: update raw_len if the bit reading is required Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 08/39] nvmem: qfprom: switch to 4-byte aligned reads Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 09/39] scsi: target: iscsi: Fix timeout on deleted connection Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 10/39] scsi: ufs: Introduce quirk to extend PA_HIBERN8TIME for UFS devices Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 11/39] virtio_ring: Fix data race by tagging event_triggered as racy for KCSAN Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 12/39] dma/mapping.c: dev_dbg support for dma_addressing_limited Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 13/39] intel_th: avoid using deprecated page->mapping, index fields Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 14/39] driver core: introduce device_set_driver() helper Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 15/39] driver core: fix potential NULL pointer dereference in dev_uevent() Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 16/39] mei: vsc: Use struct vsc_tp_packet as vsc-tp tx_buf and rx_buf type Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 17/39] dma-mapping: avoid potential unused data compilation warning Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 18/39] btrfs: tree-checker: adjust error code for header level check Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 19/39] cgroup: Fix compilation issue due to cgroup_mutex not being exported Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 20/39] vhost_task: fix vhost_task_create() documentation Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 21/39] vhost-scsi: protect vq->log_used with vq->mutex Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 22/39] scsi: mpi3mr: Add level check to control event logging Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 23/39] net: enetc: refactor bulk flipping of RX buffers to separate function Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 24/39] dma-mapping: Fix warning reported for missing prototype Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 25/39] ima: process_measurement() needlessly takes inode_lock() on MAY_READ Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 26/39] fs/buffer: split locking for pagecache lookups Sasha Levin
2025-04-30 0:47 ` Luis Chamberlain
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 27/39] fs/buffer: introduce sleeping flavors " Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 28/39] fs/buffer: use sleeping version of __find_get_block() Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 29/39] fs/ocfs2: " Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 30/39] fs/jbd2: " Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 31/39] fs/ext4: use sleeping version of sb_find_get_block() Sasha Levin
2025-04-29 23:49 ` [PATCH AUTOSEL 6.14 32/39] drm/amd/display: Enable urgent latency adjustment on DCN35 Sasha Levin
2025-04-29 23:50 ` [PATCH AUTOSEL 6.14 33/39] drm/amdgpu: Allow P2P access through XGMI Sasha Levin
2025-04-30 12:58 ` Alex Deucher
2025-04-29 23:50 ` [PATCH AUTOSEL 6.14 34/39] selftests/bpf: Mitigate sockmap_ktls disconnect_after_delete failure Sasha Levin
2025-04-29 23:50 ` [PATCH AUTOSEL 6.14 35/39] block: fix race between set_blocksize and read paths Sasha Levin
2025-04-29 23:50 ` Sasha Levin [this message]
2025-04-29 23:50 ` [PATCH AUTOSEL 6.14 37/39] io_uring: don't duplicate flushing in io_req_post_cqe Sasha Levin
2025-04-29 23:50 ` [PATCH AUTOSEL 6.14 38/39] bpf: fix possible endless loop in BPF map iteration Sasha Levin
2025-04-29 23:50 ` [PATCH AUTOSEL 6.14 39/39] samples/bpf: Fix compilation failure for samples/bpf on LoongArch Fedora Sasha Levin
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=20250429235006.536648-36-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=axboe@kernel.dk \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.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