Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp3975116ima; Tue, 23 Oct 2018 14:36:48 -0700 (PDT) X-Google-Smtp-Source: AJdET5c3B5WvtEu8+i2n5dptxXjIj2hfr+jFPxRJxK5lcPOWeI7c5YwgmeVFC60/l1dpzzKBGnbL X-Received: by 2002:a17:902:6e17:: with SMTP id u23-v6mr225580plk.127.1540330608860; Tue, 23 Oct 2018 14:36:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540330608; cv=none; d=google.com; s=arc-20160816; b=Yz9KI7ABm8SSWeysAVQP27yPzIyczlF0Y/0kGsAn2KWBPV/8rVildNOMkw0Nno/2Mo U6Ljms6f3+gdTFVUxO/ZGX+oRr1/7AsWy6u9y6pA8TnoPTo3EPeF8Qw2NYq9wp3bZUH6 8fcRqRAYMjzRrMTKdpyOp7LP467PBktmfcEczF4b0mlnSbkvaE6O+fYcj3cmxuS/aOqp aKdsHdUD2hskWN1eAr1I988mU6CNdjwU8KNtxjnB2c7ix4zWhnq6l2gaRR3hjLXoV9/R QYo6V/HC4q4qTG8uerlL8uwJoJmAyotPxJ/yqCeL5FgeQSvtFQtjhTFGVqDcobBxGQlc 3ZWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=6kiimSHEOpzRp7ehclRKTX3KqYQiZViHrxBew/pat9w=; b=lAJfNKCqsowwl04l9hrm3Sj7I3qK/Hs8exoHWnS7MlpOxY+m1Q0tqtI9H7LOXtbfPs oEf5ClNNjX/lp2uLKSP8+EA1tsEpRiGMotURrlIFKfQUykmfmM00QCTUTupEiuo6kCv5 bbrrK0Snz6hMNyHmNg2ofvXGFFVpLzUyzXukMHYEVI+lb6E2gf84Pkj4tif9ZOcentLH n/MCE9QHqdNK+jF02/Ku2Ex8OnpC+w5SHf+3PJgjPRONa8nV01MxHSrLX2h+MjHGllcP XS8peDKHS9fKKazZ4vb5+VSNaAW2K3Uxjbi7ahfHN/SjRpnY/PfNukFOvaT621QO+Q85 f5DQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e21-v6si2609582pgl.305.2018.10.23.14.36.33; Tue, 23 Oct 2018 14:36:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727624AbeJXGBH (ORCPT + 99 others); Wed, 24 Oct 2018 02:01:07 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52861 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725859AbeJXGBH (ORCPT ); Wed, 24 Oct 2018 02:01:07 -0400 Received: by mail-wm1-f65.google.com with SMTP id 189-v6so3274521wmw.2; Tue, 23 Oct 2018 14:35:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=6kiimSHEOpzRp7ehclRKTX3KqYQiZViHrxBew/pat9w=; b=OZHLQchWXmzdfxc1cP9TddIYJ3Bm5M+pCmJmnqwmtW5a+Gxg0+XJUjk9d5YOVybpz3 kuehIu/GBKMcn2wGXnszyK/rgQOzfS1pri2GiRA7hDck3Equ4Zhs9IRP3GNH87cnTCGv eyxLNySvXcNZzQUkh/jGQ46A414OKeG+/sdaXMw6AMXap1KIpnADcNoyKD07FOTpXhEC h3pA/iebWrVD355dUR1bvoSzG8q1y13TuG7zJXtujosrpDHD7e3EBOhLKdDtawdF9CfS m20mXVHbpk+YJ32IUBNQoPTlQDx9r0xnG1KpuHAgxPakL4aSIzrInQZkEk190ub4d5/m dYoQ== X-Gm-Message-State: AGRZ1gL4dTm1FZZ7/rRnPocTFgPfuvVTiyrtvXJoDG8h2OvLk71IzTjM p0pEW2ce37f6pj/NAyla+kZe38QM5fU= X-Received: by 2002:a1c:9d90:: with SMTP id g138-v6mr1463006wme.41.1540330553160; Tue, 23 Oct 2018 14:35:53 -0700 (PDT) Received: from [192.168.1.178] (host-92-3-126-56.as43234.net. [92.3.126.56]) by smtp.gmail.com with ESMTPSA id o17-v6sm3135032wro.2.2018.10.23.14.35.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Oct 2018 14:35:52 -0700 (PDT) Subject: Re: [PATCH v2 3/5] Creates macro to avoid variable shadowing To: =?UTF-8?Q?Leonardo_Br=c3=a1s?= , lkcamp@lists.libreplanetbr.org Cc: Borislav Petkov , David.Laight@aculab.com, Andy Lutomirski , Ingo Molnar , Masahiro Yamada , Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org References: <20181023011042.GA6582@WindFlash> From: Helen Koike Message-ID: Date: Tue, 23 Oct 2018 18:35:49 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <20181023011042.GA6582@WindFlash> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Leonardo, On 10/22/18 11:10 PM, Leonardo Brás wrote: > Creates 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. > > Signed-off-by: Leonardo Brás > --- > scripts/mod/file2alias.c | 24 +++++++++++++++++------- > 1 file changed, 17 insertions(+), 7 deletions(-) > > diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c > index 7be43697ff84..3015c0bdecb2 100644 > --- a/scripts/mod/file2alias.c > +++ b/scripts/mod/file2alias.c > @@ -95,12 +95,20 @@ extern struct devtable *__start___devtable[], *__stop___devtable[]; > */ > #define DEF_FIELD(m, 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 > * 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(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. */ > #define ADD_TO_DEVTABLE(device_id, type, function) \ > @@ -641,25 +649,27 @@ static void do_pnp_card_entries(void *symval, unsigned long size, > unsigned int i; > > device_id_check(mod->name, "pnp", size, id_size, symval); > + DEF_FIELD_ADDR(symval, pnp_card_device_id, devs); > + typeof(devs) devs_last; > > for (i = 0; i < count; i++) { > unsigned int j; > - DEF_FIELD_ADDR(symval + i*id_size, pnp_card_device_id, devs); > + devs_last = devs + i * id_size; Instead of doing all these changes, you could just modify here with DEF_FIELD_ADDR_VAR(symval + i*id_size, pnp_card_device_id, devs, devs_aux); Like this you are not changing the logic in this file, you are just renaming the variable which is more then enough to solve the -Wshadow warning. I don't it is worthy changing the logic. Regards, Helen. > > for (j = 0; j < PNP_MAX_DEVICES; j++) { > - const char *id = (char *)(*devs)[j].id; > - int i2, j2; > + const char *id = (char *)(*devs_last)[j].id; > + int j2; > int dup = 0; > > if (!id[0]) > break; > > /* find duplicate, already added value */ > - for (i2 = 0; i2 < i && !dup; i2++) { > - DEF_FIELD_ADDR(symval + i2*id_size, pnp_card_device_id, devs); > + while ((devs_last -= id_size) >= devs && !dup) { > > for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) { > - const char *id2 = (char *)(*devs)[j2].id; > + const char *id2 = > + (char *)(*devs_last)[j2].id; > > if (!id2[0]) > break; >