diff options
author | Leonardo Bras <leobras.c@gmail.com> | 2018-10-24 00:03:52 -0400 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-10-28 11:41:41 -0400 |
commit | c2b1a9226fe7c1cee8f0ae42496f3eb282d73ebb (patch) | |
tree | 30b6357b3e4926a21f06de575f6668b0bdd91890 /scripts/mod/file2alias.c | |
parent | 9e1e8194332fa4c453bcbad434b5da17c1c7e4c5 (diff) |
modpost: Create macro to avoid variable shadowing
Create DEF_FIELD_ADDR_VAR as a more generic version of the DEF_FIELD_ADD
macro, allowing usage of a variable name other than the struct element name.
Also, sets DEF_FIELD_ADDR as a specific usage of DEF_FILD_ADDR_VAR in which
the var name is the same as the struct element name.
Then, makes use of DEF_FIELD_ADDR_VAR to create a variable of another name,
in order to avoid variable shadowing.
Signed-off-by: Leonardo Bras <leobras.c@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'scripts/mod/file2alias.c')
-rw-r--r-- | scripts/mod/file2alias.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index ba4ebc4b346e..28a61665bb9c 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c | |||
@@ -95,12 +95,20 @@ extern struct devtable *__start___devtable[], *__stop___devtable[]; | |||
95 | */ | 95 | */ |
96 | #define DEF_FIELD(m, devid, f) \ | 96 | #define DEF_FIELD(m, devid, f) \ |
97 | typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f)) | 97 | typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f)) |
98 | |||
99 | /* Define a variable v that holds the address of field f of struct devid | ||
100 | * based at address m. Due to the way typeof works, for a field of type | ||
101 | * T[N] the variable has type T(*)[N], _not_ T*. | ||
102 | */ | ||
103 | #define DEF_FIELD_ADDR_VAR(m, devid, f, v) \ | ||
104 | typeof(((struct devid *)0)->f) *v = ((m) + OFF_##devid##_##f) | ||
105 | |||
98 | /* Define a variable f that holds the address of field f of struct devid | 106 | /* Define a variable f that holds the address of field f of struct devid |
99 | * based at address m. Due to the way typeof works, for a field of type | 107 | * based at address m. Due to the way typeof works, for a field of type |
100 | * T[N] the variable has type T(*)[N], _not_ T*. | 108 | * T[N] the variable has type T(*)[N], _not_ T*. |
101 | */ | 109 | */ |
102 | #define DEF_FIELD_ADDR(m, devid, f) \ | 110 | #define DEF_FIELD_ADDR(m, devid, f) \ |
103 | typeof(((struct devid *)0)->f) *f = ((m) + OFF_##devid##_##f) | 111 | DEF_FIELD_ADDR_VAR(m, devid, f, f) |
104 | 112 | ||
105 | /* Add a table entry. We test function type matches while we're here. */ | 113 | /* Add a table entry. We test function type matches while we're here. */ |
106 | #define ADD_TO_DEVTABLE(device_id, type, function) \ | 114 | #define ADD_TO_DEVTABLE(device_id, type, function) \ |
@@ -644,7 +652,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size, | |||
644 | 652 | ||
645 | for (i = 0; i < count; i++) { | 653 | for (i = 0; i < count; i++) { |
646 | unsigned int j; | 654 | unsigned int j; |
647 | DEF_FIELD_ADDR(symval + i*id_size, pnp_card_device_id, devs); | 655 | DEF_FIELD_ADDR(symval + i * id_size, pnp_card_device_id, devs); |
648 | 656 | ||
649 | for (j = 0; j < PNP_MAX_DEVICES; j++) { | 657 | for (j = 0; j < PNP_MAX_DEVICES; j++) { |
650 | const char *id = (char *)(*devs)[j].id; | 658 | const char *id = (char *)(*devs)[j].id; |
@@ -656,10 +664,13 @@ static void do_pnp_card_entries(void *symval, unsigned long size, | |||
656 | 664 | ||
657 | /* find duplicate, already added value */ | 665 | /* find duplicate, already added value */ |
658 | for (i2 = 0; i2 < i && !dup; i2++) { | 666 | for (i2 = 0; i2 < i && !dup; i2++) { |
659 | DEF_FIELD_ADDR(symval + i2*id_size, pnp_card_device_id, devs); | 667 | DEF_FIELD_ADDR_VAR(symval + i2 * id_size, |
668 | pnp_card_device_id, | ||
669 | devs, devs_dup); | ||
660 | 670 | ||
661 | for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) { | 671 | for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) { |
662 | const char *id2 = (char *)(*devs)[j2].id; | 672 | const char *id2 = |
673 | (char *)(*devs_dup)[j2].id; | ||
663 | 674 | ||
664 | if (!id2[0]) | 675 | if (!id2[0]) |
665 | break; | 676 | break; |