From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 94CA343AED; Sun, 11 Feb 2024 23:25:55 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1E0F04025E; Sun, 11 Feb 2024 23:25:55 +0100 (CET) Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by mails.dpdk.org (Postfix) with ESMTP id 007E64025D for ; Sun, 11 Feb 2024 23:25:53 +0100 (CET) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1d51ba18e1bso26308425ad.0 for ; Sun, 11 Feb 2024 14:25:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1707690353; x=1708295153; 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=43VrHOxUGxdmBGUAXU2AmrJ/+Kw8bZ9LjanfaJuOLJc=; b=zdAab9JsBQCzVxxizw3gjfG2bOk0cUcLGJb8FNTOKYIz6aHr5nywk5Crs+8RoqCzHU TLrF+eUs+Hit/bTqbFoQ0kNqpahR6znDdwQFi7ZkM3SnXpP7rcyB3rI53ZVv9KazmCC2 XxV3MVQ6vSfszdf0X/eyJCeeAhhTCcyCRmpIiub+sTsalPKJVr38RCoUrljYbqvxwkFR Ssy6PKBh1W0u6TNoQJliyHqPN2IX+zLHGn9sX0zdQLSrDo0uW9oX502yF6LvH34znxXy CdjaBR8YHHVakARM3V0mqn0rHJWVKDvjUTtPpcEG5ez8/280C4CW7RV+03rt80gd8VWE w6iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707690353; x=1708295153; 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=43VrHOxUGxdmBGUAXU2AmrJ/+Kw8bZ9LjanfaJuOLJc=; b=g63YGutJl5+KDiBiZSC6FJ02g0C0rK0bjgQJzQ0lVvzsrQqBWjSey7hIFJOy44Wiqb +1ZbZXdHNq7hieaRVT7A0eSJW2qUu1gYy/gcZ8/CHNDfpv7aGOAS0WLp4gx71XYY85u2 t+4sq2s7CXb4yE+r7sD920HeZqd1VQMYFa6xDWPhtGPvFSOziHHq88W7FlqKKq/BLaFT s6OI4TKLX6KpxF2n2bW/Sx5tmSoe/FoI33EdHhSZf2wKso1jl4M2w86HqO6r7fQqx0sP iG7TOqwR+Je+7TvY0T2ixI8Y5LWidPT6dcBvRSwgWU+6PLAsAKN3MoDnD6/g34kd4eBh y7og== X-Gm-Message-State: AOJu0YwiS7dJ0KcOMb8pY3m9YwAVFOezTqtd6cOapl4Zk9kJaqJL3hnO sKjQCgy+BgK0bTQuDS/zri62AJgLTkbmB256HYuxcfzbtqZ7p3lt8h++mSCS2TX8yyldLYkjUDw K X-Google-Smtp-Source: AGHT+IEy6azaVDYQs0+7p74k3E/NSEgMOp9KmGWmTo4eInPccxsBsRzz3r2FPuSGCHpdhKbwuQr7jA== X-Received: by 2002:a17:902:e543:b0:1da:22d9:e7be with SMTP id n3-20020a170902e54300b001da22d9e7bemr6015498plf.23.1707690352930; Sun, 11 Feb 2024 14:25:52 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUKOVIBywqLaZ+UulLfGw4G2p7YKiId24DVtlXhpss9x1zPRN1qIh8x5Wl2pXV10RDQL//rzOZbRGqeFXV1LssRLf8j/fVFpbg= Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id m2-20020a170902c44200b001d949e663d5sm4729704plm.31.2024.02.11.14.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 14:25:52 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH] common/sfc: replace out of bounds condition with static_assert Date: Sun, 11 Feb 2024 14:24:15 -0800 Message-ID: <20240211222543.116113-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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. This method does not force the condition to be const and can have false negatives. Better to use static_assert() like other places in DPDK. Fixes: f67e4719147d ("net/sfc/base: fix coding style") Signed-off-by: Stephen Hemminger Acked-by: Morten Brørup Reviewed-by: Morten Brørup --- v3 - change the macro to workaround issues with older clang. Compiles on Debian testing with Gcc and Clang. drivers/common/sfc_efx/base/efx.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h index 3312c2fa8f81..d2fa6bf49396 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,8 +19,14 @@ 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])) -- 2.43.0