Skip to content

Commit e2d1d49

Browse files
torvaldsvijay-suman
authored andcommitted
minmax: make generic MIN() and MAX() macros available everywhere
[ Upstream commit 1a251f5 ] This just standardizes the use of MIN() and MAX() macros, with the very traditional semantics. The goal is to use these for C constant expressions and for top-level / static initializers, and so be able to simplify the min()/max() macros. These macro names were used by various kernel code - they are very traditional, after all - and all such users have been fixed up, with a few different approaches: - trivial duplicated macro definitions have been removed Note that 'trivial' here means that it's obviously kernel code that already included all the major kernel headers, and thus gets the new generic MIN/MAX macros automatically. - non-trivial duplicated macro definitions are guarded with #ifndef This is the "yes, they define their own versions, but no, the include situation is not entirely obvious, and maybe they don't get the generic version automatically" case. - strange use case #1 A couple of drivers decided that the way they want to describe their versioning is with #define MAJ 1 #define MIN 2 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) which adds zero value and I just did my Alexander the Great impersonation, and rewrote that pointless Gordian knot as #define DRV_VERSION "1.2" instead. - strange use case #2 A couple of drivers thought that it's a good idea to have a random 'MIN' or 'MAX' define for a value or index into a table, rather than the traditional macro that takes arguments. These values were re-written as C enum's instead. The new function-line macros only expand when followed by an open parenthesis, and thus don't clash with enum use. Happily, there weren't really all that many of these cases, and a lot of users already had the pattern of using '#ifndef' guarding (or in one case just using '#undef MIN') before defining their own private version that does the same thing. I left such cases alone. Cc: David Laight <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Eliav Farber <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit e035ca130ff7f5655f7c63caaeacaf0828f85cce) Signed-off-by: Vijayendra Suman <[email protected]>
1 parent d9b07de commit e2d1d49

File tree

21 files changed

+43
-39
lines changed

21 files changed

+43
-39
lines changed

arch/um/drivers/mconsole_user.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ static struct mconsole_command *mconsole_parse(struct mc_request *req)
7171
return NULL;
7272
}
7373

74+
#ifndef MIN
7475
#define MIN(a,b) ((a)<(b) ? (a):(b))
76+
#endif
7577

7678
#define STRINGX(x) #x
7779
#define STRING(x) STRINGX(x)

drivers/edac/skx_common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#define I10NM_NUM_CHANNELS MAX(I10NM_NUM_DDR_CHANNELS, I10NM_NUM_HBM_CHANNELS)
4646
#define I10NM_NUM_DIMMS MAX(I10NM_NUM_DDR_DIMMS, I10NM_NUM_HBM_DIMMS)
4747

48-
#define MAX(a, b) ((a) > (b) ? (a) : (b))
4948
#define NUM_IMC MAX(SKX_NUM_IMC, I10NM_NUM_IMC)
5049
#define NUM_CHANNELS MAX(SKX_NUM_CHANNELS, I10NM_NUM_CHANNELS)
5150
#define NUM_DIMMS MAX(SKX_NUM_DIMMS, I10NM_NUM_DIMMS)

drivers/gpu/drm/amd/amdgpu/amdgpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,9 @@ int emu_soc_asic_init(struct amdgpu_device *adev);
12771277

12781278
#define amdgpu_inc_vram_lost(adev) atomic_inc(&((adev)->vram_lost_counter));
12791279

1280+
#ifndef MIN
12801281
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
1282+
#endif
12811283

12821284
/* Common functions */
12831285
bool amdgpu_device_has_job_running(struct amdgpu_device *adev);

drivers/gpu/drm/amd/display/modules/hdcp/hdcp_ddc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
#include "hdcp.h"
2727

28+
#ifndef MIN
2829
#define MIN(a, b) ((a) < (b) ? (a) : (b))
30+
#endif
2931
#define HDCP_I2C_ADDR 0x3a /* 0x74 >> 1*/
3032
#define KSV_READ_SIZE 0xf /* 0x6803b - 0x6802c */
3133
#define HDCP_MAX_AUX_TRANSACTION_SIZE 16

drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppevvmath.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@
2222
*/
2323
#include <asm/div64.h>
2424

25-
#define SHIFT_AMOUNT 16 /* We multiply all original integers with 2^SHIFT_AMOUNT to get the fInt representation */
25+
enum ppevvmath_constants {
26+
/* We multiply all original integers with 2^SHIFT_AMOUNT to get the fInt representation */
27+
SHIFT_AMOUNT = 16,
2628

27-
#define PRECISION 5 /* Change this value to change the number of decimal places in the final output - 5 is a good default */
29+
/* Change this value to change the number of decimal places in the final output - 5 is a good default */
30+
PRECISION = 5,
2831

29-
#define SHIFTED_2 (2 << SHIFT_AMOUNT)
30-
#define MAX (1 << (SHIFT_AMOUNT - 1)) - 1 /* 32767 - Might change in the future */
32+
SHIFTED_2 = (2 << SHIFT_AMOUNT),
33+
34+
/* 32767 - Might change in the future */
35+
MAX = (1 << (SHIFT_AMOUNT - 1)) - 1,
36+
};
3137

3238
/* -------------------------------------------------------------------------------
3339
* NEW TYPE - fINT

drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,9 @@ static void sienna_cichlid_get_override_pcie_settings(struct smu_context *smu,
19641964
}
19651965
}
19661966

1967+
#ifndef MAX
19671968
#define MAX(a, b) ((a) > (b) ? (a) : (b))
1969+
#endif
19681970

19691971
static int sienna_cichlid_update_pcie_parameters(struct smu_context *smu,
19701972
uint32_t pcie_gen_cap,

drivers/gpu/drm/radeon/evergreen_cs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
#include "evergreen_reg_safe.h"
3434
#include "cayman_reg_safe.h"
3535

36+
#ifndef MIN
3637
#define MAX(a,b) (((a)>(b))?(a):(b))
3738
#define MIN(a,b) (((a)<(b))?(a):(b))
39+
#endif
3840

3941
#define REG_SAFE_BM_SIZE ARRAY_SIZE(evergreen_reg_safe_bm)
4042

drivers/hwmon/adt7475.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@
2323
#include <linux/util_macros.h>
2424

2525
/* Indexes for the sysfs hooks */
26-
27-
#define INPUT 0
28-
#define MIN 1
29-
#define MAX 2
30-
#define CONTROL 3
31-
#define OFFSET 3
32-
#define AUTOMIN 4
33-
#define THERM 5
34-
#define HYSTERSIS 6
35-
26+
enum adt_sysfs_id {
27+
INPUT = 0,
28+
MIN = 1,
29+
MAX = 2,
30+
CONTROL = 3,
31+
OFFSET = 3, // Dup
32+
AUTOMIN = 4,
33+
THERM = 5,
34+
HYSTERSIS = 6,
3635
/*
3736
* These are unique identifiers for the sysfs functions - unlike the
3837
* numbers above, these are not also indexes into an array
3938
*/
39+
ALARM = 9,
40+
FAULT = 10,
41+
};
4042

41-
#define ALARM 9
42-
#define FAULT 10
4343

4444
/* 7475 Common Registers */
4545

drivers/media/dvb-frontends/stv0367_priv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
#endif
2626

2727
/* MACRO definitions */
28+
#ifndef MIN
2829
#define MAX(X, Y) ((X) >= (Y) ? (X) : (Y))
2930
#define MIN(X, Y) ((X) <= (Y) ? (X) : (Y))
31+
#endif
32+
3033
#define INRANGE(X, Y, Z) \
3134
((((X) <= (Y)) && ((Y) <= (Z))) || \
3235
(((Z) <= (Y)) && ((Y) <= (X))) ? 1 : 0)

drivers/net/fjes/fjes_main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
#include "fjes.h"
1515
#include "fjes_trace.h"
1616

17-
#define MAJ 1
18-
#define MIN 2
19-
#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN)
17+
#define DRV_VERSION "1.2"
2018
#define DRV_NAME "fjes"
2119
char fjes_driver_name[] = DRV_NAME;
2220
char fjes_driver_version[] = DRV_VERSION;

0 commit comments

Comments
 (0)