From nobody Thu Dec 18 09:48:37 2025 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D185F156C6A for ; Wed, 4 Dec 2024 16:32:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733329974; cv=none; b=bfQ1CVKgyU52MAtDLvD1gwWs8Vsr+HP+LlU1zCsjvoP0vngoBrmzOwB9QgHlSLFtGi4sRdtaqcLN+zmZsqOW2+TKOuIBhmo82owU2LUVybX/XoNuEak126SEQxr6eAqhMk6r89YmUlBYn+JvlKQEKFIFk1l8OIg24F894qjXXP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733329974; c=relaxed/simple; bh=Z0dYTEMwvs7EPeBramaT98wi9z6hwRDhzo523x4GzXQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=lfYTLbyFKlKJibYcl11lpJtyxQ3f5cj3gAftPKD2H1CqJ3l3uNK0RJKNGCZYEXYRw/wXW6sfSHbORH3+fgSG/SVT81PaQkN4339uvymgqWp2ul7ub6Bhoy0UkEIy8Qe6dm5XhpFFLCFpuugwpyJTxPR8j3la8J9OK/9F+c4L7UI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=c63XBgaF; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="c63XBgaF" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7e6d04f74faso2476a12.1 for ; Wed, 04 Dec 2024 08:32:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1733329972; x=1733934772; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=B9F2gbv4yEGv6FWimwcogNz/DAberMpNHKWgDCnbd2w=; b=c63XBgaFWVjjICt1zdzR96hDRI7LWCGhDji9iAEFLGpRvbo87nWUc0Vy9k16wczuCQ B0jbr3o8laT/pdzxHbyEfz1m2zIZJS1N6UedFrvcF2LV6kAVMLJWoSRh8z94/VVPsaVo VgJQYpxtapRHZhbhROqd4/4oorsuR032rEuB0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733329972; x=1733934772; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=B9F2gbv4yEGv6FWimwcogNz/DAberMpNHKWgDCnbd2w=; b=tYn6V90r8LhyUEZg/jYhVa7ev/pKn6Tn5uPhorj0UrPDZm8fbJVQp+nygPq+oMurmw S6BMvrUjncFFXKWgrNW04kCWo8aMEbZG9tLk6eIQl0RjAv+cXeLAmX/PoTZ+PUpKYFvl szLBCOzbmv8NeQKdCZ+mXvS14umt/32b2aZpssp4U26KEAjxPALsAaTcKuZSccH7ZxLE DSXSu4vuquyy01x1rye4VA8jPUVCk23BG40Ezx5vCdPxh3bdOcQpOmK5tlQNilfMHiGH QEExLN5yOpCJIvW4EK0jmZGVhMN0wE/CEfBcG8meVrYDHVrdaM45a7228dMiD+utvqFD bvzA== X-Forwarded-Encrypted: i=1; AJvYcCXojb0xeb6k8SR27zN3teMdaDsVwyXLBHo8xS5JeQ5MYzMxfh8twQOpbeaKQXkYMS0twXmvW92Y4uTAPgE=@vger.kernel.org X-Gm-Message-State: AOJu0Ywmk4OSxZFvfe3v044sp+kg92IlrFbpXv6eda2yO/Cq/QoInbS/ IUnTP5yybrkJwZxkpNKpInmI0e/yDGau4KCwPFGQ3oUul7JcvV9R9ECZIgt7r9k= X-Gm-Gg: ASbGncuWDuszdtgT8LfMAAMr6IBobdxhi7jtDIbCJJMq3ITIolOghEIGXMa1QsP9czE mIIJvzYZlO3lqyVeTGYK6IZypTDNmWmWppcIljH9tpHglmO2JIMJ3LA9En+TPSjwjEPl282Ley1 pRPBxfrd5FLVw7ubG0sb7BcPzk6SfBxX2O/drkD25KNtrdB04PnIalTqxEulX75gtcnQwH08RrQ JZUR/cxDalaU53ChpLE42aaLyGFBu+07/i3SDfzaxx6Tw0HgW6yN8LMgg== X-Google-Smtp-Source: AGHT+IH+E1gXaxMcRBNlIPPX1i+yJ6kT0s/1DKSFVWFhZ1hgmYUfBlH8N4Ve1euLnBgvSAii6npH/w== X-Received: by 2002:a17:902:f64d:b0:215:8fd3:d1b6 with SMTP id d9443c01a7336-215be6fca4fmr115273835ad.23.1733329970689; Wed, 04 Dec 2024 08:32:50 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-215884744e6sm60591775ad.174.2024.12.04.08.32.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 08:32:49 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: pabeni@redhat.com, edumazet@google.com, kuba@kernel.org, mkarsten@uwaterloo.ca, stfomichev@gmail.com, Joe Damato , "David S. Miller" , Simon Horman , Shuah Khan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST FRAMEWORK), linux-kernel@vger.kernel.org (open list), llvm@lists.linux.dev (open list:CLANG/LLVM BUILD SUPPORT:Keyword:\b(?i:clang|llvm)\b) Subject: [PATCH net-next v2] selftests: net: cleanup busy_poller.c Date: Wed, 4 Dec 2024 16:32:39 +0000 Message-Id: <20241204163239.294123-1-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix various integer type conversions by using strtoull and a temporary variable which is bounds checked before being casted into the appropriate cfg_* variable for use by the test program. While here: - free the strdup'd cfg string for overall hygenie. - initialize napi_id =3D 0 in setup_queue to avoid warnings on some compilers. Signed-off-by: Joe Damato Acked-by: Stanislav Fomichev --- v2: - initialize napi_id to 0 in setup_queue to avoid clang warning as suggested by Stanislav. Tested with clang 10.0.0 and 18.1.8 tools/testing/selftests/net/busy_poller.c | 88 +++++++++++++---------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/tools/testing/selftests/net/busy_poller.c b/tools/testing/self= tests/net/busy_poller.c index 99b0e8c17fca..04c7ff577bb8 100644 --- a/tools/testing/selftests/net/busy_poller.c +++ b/tools/testing/selftests/net/busy_poller.c @@ -54,16 +54,16 @@ struct epoll_params { #define EPIOCGPARAMS _IOR(EPOLL_IOC_TYPE, 0x02, struct epoll_params) #endif =20 -static uint32_t cfg_port =3D 8000; +static uint16_t cfg_port =3D 8000; static struct in_addr cfg_bind_addr =3D { .s_addr =3D INADDR_ANY }; static char *cfg_outfile; static int cfg_max_events =3D 8; -static int cfg_ifindex; +static uint32_t cfg_ifindex; =20 /* busy poll params */ static uint32_t cfg_busy_poll_usecs; -static uint32_t cfg_busy_poll_budget; -static uint32_t cfg_prefer_busy_poll; +static uint16_t cfg_busy_poll_budget; +static uint8_t cfg_prefer_busy_poll; =20 /* IRQ params */ static uint32_t cfg_defer_hard_irqs; @@ -79,6 +79,7 @@ static void usage(const char *filepath) =20 static void parse_opts(int argc, char **argv) { + unsigned long long tmp; int ret; int c; =20 @@ -86,31 +87,40 @@ static void parse_opts(int argc, char **argv) usage(argv[0]); =20 while ((c =3D getopt(argc, argv, "p:m:b:u:P:g:o:d:r:s:i:")) !=3D -1) { + /* most options take integer values, except o and b, so reduce + * code duplication a bit for the common case by calling + * strtoull here and leave bounds checking and casting per + * option below. + */ + if (c !=3D 'o' && c !=3D 'b') + tmp =3D strtoull(optarg, NULL, 0); + switch (c) { case 'u': - cfg_busy_poll_usecs =3D strtoul(optarg, NULL, 0); - if (cfg_busy_poll_usecs =3D=3D ULONG_MAX || - cfg_busy_poll_usecs > UINT32_MAX) + if (tmp =3D=3D ULLONG_MAX || tmp > UINT32_MAX) error(1, ERANGE, "busy_poll_usecs too large"); + + cfg_busy_poll_usecs =3D (uint32_t)tmp; break; case 'P': - cfg_prefer_busy_poll =3D strtoul(optarg, NULL, 0); - if (cfg_prefer_busy_poll =3D=3D ULONG_MAX || - cfg_prefer_busy_poll > 1) + if (tmp =3D=3D ULLONG_MAX || tmp > 1) error(1, ERANGE, "prefer busy poll should be 0 or 1"); + + cfg_prefer_busy_poll =3D (uint8_t)tmp; break; case 'g': - cfg_busy_poll_budget =3D strtoul(optarg, NULL, 0); - if (cfg_busy_poll_budget =3D=3D ULONG_MAX || - cfg_busy_poll_budget > UINT16_MAX) + if (tmp =3D=3D ULLONG_MAX || tmp > UINT16_MAX) error(1, ERANGE, "busy poll budget must be [0, UINT16_MAX]"); + + cfg_busy_poll_budget =3D (uint16_t)tmp; break; case 'p': - cfg_port =3D strtoul(optarg, NULL, 0); - if (cfg_port > UINT16_MAX) + if (tmp =3D=3D ULLONG_MAX || tmp > UINT16_MAX) error(1, ERANGE, "port must be <=3D 65535"); + + cfg_port =3D (uint16_t)tmp; break; case 'b': ret =3D inet_aton(optarg, &cfg_bind_addr); @@ -124,41 +134,39 @@ static void parse_opts(int argc, char **argv) error(1, 0, "outfile invalid"); break; case 'm': - cfg_max_events =3D strtol(optarg, NULL, 0); - - if (cfg_max_events =3D=3D LONG_MIN || - cfg_max_events =3D=3D LONG_MAX || - cfg_max_events <=3D 0) + if (tmp =3D=3D ULLONG_MAX || tmp > INT_MAX) error(1, ERANGE, - "max events must be > 0 and < LONG_MAX"); + "max events must be > 0 and <=3D INT_MAX"); + + cfg_max_events =3D (int)tmp; break; case 'd': - cfg_defer_hard_irqs =3D strtoul(optarg, NULL, 0); - - if (cfg_defer_hard_irqs =3D=3D ULONG_MAX || - cfg_defer_hard_irqs > INT32_MAX) + if (tmp =3D=3D ULLONG_MAX || tmp > INT32_MAX) error(1, ERANGE, "defer_hard_irqs must be <=3D INT32_MAX"); + + cfg_defer_hard_irqs =3D (uint32_t)tmp; break; case 'r': - cfg_gro_flush_timeout =3D strtoull(optarg, NULL, 0); - - if (cfg_gro_flush_timeout =3D=3D ULLONG_MAX) + if (tmp =3D=3D ULLONG_MAX || tmp > UINT64_MAX) error(1, ERANGE, - "gro_flush_timeout must be < ULLONG_MAX"); + "gro_flush_timeout must be < UINT64_MAX"); + + cfg_gro_flush_timeout =3D (uint64_t)tmp; break; case 's': - cfg_irq_suspend_timeout =3D strtoull(optarg, NULL, 0); - - if (cfg_irq_suspend_timeout =3D=3D ULLONG_MAX) + if (tmp =3D=3D ULLONG_MAX || tmp > UINT64_MAX) error(1, ERANGE, "irq_suspend_timeout must be < ULLONG_MAX"); + + cfg_irq_suspend_timeout =3D (uint64_t)tmp; break; case 'i': - cfg_ifindex =3D strtoul(optarg, NULL, 0); - if (cfg_ifindex =3D=3D ULONG_MAX) + if (tmp =3D=3D ULLONG_MAX || tmp > INT_MAX) error(1, ERANGE, - "ifindex must be < ULONG_MAX"); + "ifindex must be <=3D INT_MAX"); + + cfg_ifindex =3D (int)tmp; break; } } @@ -215,7 +223,7 @@ static void setup_queue(void) struct netdev_napi_set_req *set_req =3D NULL; struct ynl_sock *ys; struct ynl_error yerr; - uint32_t napi_id; + uint32_t napi_id =3D 0; =20 ys =3D ynl_sock_create(&ynl_netdev_family, &yerr); if (!ys) @@ -277,8 +285,8 @@ static void run_poller(void) * here */ epoll_params.busy_poll_usecs =3D cfg_busy_poll_usecs; - epoll_params.busy_poll_budget =3D (uint16_t)cfg_busy_poll_budget; - epoll_params.prefer_busy_poll =3D (uint8_t)cfg_prefer_busy_poll; + epoll_params.busy_poll_budget =3D cfg_busy_poll_budget; + epoll_params.prefer_busy_poll =3D cfg_prefer_busy_poll; epoll_params.__pad =3D 0; =20 val =3D 1; @@ -342,5 +350,9 @@ int main(int argc, char *argv[]) parse_opts(argc, argv); setup_queue(); run_poller(); + + if (cfg_outfile) + free(cfg_outfile); + return 0; } base-commit: e8e7be7d212dc2bc83b8151e51088666a6c42092 --=20 2.25.1