Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3903590pxb; Mon, 27 Sep 2021 05:22:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxM8p923ViWnSBJDpbrCvxvAllx6m8dM5wgb1e9zfb8bNzQruMuENKu7EoWaYW8gwByBwQy X-Received: by 2002:a17:90b:17ca:: with SMTP id me10mr19611707pjb.171.1632745368800; Mon, 27 Sep 2021 05:22:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632745368; cv=none; d=google.com; s=arc-20160816; b=kS785Yn8Xv1qykyCHBbwQEp5+ZnWtAlh2Pd6W2iWZ3YCyimibzUMHdrKxAU/quxNpW rIoquObMGuDdqbYCmDZaTqfN8kA0HIkOhwCEZHB3zPb+6HcEyq/BmXB5fSzJvhwxF6DA /mjQbEEcTtcIO0P6MXNEPTsQcqFNgoCY/RSLQlxuCkDBtXGR1ToFgT9aZu//gKVl0KhK 1iL8xHhLKmZ2mn+7dSMs0vxMa2apkBoUhzj4pZmp5BQuA/PnQw8TlyUdrh6zXHHI4bCy aZUHo59TQDS1Ge3YsS0+C/I/L19xyYQBRhncCJ83Fgw/H/QyMjdbbcv3BJSxp/H/7q3/ QTuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=0IibwR+ZhTjZ8xIhF3NJ0dU8ZvMUGNSx3J2A+VCnAes=; b=bJOeGvnzhCzis9mV+qpo69poRNPSEuhCl+xjv9YnAWk3iWz5LtMscYWXm3bPqIQmwF Fsx8g1RgwoqCvOGCgvfDpJPbvAuCP1gFoWX5HnsXCpPGsfFpKfoqfmXwFrNnSUCEcWPr Hh0oo9qjVin0xwgdvTf7appH8+NO45ivbpvBC82MDPyne3GD3J1BlQ/+xKwMVRnLIF0G yqyBdMGohu1bWrkgJRsBcOVns4PTGTH9bFEidkXrg6hr/PtSy6lqANa+EIEGI2sIDTa4 LsaC5q25yHYHa6h4lEvrtOZrioN241MRB2iSHW1uAbI0iiYI8x2fx9t0+jJf7WNqi4pM bOyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kp4bOf49; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d26si22505836pgv.499.2021.09.27.05.22.36; Mon, 27 Sep 2021 05:22:48 -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=@kernel.org header.s=k20201202 header.b=kp4bOf49; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234336AbhI0MXH (ORCPT + 99 others); Mon, 27 Sep 2021 08:23:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:45432 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234290AbhI0MWr (ORCPT ); Mon, 27 Sep 2021 08:22:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 31D5B61058; Mon, 27 Sep 2021 12:21:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632745270; bh=kEUnvq6r3df7WOYaeqB5E+DLccPdbdebgIInj07zILU=; h=From:To:Cc:Subject:Date:From; b=kp4bOf49VtZ+onb9V1XGhpj7eYyxSuMwtgYl6GhW1kSVI+8n4iqeVqZ9Ssv9HtKin i3CMVAEDfzmBCfXrggwhkCds+7kZOR7Aw+KE9B09S/upNAP8LH3YRyM5PNtGDvOdgJ 9ar5ZG4FezOMuDadyIpwx4Ggn1PR23vLqJFwdvIlrziCxGmECksJrRSxthqv80yL+g lCDsPzQbqkiJBnhpouXmvDFuemz48qH+Lkr/SENEQl53WWJAMeWED+kxGHw4rClgzf mDJZqCcm5G0I6daxgx2QgX2/qRFZ6fPDov26neVaN+kp9wmhLnMWGt0L0U9vQgkOAW m7A69UC+HlWHw== From: Arnd Bergmann To: Harry Wentland , Leo Li , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , Evan Quan Cc: Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Randy Dunlap , Mauro Carvalho Chehab , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] gpu: amd: replace open-coded offsetof() with builtin Date: Mon, 27 Sep 2021 14:20:41 +0200 Message-Id: <20210927122105.942129-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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