Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4246346pxb; Mon, 27 Sep 2021 12:33:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0yfkPEH4tbyHkysVSceA5jh1Cm5lutSNXL/sQa25P7N9pc3U64q/mtDqIzSqoOXtKf5K2 X-Received: by 2002:a17:902:c407:b0:13d:93aa:8098 with SMTP id k7-20020a170902c40700b0013d93aa8098mr1405171plk.3.1632771204081; Mon, 27 Sep 2021 12:33:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632771204; cv=none; d=google.com; s=arc-20160816; b=jy7BZPKuRSI9xH4OUzlaJr2e+nm1UK7NEvQ6ICSN6mdDomTyn3MVHCK8u6Gqq4wR4g JbSyCAjOYW57McSwe2Scc2e6ndVqabOzKGi921n15Xjghm39p1Y2+5F/a2A8GiYgy2C+ QifW9Ek5mqSpKpDCmmvOFQKaXgSgzNoQfCf7M1BN9OD/KV9HwST0RDlfyOPR4zyjH18Z zAIk8ymHrzPUnjhSWPR4TudyeEXPjMUSvEvkpo8qo30x9uOnNOfaBjb+9ToxWQ6yiiz/ W/fTD/AnEIlc2Se6lv6M3qAeoZAQBEePl0dzQu1MEE5hxqxKVgTHonod0qelDlZRxuD9 eTRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=G70HjmRcm7pebw7JMA1+BswintokSfzUf7wbPLT3bh8=; b=aYpcjrFwWvfzpkcbuOOdsQ+0Wdpd8kRn4s+5ce2SElzr3pd3WLtifeCdFc9lFO+E9q 2OpFMptd6MzFT1BfKwpspmadQlu4A+2Emrcoj6nrMybVAR6shtS9MDggzSF5cLHbDarM Xt/AXPR+5q6Iwuuhx/DV78JB8FO5OmKzxR5AepJrBl6rcpwvi4ADfpCx0/zH4Ug1kQd0 c5mymklo03sooAJzpT2XuwZw8Se1rsAMm7LMf2yhKdgxdO6x4ds7aiIBAlCMHy8Pa0nG iVhxKLjJbBbZebnEtb4T6xaI24Yokm4idgjey1u8G+lO/anX6/OlivbAL/IGyyAB7gLw wmgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PePbdCn6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id l10si22534676pgq.267.2021.09.27.12.33.10; Mon, 27 Sep 2021 12:33:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PePbdCn6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S236474AbhI0TcW (ORCPT + 99 others); Mon, 27 Sep 2021 15:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236225AbhI0TcW (ORCPT ); Mon, 27 Sep 2021 15:32:22 -0400 Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8241C061575 for ; Mon, 27 Sep 2021 12:30:43 -0700 (PDT) Received: by mail-oi1-x22a.google.com with SMTP id z11so27051709oih.1 for ; Mon, 27 Sep 2021 12:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=G70HjmRcm7pebw7JMA1+BswintokSfzUf7wbPLT3bh8=; b=PePbdCn6lrls3OElmo0ChOma4HDqlmsHsEHDorEC1YUw+6b9n0aZGWZXB3GVDPKKp6 SFE/UG1jAFrArGdtIlr+SMmpgZX+Tr5S36rUZnopGF19M9FSkOl051bYAprEoRP0kOqK I16VFG8p8H31MVTOYOmGFk/XcGqvb/mdEmZwMaeDiZhP4+Q7ClirAHP/Zkwy+1+74RgS en8o0Y/uSFD+QQy/rZlJPCzjQ2ApgTkH6YndJrOXBVCGcyp/XDnowkKjtg416C13GMb0 3ll3dkukgB+m23pCQByPJSESGbtr3IMLBgm+cvnj+onS7Tm7U5twqcvoF7+uoHC3Y55b DTBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=G70HjmRcm7pebw7JMA1+BswintokSfzUf7wbPLT3bh8=; b=IDO9ZHGrb14Jj8JDmGcyumc4X6kZ+9vonsd2uJTcn/S7Ih09+Ef7vrFKXuNB3l0ALb EZyYigTpmh8wVbNZwxJTUkniN6gciJtM7xMt5pwQGKq7/umXrFaha190n3i7WsKGcDRa gPZKVDOkYOwfAbNDFp6FrsTmregCiWEx5ZlL7tCCpX+0HRrm58xfHLGaacRIO4FJqVTn f3Tu+yFl5Ns3bOgqc3Q4RbWQry+bZmKBUZnUPwgAJaKAGQzCCRKPlgA4Vv6VLaRUYuDI 6NH4bXRifUwBgGTktvpEIuMNr0oxNpqTAoEwTP2WObneUipK5yoadjkrbFh7n+R1I5bj PXuw== X-Gm-Message-State: AOAM531uUC3d+6UPvWTPfKD648KSpAuH3OVcXla2oh02nc1U6FVG2SQS oUNOggDYqfDMePOS4nSUXplZ9SA/NWMzzNWmRRf1gNoX X-Received: by 2002:aca:ab4d:: with SMTP id u74mr599346oie.120.1632771043148; Mon, 27 Sep 2021 12:30:43 -0700 (PDT) MIME-Version: 1.0 References: <20210927122105.942129-1-arnd@kernel.org> In-Reply-To: <20210927122105.942129-1-arnd@kernel.org> From: Alex Deucher Date: Mon, 27 Sep 2021 15:30:32 -0400 Message-ID: Subject: Re: [PATCH] gpu: amd: replace open-coded offsetof() with builtin To: Arnd Bergmann Cc: Harry Wentland , Leo Li , Alex Deucher , =?UTF-8?Q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Evan Quan , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Randy Dunlap , Mauro Carvalho Chehab , amd-gfx list , Maling list - DRI developers , LKML , llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Applied. Thanks! Alex On Mon, Sep 27, 2021 at 8:21 AM Arnd Bergmann wrote: > > From: Arnd Bergmann > > The two AMD drivers have their own custom offsetof() implementation > that now triggers a warning with recent versions of clang: > > drivers/gpu/drm/radeon/radeon_atombios.c:133:14: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction] > > Change all the instances to use the normal offsetof() provided > by the kernel that does not have this problem. > > Signed-off-by: Arnd Bergmann > --- > drivers/gpu/drm/amd/display/dc/bios/command_table2.c | 4 +--- > drivers/gpu/drm/amd/include/atombios.h | 2 +- > drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomfwctrl.h | 4 ++-- > drivers/gpu/drm/radeon/atombios.h | 2 +- > 4 files changed, 5 insertions(+), 7 deletions(-) > > diff --git a/drivers/gpu/drm/amd/display/dc/bios/command_table2.c b/drivers/gpu/drm/amd/display/dc/bios/command_table2.c > index f1f672a997d7..4f37be727332 100644 > --- a/drivers/gpu/drm/amd/display/dc/bios/command_table2.c > +++ b/drivers/gpu/drm/amd/display/dc/bios/command_table2.c > @@ -44,9 +44,7 @@ > bp->base.ctx->logger > > #define GET_INDEX_INTO_MASTER_TABLE(MasterOrData, FieldName)\ > - (((char *)(&((\ > - struct atom_master_list_of_##MasterOrData##_functions_v2_1 *)0)\ > - ->FieldName)-(char *)0)/sizeof(uint16_t)) > + (offsetof(struct atom_master_list_of_##MasterOrData##_functions_v2_1, FieldName) / sizeof(uint16_t)) > > #define EXEC_BIOS_CMD_TABLE(fname, params)\ > (amdgpu_atom_execute_table(((struct amdgpu_device *)bp->base.ctx->driver_context)->mode_info.atom_context, \ > diff --git a/drivers/gpu/drm/amd/include/atombios.h b/drivers/gpu/drm/amd/include/atombios.h > index 6a505d1b82a5..da895d1f3b4f 100644 > --- a/drivers/gpu/drm/amd/include/atombios.h > +++ b/drivers/gpu/drm/amd/include/atombios.h > @@ -7148,7 +7148,7 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 > #define GET_COMMAND_TABLE_COMMANDSET_REVISION(TABLE_HEADER_OFFSET) (((static_cast(TABLE_HEADER_OFFSET))->ucTableFormatRevision )&0x3F) > #define GET_COMMAND_TABLE_PARAMETER_REVISION(TABLE_HEADER_OFFSET) (((static_cast(TABLE_HEADER_OFFSET))->ucTableContentRevision)&0x3F) > #else // not __cplusplus > -#define GetIndexIntoMasterTable(MasterOrData, FieldName) (((char*)(&((ATOM_MASTER_LIST_OF_##MasterOrData##_TABLES*)0)->FieldName)-(char*)0)/sizeof(USHORT)) > +#define GetIndexIntoMasterTable(MasterOrData, FieldName) (offsetof(ATOM_MASTER_LIST_OF_##MasterOrData##_TABLES, FieldName) / sizeof(USHORT)) > > #define GET_COMMAND_TABLE_COMMANDSET_REVISION(TABLE_HEADER_OFFSET) ((((ATOM_COMMON_TABLE_HEADER*)TABLE_HEADER_OFFSET)->ucTableFormatRevision)&0x3F) > #define GET_COMMAND_TABLE_PARAMETER_REVISION(TABLE_HEADER_OFFSET) ((((ATOM_COMMON_TABLE_HEADER*)TABLE_HEADER_OFFSET)->ucTableContentRevision)&0x3F) > diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomfwctrl.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomfwctrl.h > index b7e2651b570b..2fc1733bcdcf 100644 > --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomfwctrl.h > +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomfwctrl.h > @@ -29,9 +29,9 @@ > typedef enum atom_smu9_syspll0_clock_id BIOS_CLKID; > > #define GetIndexIntoMasterCmdTable(FieldName) \ > - (((char*)(&((struct atom_master_list_of_command_functions_v2_1*)0)->FieldName)-(char*)0)/sizeof(uint16_t)) > + (offsetof(struct atom_master_list_of_command_functions_v2_1, FieldName) / sizeof(uint16_t)) > #define GetIndexIntoMasterDataTable(FieldName) \ > - (((char*)(&((struct atom_master_list_of_data_tables_v2_1*)0)->FieldName)-(char*)0)/sizeof(uint16_t)) > + (offsetof(struct atom_master_list_of_data_tables_v2_1, FieldName) / sizeof(uint16_t)) > > #define PP_ATOMFWCTRL_MAX_VOLTAGE_ENTRIES 32 > > diff --git a/drivers/gpu/drm/radeon/atombios.h b/drivers/gpu/drm/radeon/atombios.h > index 83e8b8547f9b..bd5dc09e860f 100644 > --- a/drivers/gpu/drm/radeon/atombios.h > +++ b/drivers/gpu/drm/radeon/atombios.h > @@ -5983,7 +5983,7 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 > #define GET_COMMAND_TABLE_COMMANDSET_REVISION(TABLE_HEADER_OFFSET) (((static_cast(TABLE_HEADER_OFFSET))->ucTableFormatRevision )&0x3F) > #define GET_COMMAND_TABLE_PARAMETER_REVISION(TABLE_HEADER_OFFSET) (((static_cast(TABLE_HEADER_OFFSET))->ucTableContentRevision)&0x3F) > #else // not __cplusplus > -#define GetIndexIntoMasterTable(MasterOrData, FieldName) (((char*)(&((ATOM_MASTER_LIST_OF_##MasterOrData##_TABLES*)0)->FieldName)-(char*)0)/sizeof(USHORT)) > +#define GetIndexIntoMasterTable(MasterOrData, FieldName) (offsetof(ATOM_MASTER_LIST_OF_##MasterOrData##_TABLES, FieldName)/sizeof(USHORT)) > > #define GET_COMMAND_TABLE_COMMANDSET_REVISION(TABLE_HEADER_OFFSET) ((((ATOM_COMMON_TABLE_HEADER*)TABLE_HEADER_OFFSET)->ucTableFormatRevision)&0x3F) > #define GET_COMMAND_TABLE_PARAMETER_REVISION(TABLE_HEADER_OFFSET) ((((ATOM_COMMON_TABLE_HEADER*)TABLE_HEADER_OFFSET)->ucTableContentRevision)&0x3F) > -- > 2.29.2 >