]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
tun: Refactor CONFIG_TUN_VNET_CROSS_LE
authorAkihiko Odaki <akihiko.odaki@daynix.com>
Fri, 7 Feb 2025 06:10:51 +0000 (15:10 +0900)
committerJakub Kicinski <kuba@kernel.org>
Tue, 11 Feb 2025 03:07:10 +0000 (19:07 -0800)
Check IS_ENABLED(CONFIG_TUN_VNET_CROSS_LE) to save some lines and make
future changes easier.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20250207-tun-v6-1-fb49cf8b103e@daynix.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/tun.c

index acf96f26248873abe495c67b36727f3ca82f6164..8a9a29031bd88916271342487e786649c467a23c 100644 (file)
@@ -298,17 +298,21 @@ static bool tun_napi_frags_enabled(const struct tun_file *tfile)
        return tfile->napi_frags_enabled;
 }
 
-#ifdef CONFIG_TUN_VNET_CROSS_LE
 static inline bool tun_legacy_is_little_endian(struct tun_struct *tun)
 {
-       return tun->flags & TUN_VNET_BE ? false :
-               virtio_legacy_is_little_endian();
+       bool be = IS_ENABLED(CONFIG_TUN_VNET_CROSS_LE) &&
+                 (tun->flags & TUN_VNET_BE);
+
+       return !be && virtio_legacy_is_little_endian();
 }
 
 static long tun_get_vnet_be(struct tun_struct *tun, int __user *argp)
 {
        int be = !!(tun->flags & TUN_VNET_BE);
 
+       if (!IS_ENABLED(CONFIG_TUN_VNET_CROSS_LE))
+               return -EINVAL;
+
        if (put_user(be, argp))
                return -EFAULT;
 
@@ -319,6 +323,9 @@ static long tun_set_vnet_be(struct tun_struct *tun, int __user *argp)
 {
        int be;
 
+       if (!IS_ENABLED(CONFIG_TUN_VNET_CROSS_LE))
+               return -EINVAL;
+
        if (get_user(be, argp))
                return -EFAULT;
 
@@ -329,22 +336,6 @@ static long tun_set_vnet_be(struct tun_struct *tun, int __user *argp)
 
        return 0;
 }
-#else
-static inline bool tun_legacy_is_little_endian(struct tun_struct *tun)
-{
-       return virtio_legacy_is_little_endian();
-}
-
-static long tun_get_vnet_be(struct tun_struct *tun, int __user *argp)
-{
-       return -EINVAL;
-}
-
-static long tun_set_vnet_be(struct tun_struct *tun, int __user *argp)
-{
-       return -EINVAL;
-}
-#endif /* CONFIG_TUN_VNET_CROSS_LE */
 
 static inline bool tun_is_little_endian(struct tun_struct *tun)
 {