Skip to content

Commit 6183c65

Browse files
torvaldsgregkh
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]>
1 parent c0c83f4 commit 6183c65

File tree

23 files changed

+51
-38
lines changed

23 files changed

+51
-38
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
@@ -1285,7 +1285,9 @@ int emu_soc_asic_init(struct amdgpu_device *adev);
12851285
for (i = ffs(inst_mask); i-- != 0; \
12861286
i = ffs(inst_mask & BIT_MASK_UPPER(i + 1)))
12871287

1288+
#ifndef MIN
12881289
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
1290+
#endif
12891291

12901292
/* Common functions */
12911293
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
@@ -2082,7 +2082,9 @@ static int sienna_cichlid_display_disable_memory_clock_switch(struct smu_context
20822082
return ret;
20832083
}
20842084

2085+
#ifndef MAX
20852086
#define MAX(a, b) ((a) > (b) ? (a) : (b))
2087+
#endif
20862088

20872089
static int sienna_cichlid_update_pcie_parameters(struct smu_context *smu,
20882090
uint8_t pcie_gen_cap,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,10 @@ static int smu_v13_0_0_get_thermal_temperature_range(struct smu_context *smu,
16961696
return 0;
16971697
}
16981698

1699+
#ifndef MAX
16991700
#define MAX(a, b) ((a) > (b) ? (a) : (b))
1701+
#endif
1702+
17001703
static ssize_t smu_v13_0_0_get_gpu_metrics(struct smu_context *smu,
17011704
void **table)
17021705
{

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,10 @@ static int smu_v13_0_7_get_thermal_temperature_range(struct smu_context *smu,
16741674
return 0;
16751675
}
16761676

1677+
#ifndef MAX
16771678
#define MAX(a, b) ((a) > (b) ? (a) : (b))
1679+
#endif
1680+
16781681
static ssize_t smu_v13_0_7_get_gpu_metrics(struct smu_context *smu,
16791682
void **table)
16801683
{

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
@@ -22,23 +22,23 @@
2222
#include <linux/util_macros.h>
2323

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

40-
#define ALARM 9
41-
#define FAULT 10
4242

4343
/* 7475 Common Registers */
4444

0 commit comments

Comments
 (0)