Skip to content

Commit 7d4fa07

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 <David.Laight@aculab.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Eliav Farber <farbere@amazon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e6684ed commit 7d4fa07

23 files changed

Lines changed: 51 additions & 37 deletions

File tree

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
@@ -1258,7 +1258,9 @@ int emu_soc_asic_init(struct amdgpu_device *adev);
12581258

12591259
#define amdgpu_inc_vram_lost(adev) atomic_inc(&((adev)->vram_lost_counter));
12601260

1261+
#ifndef MIN
12611262
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
1263+
#endif
12621264

12631265
/* Common functions */
12641266
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
@@ -2081,7 +2081,9 @@ static int sienna_cichlid_display_disable_memory_clock_switch(struct smu_context
20812081
return ret;
20822082
}
20832083

2084+
#ifndef MAX
20842085
#define MAX(a, b) ((a) > (b) ? (a) : (b))
2086+
#endif
20852087

20862088
static int sienna_cichlid_update_pcie_parameters(struct smu_context *smu,
20872089
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
@@ -1255,7 +1255,10 @@ static int smu_v13_0_0_get_thermal_temperature_range(struct smu_context *smu,
12551255
return 0;
12561256
}
12571257

1258+
#ifndef MAX
12581259
#define MAX(a, b) ((a) > (b) ? (a) : (b))
1260+
#endif
1261+
12591262
static ssize_t smu_v13_0_0_get_gpu_metrics(struct smu_context *smu,
12601263
void **table)
12611264
{

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
@@ -1263,7 +1263,10 @@ static int smu_v13_0_7_get_thermal_temperature_range(struct smu_context *smu,
12631263
return 0;
12641264
}
12651265

1266+
#ifndef MAX
12661267
#define MAX(a, b) ((a) > (b) ? (a) : (b))
1268+
#endif
1269+
12671270
static ssize_t smu_v13_0_7_get_gpu_metrics(struct smu_context *smu,
12681271
void **table)
12691272
{

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

0 commit comments

Comments
 (0)