summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2024-03-02 15:30:33 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2024-03-02 17:31:51 -0500
commit1d680937f0cd72feb27b8e927810b2cc755b2b3b (patch)
tree197a64a0c26c18cd8de9f13e8ac998cf3bb584a5
parent456f9c4fa486fe58df2cdd71b02f1a86fee65394 (diff)
bcachefs: copy_(to|from)_user_errcode()
we've got some helpers that return errors sanely, move them to a more common location for use in fs-ioctl.c Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/chardev.c6
-rw-r--r--fs/bcachefs/util.h16
2 files changed, 16 insertions, 6 deletions
diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c
index 992939152f01..4603fe6d988a 100644
--- a/fs/bcachefs/chardev.c
+++ b/fs/bcachefs/chardev.c
@@ -22,12 +22,6 @@
#include <linux/thread_with_file.h>
#include <linux/uaccess.h>
-__must_check
-static int copy_to_user_errcode(void __user *to, const void *from, unsigned long n)
-{
- return copy_to_user(to, from, n) ? -EFAULT : 0;
-}
-
/* returns with ref on ca->ref */
static struct bch_dev *bch2_device_lookup(struct bch_fs *c, u64 dev,
unsigned flags)
diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h
index c5fec87d8ecc..4318c2c7bf14 100644
--- a/fs/bcachefs/util.h
+++ b/fs/bcachefs/util.h
@@ -743,4 +743,20 @@ static inline bool qstr_eq(const struct qstr l, const struct qstr r)
void bch2_darray_str_exit(darray_str *);
int bch2_split_devs(const char *, darray_str *);
+#ifdef __KERNEL__
+
+__must_check
+static inline int copy_to_user_errcode(void __user *to, const void *from, unsigned long n)
+{
+ return copy_to_user(to, from, n) ? -EFAULT : 0;
+}
+
+__must_check
+static inline int copy_from_user_errcode(void *to, const void __user *from, unsigned long n)
+{
+ return copy_from_user(to, from, n) ? -EFAULT : 0;
+}
+
+#endif
+
#endif /* _BCACHEFS_UTIL_H */