Skip to content

Commit 55139d4

Browse files
torvaldslutzbichler
authored andcommitted
minmax: make generic MIN() and MAX() macros available
everywhere 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 freebsd#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 freebsd#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]>
1 parent cd8678c commit 55139d4

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

drivers/gpu/drm/amd/display/dc/core/dc_stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "dc_stream_priv.h"
3636

3737
#define DC_LOGGER dc->ctx->logger
38-
#ifdef __linux__
38+
#ifndef MIN
3939
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
4040
#define MAX(x, y) ((x > y) ? x : y)
4141
#endif

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

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

2626
#include "hdcp.h"
2727

28-
#ifdef __FreeBSD__
29-
#undef MIN
30-
#endif
31-
28+
#ifndef MIN
3229
#define MIN(a, b) ((a) < (b) ? (a) : (b))
30+
#endif
3331
#define HDCP_I2C_ADDR 0x3a /* 0x74 >> 1*/
3432
#define KSV_READ_SIZE 0xf /* 0x6803b - 0x6802c */
3533
#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
@@ -25,12 +25,18 @@
2525
#undef MAX
2626
#endif
2727

28-
#define SHIFT_AMOUNT 16 /* We multiply all original integers with 2^SHIFT_AMOUNT to get the fInt representation */
28+
enum ppevvmath_constants {
29+
/* We multiply all original integers with 2^SHIFT_AMOUNT to get the fInt representation */
30+
SHIFT_AMOUNT = 16,
2931

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

32-
#define SHIFTED_2 (2 << SHIFT_AMOUNT)
33-
#define MAX (1 << (SHIFT_AMOUNT - 1)) - 1 /* 32767 - Might change in the future */
35+
SHIFTED_2 = (2 << SHIFT_AMOUNT),
36+
37+
/* 32767 - Might change in the future */
38+
MAX = (1 << (SHIFT_AMOUNT - 1)) - 1,
39+
};
3440

3541
/* -------------------------------------------------------------------------------
3642
* NEW TYPE - fINT

0 commit comments

Comments
 (0)