Received: by 2002:a05:7208:820a:b0:81:e143:7c29 with SMTP id q10csp575840rbf; Wed, 10 Apr 2024 13:14:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXrZvx4rlFJQmOaJVJIb0WjwOZoDaI0IXFFa1cjawM02JZD8tmpJbina4jbatZYWsWMM0QFE/li4mWQ8R5B+nicdHAZKfBIZ09+S/jxoA== X-Google-Smtp-Source: AGHT+IFhw/47YEODPMDul1wq7NaiQgsFTzeHTfVBXmg4VIy8c4J+oAZYddlmP5DRhwSWmPwm2079 X-Received: by 2002:ad4:5c8a:0:b0:69b:1d4f:8237 with SMTP id o10-20020ad45c8a000000b0069b1d4f8237mr4488319qvh.31.1712780078550; Wed, 10 Apr 2024 13:14:38 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ez1-20020ad45901000000b0069685a3332fsi13086988qvb.463.2024.04.10.13.14.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 13:14:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139298-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linutronix.de header.s=2020 header.b=k7ZalnCH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-139298-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139298-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 11B5B1C2370E for ; Wed, 10 Apr 2024 20:14:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A28A6181BB1; Wed, 10 Apr 2024 20:14:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="k7ZalnCH"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vcT1xXkr" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17809181B8E; Wed, 10 Apr 2024 20:14:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712780068; cv=none; b=lXQ/hGrRmu5f52iPW4Os1QL8iwfp4ME++3R/KyqPdG49KZ4DjqwFI+8eTQBzVCG3il5j1BDWhKF3Wpi8anHnMgKlO1B7PDfyb7fhIXMFXJVNhNxJwEiix+LEhT5k+W672DO7m4uxtGiHC9dN+MYMo5qwqH5iWKQDh8OtVFM16WU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712780068; c=relaxed/simple; bh=Rqy6Xs2fyCvZ69aDntTlbG095epWeaAAKb5UV4cLrco=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=XK7uL1Kwgg5KRueNSfPT28u1LxcPt7UhEapLPz2NVP8XNoh/GV3INZhBDHn5ERqtWjzrUKdwNZGX+tZ1KaYIldFeSkmTQjUrtyvUIfYBOc4QA9LzS+TVTEknu/SjnKVeRCm63DYuqTzWop9N+nUMMAAFQhcMQ2SNXmX7LonyaqM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=k7ZalnCH; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vcT1xXkr; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Wed, 10 Apr 2024 20:14:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712780065; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tDXuJbRR0DIfp06MkOUcJdP+NuBmCt9MmdpCM5pWau4=; b=k7ZalnCHhnXHt1jKDkjyanzMFHM17hLw1h9GtCdraguNNVtQkRW5o8v1Y4TLpv90/yDbEt nNzLqhvILkRmunE283kDMgkGgKz/Jf4iwiYdAG7gpnsxXyeXCmUraEFHbdZ+WhuE2C3VqK Oh/XYVekXBtN3jeXKq8qtW5c65TNV1jcTPZfb8LPpkQx6Mn1X6+i6p6qFC30/u1w+ILtgL zmEO4rbEY4wuGT/raDa+BD1R7t60Dyqs1VpOn/2SIeIwUJHB9++WLHkwI3Jz91rvLrQtGs d4aJQWf7zTruXcihX5RUHXOxwF93JUSNA6CXMTB7XLSpyDX/JupZbp6ZNayuaA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712780065; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tDXuJbRR0DIfp06MkOUcJdP+NuBmCt9MmdpCM5pWau4=; b=vcT1xXkrduEAlqZyXpLIc86hmMWnNZmOUVX5kHZXEv9w+l9S18gZCdgz8r9z1UER4TjPgg orl0Z+PkvejFwsBw== From: "tip-bot2 for John Stultz" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/urgent] selftests: timers: Fix valid-adjtimex signed left-shift undefined behavior Cc: Lee Jones , Muhammad Usama Anjum , John Stultz , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240409202222.2830476-1-jstultz@google.com> References: <20240409202222.2830476-1-jstultz@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171278006447.10875.16088506063251759811.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the timers/urgent branch of tip: Commit-ID: 076361362122a6d8a4c45f172ced5576b2d4a50d Gitweb: https://git.kernel.org/tip/076361362122a6d8a4c45f172ced5576b2d4a50d Author: John Stultz AuthorDate: Tue, 09 Apr 2024 13:22:12 -07:00 Committer: Thomas Gleixner CommitterDate: Wed, 10 Apr 2024 22:07:42 +02:00 selftests: timers: Fix valid-adjtimex signed left-shift undefined behavior The struct adjtimex freq field takes a signed value who's units are in shifted (<<16) parts-per-million. Unfortunately for negative adjustments, the straightforward use of: freq = ppm << 16 trips undefined behavior warnings with clang: valid-adjtimex.c:66:6: warning: shifting a negative signed value is undefined [-Wshift-negative-value] -499<<16, ~~~~^ valid-adjtimex.c:67:6: warning: shifting a negative signed value is undefined [-Wshift-negative-value] -450<<16, ~~~~^ . Fix it by using a multiply by (1 << 16) instead of shifting negative values in the valid-adjtimex test case. Align the values for better readability. Reported-by: Lee Jones Reported-by: Muhammad Usama Anjum Signed-off-by: John Stultz Signed-off-by: Thomas Gleixner Reviewed-by: Muhammad Usama Anjum Link: https://lore.kernel.org/r/20240409202222.2830476-1-jstultz@google.com Link: https://lore.kernel.org/lkml/0c6d4f0d-2064-4444-986b-1d1ed782135f@collabora.com/ --- tools/testing/selftests/timers/valid-adjtimex.c | 73 +++++++--------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/tools/testing/selftests/timers/valid-adjtimex.c b/tools/testing/selftests/timers/valid-adjtimex.c index 48b9a80..d13ebde 100644 --- a/tools/testing/selftests/timers/valid-adjtimex.c +++ b/tools/testing/selftests/timers/valid-adjtimex.c @@ -21,9 +21,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ - - - #include #include #include @@ -62,45 +59,47 @@ int clear_time_state(void) #define NUM_FREQ_OUTOFRANGE 4 #define NUM_FREQ_INVALID 2 +#define SHIFTED_PPM (1 << 16) + long valid_freq[NUM_FREQ_VALID] = { - -499<<16, - -450<<16, - -400<<16, - -350<<16, - -300<<16, - -250<<16, - -200<<16, - -150<<16, - -100<<16, - -75<<16, - -50<<16, - -25<<16, - -10<<16, - -5<<16, - -1<<16, + -499 * SHIFTED_PPM, + -450 * SHIFTED_PPM, + -400 * SHIFTED_PPM, + -350 * SHIFTED_PPM, + -300 * SHIFTED_PPM, + -250 * SHIFTED_PPM, + -200 * SHIFTED_PPM, + -150 * SHIFTED_PPM, + -100 * SHIFTED_PPM, + -75 * SHIFTED_PPM, + -50 * SHIFTED_PPM, + -25 * SHIFTED_PPM, + -10 * SHIFTED_PPM, + -5 * SHIFTED_PPM, + -1 * SHIFTED_PPM, -1000, - 1<<16, - 5<<16, - 10<<16, - 25<<16, - 50<<16, - 75<<16, - 100<<16, - 150<<16, - 200<<16, - 250<<16, - 300<<16, - 350<<16, - 400<<16, - 450<<16, - 499<<16, + 1 * SHIFTED_PPM, + 5 * SHIFTED_PPM, + 10 * SHIFTED_PPM, + 25 * SHIFTED_PPM, + 50 * SHIFTED_PPM, + 75 * SHIFTED_PPM, + 100 * SHIFTED_PPM, + 150 * SHIFTED_PPM, + 200 * SHIFTED_PPM, + 250 * SHIFTED_PPM, + 300 * SHIFTED_PPM, + 350 * SHIFTED_PPM, + 400 * SHIFTED_PPM, + 450 * SHIFTED_PPM, + 499 * SHIFTED_PPM, }; long outofrange_freq[NUM_FREQ_OUTOFRANGE] = { - -1000<<16, - -550<<16, - 550<<16, - 1000<<16, + -1000 * SHIFTED_PPM, + -550 * SHIFTED_PPM, + 550 * SHIFTED_PPM, + 1000 * SHIFTED_PPM, }; #define LONG_MAX (~0UL>>1)