On Mon, Feb 19, 2024 at 01:01:01PM +0000, John Garry wrote:
@@ -3523,4 +3535,26 @@ extern int vfs_fadvise(struct file *file, loff_t offset, loff_t len,This doesn't need if else if else if and it doesn't need to check
extern int generic_fadvise(struct file *file, loff_t offset, loff_t len,
int advice);
+static inline bool atomic_write_valid(loff_t pos, struct iov_iter *iter,
+ unsigned int unit_min, unsigned int unit_max)
+{
+ size_t len = iov_iter_count(iter);
+
+ if (!iter_is_ubuf(iter))
+ return false;
+
+ if (len == unit_min || len == unit_max) {
+ /* ok if exactly min or max */
+ } else if (len < unit_min || len > unit_max) {
+ return false;
+ } else if (!is_power_of_2(len)) {
+ return false;
+ }
for exact unit min/max matches.
The exact matches require the
length to be a power of 2, so the checks are simply:
if (len < unit_min || len > unit_max)
return false;
if (!is_power_of_2(len))
return false;
+ if (pos & (len - 1))This has typing issues - 64 bit value, 32 bit mask. probably should
+ return false;
use:
if (!IS_ALIGNED(pos, len))
return false;