From patchwork Mon Sep 27 12:13:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 514678 Delivered-To: patch@linaro.org Received: by 2002:a17:906:f46:0:0:0:0 with SMTP id h6csp3877078ejj; Mon, 27 Sep 2021 05:13:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywZVebZtV6809TGyUmVdcs3oJjSSIaCqmrEk7AJPFykFOyWSysSaUehPE0ouPYN1epOm+p X-Received: by 2002:a63:7b54:: with SMTP id k20mr15985067pgn.137.1632744824953; Mon, 27 Sep 2021 05:13:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632744824; cv=none; d=google.com; s=arc-20160816; b=srr5a/3pGN7fDVf9f9RggyoJ/+DtQphJpjkXDfA24+KI2lZ+qGXNkZMFXY2dJhHd5W dlp3aVw0DgUnXx2QtDFnUDcHfK6MXxkLnjuPORTucpTQiilPWcrkBI9rvnia/QpZpda8 Q9Eh7QeKeqNM0xr/lXwfMvNf8NqnrrCQNnjCajGFUk0Grb12mS6hP6fDGC0HTw6dmEdr 1Sr8zcF6yv3wbrm/3u5ltdMCOVdQ2nyJL33fGGI+WVE5MJQ07yhSZw5errG8e1v12d31 397vmryIY8YBemRk4C4cG53zK/YVC62qbIaoFMadqcNwpKHjwnMC9QyLI8zV5EFMNUps Dqlw== 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=LSa10ov5Q0dJf8bTFIm9WJInHp8NM9G8cxD9cjGZ58I=; b=RqzQRYp+ZkgYM7+tED6I6wv/+8VPVZAemj4NZ0uoVhG5jDc8Tn07HbWTsM4zLl243n 8fx7oH1R0Y1Aen2lasRFL8PoGrCNU43QB/x+8XIr8gRUxWNrNblyeQBrFhI8PxI4j6nF KJCsW9YDNBpBI0hYhtPPTLuhfgl63L+QuSt3j/+6B7rwYG3oY75DXIl0TKsfRMMQqhaO +tGcp2LihGFooqwbv+oShAf2FTJd2CeHbhzCfzfCghb96nuqz6Cdf/reFzEVO+HYDbm5 xMW0899gz1cO5VjcOIUQ/xs00OSs0Yx1ClWsz66i8Sa7I04Qv+a5n88Fj6QGoCwGE4et Sk1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UpUByMnI; spf=pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-acpi-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 13si20420798pgb.551.2021.09.27.05.13.44; Mon, 27 Sep 2021 05:13:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-acpi-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=UpUByMnI; spf=pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-acpi-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 S234087AbhI0MPV (ORCPT + 2 others); Mon, 27 Sep 2021 08:15:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:39962 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234073AbhI0MPV (ORCPT ); Mon, 27 Sep 2021 08:15:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 75E6D60F94; Mon, 27 Sep 2021 12:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632744823; bh=8u31DX783FdC23lJsimtIilUO38jZwFeE1YBJx/LGoc=; h=From:To:Cc:Subject:Date:From; b=UpUByMnIr/ZS/ZRpyvut2oEJ2FTzjyfQi7zLMWh9tZ1KvciN7L1PZl6CizIgwKfZl E+aOeb0YY14mId2O++/pwcxEXLNEt8v+nCxj9kry06OsZZyQ4j7+fQp33syzmBOxuM e5XQoOHLo0mFPcgNI9yY56MaZpZBtN9VaOMtHl4PN/wCVokhhc8KGi5pKFxBalykFh HQRkepe7RDmxd3BR/V1EAfy5qQRdboB8AWS1n4AatNMFdOgeOdJAGY9caUZZgvJzLQ S2Uwuv6jsVOpNEhe5jgQvH2qnioYdDE7Ral3+ABwNzFajOl8PKFjzH7Lnj2NSm1wkD pgpNbcHhIdQMw== From: Arnd Bergmann To: "Rafael J. Wysocki" , Len Brown , Robert Moore Cc: Arnd Bergmann , "Rafael J. Wysocki" , Nathan Chancellor , Nick Desaulniers , Erik Kaneda , linux-acpi@vger.kernel.org, devel@acpica.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] ACPI: avoid NULL pointer arithmetic Date: Mon, 27 Sep 2021 14:13:22 +0200 Message-Id: <20210927121338.938994-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Arnd Bergmann There are some very old macros for doing an open-coded offsetof() and cast between pointer and integer in ACPI headers. clang-14 now complains about these: drivers/acpi/acpica/tbfadt.c:86:3: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction] ACPI_FADT_OFFSET(pm_timer_block), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/acpi/actbl.h:376:47: note: expanded from macro 'ACPI_FADT_OFFSET' #define ACPI_FADT_OFFSET(f) (u16) ACPI_OFFSET (struct acpi_table_fadt, f) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/acpi/actypes.h:511:41: note: expanded from macro 'ACPI_OFFSET' #define ACPI_OFFSET(d, f) ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) 0) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/acpi/actypes.h:505:79: note: expanded from macro 'ACPI_PTR_DIFF' #define ACPI_PTR_DIFF(a, b) ((acpi_size) (ACPI_CAST_PTR (u8, (a)) - ACPI_CAST_PTR (u8, (b)))) ^ ~~~~~~~~~~~~~~~~~~~~~~~ Convert them to the modern equivalents. Signed-off-by: Arnd Bergmann --- include/acpi/actypes.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.29.2 diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h index 92c71dfce0d5..285bc7b73de3 100644 --- a/include/acpi/actypes.h +++ b/include/acpi/actypes.h @@ -507,8 +507,8 @@ typedef u64 acpi_integer; /* Pointer/Integer type conversions */ #define ACPI_TO_POINTER(i) ACPI_CAST_PTR (void, (acpi_size) (i)) -#define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p, (void *) 0) -#define ACPI_OFFSET(d, f) ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) 0) +#define ACPI_TO_INTEGER(p) ((uintptr_t)(p)) +#define ACPI_OFFSET(d, f) offsetof(d, f) #define ACPI_PHYSADDR_TO_PTR(i) ACPI_TO_POINTER(i) #define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i)