0ccc47
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
0ccc47
From: Peter Jones <pjones@redhat.com>
0ccc47
Date: Thu, 21 Apr 2022 16:31:17 -0400
0ccc47
Subject: [PATCH] ReiserFS: switch to using grub_min()/grub_max()
0ccc47
0ccc47
This is a minor cleanup patch to remove the bespoke MIN() and MAX()
0ccc47
definitions from the reiserfs driver, and uses grub_min() / grub_max()
0ccc47
instead.
0ccc47
0ccc47
Signed-off-by: Peter Jones <pjones@redhat.com>
0ccc47
(cherry picked from commit 5fc601574fce99b32fe4dfb55bd8f3ab0175fd6a)
0ccc47
(cherry picked from commit 31e581893c564582c729fd0c033d3ce021854be8)
0ccc47
---
0ccc47
 grub-core/fs/reiserfs.c | 28 +++++++++-------------------
0ccc47
 1 file changed, 9 insertions(+), 19 deletions(-)
0ccc47
0ccc47
diff --git a/grub-core/fs/reiserfs.c b/grub-core/fs/reiserfs.c
0ccc47
index 39736f63c6..9556c15ff0 100644
0ccc47
--- a/grub-core/fs/reiserfs.c
0ccc47
+++ b/grub-core/fs/reiserfs.c
0ccc47
@@ -42,16 +42,6 @@
0ccc47
 
0ccc47
 GRUB_MOD_LICENSE ("GPLv3+");
0ccc47
 
0ccc47
-#define MIN(a, b) \
0ccc47
-  ({ typeof (a) _a = (a); \
0ccc47
-     typeof (b) _b = (b); \
0ccc47
-     _a < _b ? _a : _b; })
0ccc47
-
0ccc47
-#define MAX(a, b) \
0ccc47
-  ({ typeof (a) _a = (a); \
0ccc47
-     typeof (b) _b = (b); \
0ccc47
-     _a > _b ? _a : _b; })
0ccc47
-
0ccc47
 #define REISERFS_SUPER_BLOCK_OFFSET 0x10000
0ccc47
 #define REISERFS_MAGIC_LEN 12
0ccc47
 #define REISERFS_MAGIC_STRING "ReIsEr"
0ccc47
@@ -1076,7 +1066,7 @@ grub_reiserfs_read_real (struct grub_fshelp_node *node,
0ccc47
   grub_reiserfs_set_key_type (&key, GRUB_REISERFS_ANY, 2);
0ccc47
   initial_position = off;
0ccc47
   current_position = 0;
0ccc47
-  final_position = MIN (len + initial_position, node->size);
0ccc47
+  final_position = grub_min (len + initial_position, node->size);
0ccc47
   grub_dprintf ("reiserfs",
0ccc47
 		"Reading from %lld to %lld (%lld instead of requested %ld)\n",
0ccc47
 		(unsigned long long) initial_position,
0ccc47
@@ -1115,8 +1105,8 @@ grub_reiserfs_read_real (struct grub_fshelp_node *node,
0ccc47
           grub_dprintf ("reiserfs_blocktype", "D: %u\n", (unsigned) block);
0ccc47
           if (initial_position < current_position + item_size)
0ccc47
             {
0ccc47
-              offset = MAX ((signed) (initial_position - current_position), 0);
0ccc47
-              length = (MIN (item_size, final_position - current_position)
0ccc47
+              offset = grub_max ((signed) (initial_position - current_position), 0);
0ccc47
+              length = (grub_min (item_size, final_position - current_position)
0ccc47
                         - offset);
0ccc47
               grub_dprintf ("reiserfs",
0ccc47
                             "Reading direct block %u from %u to %u...\n",
0ccc47
@@ -1161,9 +1151,9 @@ grub_reiserfs_read_real (struct grub_fshelp_node *node,
0ccc47
               grub_dprintf ("reiserfs_blocktype", "I: %u\n", (unsigned) block);
0ccc47
               if (current_position + block_size >= initial_position)
0ccc47
                 {
0ccc47
-                  offset = MAX ((signed) (initial_position - current_position),
0ccc47
-                                0);
0ccc47
-                  length = (MIN (block_size, final_position - current_position)
0ccc47
+                  offset = grub_max ((signed) (initial_position - current_position),
0ccc47
+				     0);
0ccc47
+                  length = (grub_min (block_size, final_position - current_position)
0ccc47
                             - offset);
0ccc47
                   grub_dprintf ("reiserfs",
0ccc47
                                 "Reading indirect block %u from %u to %u...\n",
0ccc47
@@ -1205,7 +1195,7 @@ grub_reiserfs_read_real (struct grub_fshelp_node *node,
0ccc47
   switch (found.type)
0ccc47
     {
0ccc47
       case GRUB_REISERFS_DIRECT:
0ccc47
-        read_length = MIN (len, item_size - file->offset);
0ccc47
+        read_length = grub_min (len, item_size - file->offset);
0ccc47
         grub_disk_read (found.data->disk,
0ccc47
                         (found.block_number * block_size) / GRUB_DISK_SECTOR_SIZE,
0ccc47
                         grub_le_to_cpu16 (found.header.item_location) + file->offset,
0ccc47
@@ -1224,12 +1214,12 @@ grub_reiserfs_read_real (struct grub_fshelp_node *node,
0ccc47
                         item_size, (char *) indirect_block_ptr);
0ccc47
         if (grub_errno)
0ccc47
           goto fail;
0ccc47
-        len = MIN (len, file->size - file->offset);
0ccc47
+        len = grub_min (len, file->size - file->offset);
0ccc47
         for (indirect_block = file->offset / block_size;
0ccc47
              indirect_block < indirect_block_count && read_length < len;
0ccc47
              indirect_block++)
0ccc47
           {
0ccc47
-            read = MIN (block_size, len - read_length);
0ccc47
+            read = grub_min (block_size, len - read_length);
0ccc47
             grub_disk_read (found.data->disk,
0ccc47
                             (grub_le_to_cpu32 (indirect_block_ptr[indirect_block]) * block_size) / GRUB_DISK_SECTOR_SIZE,
0ccc47
                             file->offset % block_size, read,