From patchwork Mon Feb 12 05:48:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 136589 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 70CFC43AF4; Mon, 12 Feb 2024 06:49:31 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 40D4B40274; Mon, 12 Feb 2024 06:49:31 +0100 (CET) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by mails.dpdk.org (Postfix) with ESMTP id F356440151 for ; Mon, 12 Feb 2024 06:49:28 +0100 (CET) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1d91397bd22so21078105ad.0 for ; Sun, 11 Feb 2024 21:49:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1707716968; x=1708321768; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4LpBXP8XP6KqT212l5nUxNM29jJolFgXINxXgiTpC+g=; b=iG2p9A9/S3sni3IpSe/EzzBaqXGzrDBT38kp4a138k74ak4Nkxy0xP74Avho9K3NzO 9+M+olAeUKDo1HW1LoHvtQe6hEz2osJVkMI33DwmgxmK6g+o/gca+0iYHZ3RNKDxHQJb SO6n8jz8TW81oS3vOLqZE8H8GfgiOhZg1HJeyrxk7w5g/3GtDzymqL6F6ldS6HFMNtRq F1gelQZLdb4d8IQQvKLjyx0nZ39vg+UOvLQs+mI+ZEGHVWQ1yAxuRYMAfmP7O+QmZCDC Z7Wa/l4QNA4fgUsC/TTkADxx2Zu6HfjMfa3gL2tdACXJ7CkrzZNZU5l5DEkbi2LPjSd4 uoug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707716968; x=1708321768; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4LpBXP8XP6KqT212l5nUxNM29jJolFgXINxXgiTpC+g=; b=tzwRC8JVlprPLHPPDySFregaXGH20PlyWU9BZdGdWmC1A7WjBEi+RNkANv6fVblcTM PDyP+W0djUYR1iO2EH2hV+PvHGLxeNpSgHVc1xtoAPdBChGC0zrxGj/pmsO4VL0Gr4BZ hnoYhnPViGs50rfbZ1FxMgaZ7h0taraHXgmCBPCMnwstghzLtZL9PWoyoKVkGcxf30gc QYpBZz6lYN68uLtoerhdtpCLg0/FucEkVHhBxe0muNmRBsAtGi0lkvhAq38iF0PAW+vK agAkQ0BY0moYDnI4Tu/o/LA9+nxOKshiYuzp1UNLN3RqLHnjnRb1B8qoXWnKorHjaBeI JSWA== X-Gm-Message-State: AOJu0YykiNaWmlh2WLggs3HeCek71LgrP5Nax+K6hcB8HunaA4Q4z/8n qD7w/lKJEZjRbSitHv3zWaDgwvE//TPE/n1g9/Qt3oqaUxYYrDPH9M9SDrnUFVmJmfBo0yUtUph 2 X-Google-Smtp-Source: AGHT+IGqTj3/JiKjsqW0vhHzdPcptPhKQ0KPBqDrkpuOmTPxilTnGsaLMbL9dQD1ZL2WuhV8J1SLtg== X-Received: by 2002:a05:6a20:2a1e:b0:199:cecf:9f5d with SMTP id e30-20020a056a202a1e00b00199cecf9f5dmr3288449pzh.29.1707716967996; Sun, 11 Feb 2024 21:49:27 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCV33LibB9dvcFOlYYNsEpPl2/hYJCGUsVFEdcN39tTKOOt3Znf41rVPkvNUyUTL+y8oIaX25E3m8z//0ORPMD9wmP/6krsoqj8= Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id d19-20020a170903209300b001d92a58330csm5103061plc.145.2024.02.11.21.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 21:49:27 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Morten_Br?= =?utf-8?q?=C3=B8rup?= Subject: [PATCH v4] common/sfc: replace out of bounds condition with static_assert Date: Sun, 11 Feb 2024 21:48:59 -0800 Message-ID: <20240212054917.12475-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118201843.189978-1-stephen@networkplumber.org> References: <20240118201843.189978-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The sfc base code had its own definition of static assertions using the out of bound array access hack. Replace it with a static_assert like rte_common.h. The use of null pointer to compute offset is not always a constant in older versions of clang. Use standard offsetof() instead. Fixes: f67e4719147d ("net/sfc/base: fix coding style") Signed-off-by: Stephen Hemminger Acked-by: Morten Brørup Reviewed-by: Morten Brørup Acked-by: Andrew Rybchenko --- drivers/common/sfc_efx/base/efx.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h index 3312c2fa8f81..5773cb00b3c7 100644 --- a/drivers/common/sfc_efx/base/efx.h +++ b/drivers/common/sfc_efx/base/efx.h @@ -7,6 +7,8 @@ #ifndef _SYS_EFX_H #define _SYS_EFX_H +#include + #include "efx_annote.h" #include "efsys.h" #include "efx_types.h" @@ -17,14 +19,20 @@ extern "C" { #endif -#define EFX_STATIC_ASSERT(_cond) \ - ((void)sizeof (char[(_cond) ? 1 : -1])) +/* + * Triggers an error at compilation time if the condition is false. + * + * The { } exists to workaround a bug in clang (#55821) + * where it would not handle _Static_assert in a switch case. + */ +#define EFX_STATIC_ASSERT(_cond) \ + { static_assert((_cond), #_cond); } #define EFX_ARRAY_SIZE(_array) \ (sizeof (_array) / sizeof ((_array)[0])) #define EFX_FIELD_OFFSET(_type, _field) \ - ((size_t)&(((_type *)0)->_field)) + offsetof(_type, _field) /* The macro expands divider twice */ #define EFX_DIV_ROUND_UP(_n, _d) (((_n) + (_d) - 1) / (_d))