Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp2870581ima; Mon, 22 Oct 2018 18:11:34 -0700 (PDT) X-Google-Smtp-Source: ACcGV632UQb+ZiA0BJMjEkon1IsXW1oF3a2ksAfeis9A4nca1oOkiG66C5FZlokYviWGJx3stsKa X-Received: by 2002:a62:1c06:: with SMTP id c6-v6mr48491740pfc.41.1540257094286; Mon, 22 Oct 2018 18:11:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540257094; cv=none; d=google.com; s=arc-20160816; b=eCPXubUQXYP2bpApknc879Hpox99Pt0uPMFS9lkcmC/TAXkCy6YpdSGpwcQr8CQ8rC /dq+ALxM4kyrxOT6ako4Gevtk8pekyHRK25CpTjGONFXFRhwKhdVep17y0100CLvHpjA lO0f1LpEhVeaHlJEEtJJeAl2TWYW+yuV7uysMkfcFH9SPQy9svSOGpR6/eP39ke6VnhF rbW2Zw2gXUAg3w4jiEtcKKr5YwqyxRPAu00JzJQQxJJAepi9IWea9ciudgvhWh56kqoY 8pgBg/am3Sdubl44QjcF1gnXltPM/xVV+myLrQigabSHhSF701f1uP8POEYdNhEBrALJ +yKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-transfer-encoding :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=L46EcQJ+O0hl3e5uDfhzLkvgGNrA7UN6EpC8xsyT0FY=; b=QRBkCHSWmQihYj3pTvuzMkbLgVIOQ7/8t+F1J1SXAQRmOV7ogRXR5xcQdSHSG/7BQQ LgkQVOEJDL+CRuNvrgVrNGCsFCVVEJ1KzqypJfTx+d7HDBySQCkGvr0KWhL61g91gYr3 Aa5wrJeXG5y17hZhD3STl/nMmUz+ZM0dMTD7l0BffEWKP8rZOO5D0HqJO0SCA8Fs4L+i JYAeRCC1eJSeChrMHfXSjimF1ajbqKqzhl3KtoOXIkoWyA5KBsc34g1XDqAOso/6TkFN KeAMxjCzrck3J3Oh97ehZWuBiZGAD2iowo8woDFausPzZgMOVfRJ9STTWEJSGLk6xEi7 7mzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CSlBOavx; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c11-v6si35898991pgj.409.2018.10.22.18.11.19; Mon, 22 Oct 2018 18:11:34 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CSlBOavx; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727830AbeJWJbt (ORCPT + 99 others); Tue, 23 Oct 2018 05:31:49 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:41941 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725883AbeJWJbt (ORCPT ); Tue, 23 Oct 2018 05:31:49 -0400 Received: by mail-qt1-f194.google.com with SMTP id l41-v6so48684758qtl.8; Mon, 22 Oct 2018 18:10:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:user-agent; bh=L46EcQJ+O0hl3e5uDfhzLkvgGNrA7UN6EpC8xsyT0FY=; b=CSlBOavx0UlhIrISkkDHA4kCNCT+CH/XOam/TlKnbL8/aBBNxuVlL9xBhZTJczWrro ytEuerpOzEPyItkG0b11HhcbCTUyXsMB4QUYMmmnNau6agHQx0HkF00oOni4SP8EkKmu Ot0hYh6HLcK4O3yT3bLvilXVpPByE5pcDJyV8OgiCX4kHYIwiB3yY0HxFLmB8+Qku277 4kSik+hUeb0ETjSAgEEvgIB7BTHVKX2RMc6XTEw1efctoI6xj2AV8qKDy++iYYx8Bew1 SapvDsYONr+dB99TNXSbb9ew8ZkmDOTQ1PFDup4A1RVHy31q/i4ew7T5aPcbjDdlyydl HPew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:user-agent; bh=L46EcQJ+O0hl3e5uDfhzLkvgGNrA7UN6EpC8xsyT0FY=; b=YJObeGoxbTD+3BlZwz9LzeIzYxyAg8ofzgnHcwcQe/7KF/o/ukMuBp3xPVsxHxBlcM XCeSVTj8boY0hH0uR4nDnvBBomDvN7VIhSn4lUpn7lK3ayXkH3LW0NJ9PLkFbxpXJ+9L E3W0icrzA0kX8TS/mYJsAFZKsTC9F4x5dBeYVlURDyZJC1UOnh25HrlBAfs/7oxPF/Il F0scdBUks8X0+7EVI+sYgi4LHAm9KQIMGFja9weS1lTVNJhfrtJPbCau9N7JA1SUHyaR sgsHyTtE2thnbXqTYrvpAHll0j9kmfoICv8n6YTrFaXxbqr2ruZM2kVUMoiOjTyDQlN8 t8ig== X-Gm-Message-State: ABuFfohCgkaAteNaL3IoDxj/U2eqF86SVFaJsIaJKYKvaNkszdTBlNRn Ss2y6ux2L+uPbmgArTSyrLA= X-Received: by 2002:aed:2d05:: with SMTP id h5-v6mr46169920qtd.291.1540257049425; Mon, 22 Oct 2018 18:10:49 -0700 (PDT) Received: from WindFlash ([179.159.21.48]) by smtp.gmail.com with ESMTPSA id c85-v6sm21153702qke.89.2018.10.22.18.10.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Oct 2018 18:10:49 -0700 (PDT) Date: Mon, 22 Oct 2018 22:10:42 -0300 From: Leonardo =?utf-8?B?QnLDoXM=?= To: lkcamp@lists.libreplanetbr.org Cc: Borislav Petkov , David.Laight@aculab.com, Andy Lutomirski , Ingo Molnar , helen@koikeco.de, Masahiro Yamada , Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/5] Creates macro to avoid variable shadowing Message-ID: <20181023011042.GA6582@WindFlash> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; 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; -- 2.19.1