mirror of https://gitee.com/openkylin/linux.git
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>
This commit is contained in:
parent
9e1e819433
commit
c2b1a9226f
|
@ -95,12 +95,20 @@ extern struct devtable *__start___devtable[], *__stop___devtable[];
|
||||||
*/
|
*/
|
||||||
#define DEF_FIELD(m, devid, f) \
|
#define DEF_FIELD(m, devid, f) \
|
||||||
typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f))
|
typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f))
|
||||||
|
|
||||||
|
/* Define a variable v that holds the address of field f of struct devid
|
||||||
|
* based at address m. Due to the way typeof works, for a field of type
|
||||||
|
* T[N] the variable has type T(*)[N], _not_ T*.
|
||||||
|
*/
|
||||||
|
#define DEF_FIELD_ADDR_VAR(m, devid, f, v) \
|
||||||
|
typeof(((struct devid *)0)->f) *v = ((m) + OFF_##devid##_##f)
|
||||||
|
|
||||||
/* Define a variable f that holds the address of field f of struct devid
|
/* Define a variable f that holds the address of field f of struct devid
|
||||||
* based at address m. Due to the way typeof works, for a field of type
|
* based at address m. Due to the way typeof works, for a field of type
|
||||||
* T[N] the variable has type T(*)[N], _not_ T*.
|
* T[N] the variable has type T(*)[N], _not_ T*.
|
||||||
*/
|
*/
|
||||||
#define DEF_FIELD_ADDR(m, devid, f) \
|
#define DEF_FIELD_ADDR(m, devid, f) \
|
||||||
typeof(((struct devid *)0)->f) *f = ((m) + OFF_##devid##_##f)
|
DEF_FIELD_ADDR_VAR(m, devid, f, f)
|
||||||
|
|
||||||
/* Add a table entry. We test function type matches while we're here. */
|
/* Add a table entry. We test function type matches while we're here. */
|
||||||
#define ADD_TO_DEVTABLE(device_id, type, function) \
|
#define ADD_TO_DEVTABLE(device_id, type, function) \
|
||||||
|
@ -644,7 +652,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
DEF_FIELD_ADDR(symval + i*id_size, pnp_card_device_id, devs);
|
DEF_FIELD_ADDR(symval + i * id_size, pnp_card_device_id, devs);
|
||||||
|
|
||||||
for (j = 0; j < PNP_MAX_DEVICES; j++) {
|
for (j = 0; j < PNP_MAX_DEVICES; j++) {
|
||||||
const char *id = (char *)(*devs)[j].id;
|
const char *id = (char *)(*devs)[j].id;
|
||||||
|
@ -656,10 +664,13 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
|
||||||
|
|
||||||
/* find duplicate, already added value */
|
/* find duplicate, already added value */
|
||||||
for (i2 = 0; i2 < i && !dup; i2++) {
|
for (i2 = 0; i2 < i && !dup; i2++) {
|
||||||
DEF_FIELD_ADDR(symval + i2*id_size, pnp_card_device_id, devs);
|
DEF_FIELD_ADDR_VAR(symval + i2 * id_size,
|
||||||
|
pnp_card_device_id,
|
||||||
|
devs, devs_dup);
|
||||||
|
|
||||||
for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) {
|
for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) {
|
||||||
const char *id2 = (char *)(*devs)[j2].id;
|
const char *id2 =
|
||||||
|
(char *)(*devs_dup)[j2].id;
|
||||||
|
|
||||||
if (!id2[0])
|
if (!id2[0])
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue