Received: by 2002:ab2:7988:0:b0:1f4:b336:87c4 with SMTP id g8csp59364lqj; Thu, 11 Apr 2024 09:46:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU9uJ72MpVYctWJ7z+qo8julB/MQ05sn8rfV3WkguQo7p4Swyt08cX7M6HjPzaC6YZByp8xUCNadx8peF79N7TJkzY6ro40xah/N2Chyg== X-Google-Smtp-Source: AGHT+IFBO0bu0Yu6hd4moYPa/TXPm6JJugDNAcOfgO8/b4ukWP2A/n97gvNezWV6s0MMC8809NG9 X-Received: by 2002:a05:620a:3189:b0:78d:65a2:b4b6 with SMTP id bi9-20020a05620a318900b0078d65a2b4b6mr259533qkb.25.1712854013194; Thu, 11 Apr 2024 09:46:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712854013; cv=pass; d=google.com; s=arc-20160816; b=QlRfGEnj4uIkncGUxmW7QZpZ6YGlTbeZvzrZDQ/3oCwWRfzjWNaUFipEfzArSS8LnI IpEQ+9gh2v4Z0AQWBDmiy28tChZG+xIy0Xj8ahIecGAPpvMgtWdcYzVHGXD+gWiu6FHY WxCcgl2rH1UrqFBOwUZyR+b5rTnjIRc7lWpttkN0PtatD+0RY59ezcbmFAPrWbqlPitK eQ10i/RxunKDFDOF4QIBqKdQDxpgsk1qylgDtz25K4I70g7JX2SyNWIGJOceUWV+/vaT fBr5ikI5Qau/st3f8/LOZvJmRaeX2CqsnGLxbJW0lxjUfjgx6a3Qs6e3djLj9B9jnyLw wJig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=bszWZOm4FnGDkUF6QcWbopb+R/zc1fOA46ZqKa2ClTY=; fh=9aHdJ9uk5KNiYzs4qj4y1LliCcuqcm3jQjxhKyEcWow=; b=AkzPUQxQ0+F0dcIkbgtBqMeI0UU9YD1YWx5tVJ8hrNZbpyBGxY2DdWqBF2WJ0erZ/E znmaWi1wWfi8HRAlz00KZTkaZINY4K0d7JmTvb6ZwDmgwEW5prlqWQyv12REcNJOGmNi 9L9muWzY/5ymJJugwDG4IRI49XXAiaQwBuQxQk0fez8Y99FCoKz52eEEwK9S8qzmH9T0 0xXjjbwLN4NK2z2kEvPML51FWSK7UgemNDxQogJtFpNMiwlNaC6ef/20NmbrRseXuSfi lLYx4fJxRHKWRp0FgQmRJTob14rsNUe6x+OMXl+ccaybINdGwzraS5cDqgnPKn8w6bo3 3ssQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WB9pt5su; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-141066-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141066-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a13-20020a05620a16cd00b0078bc5363c35si1837303qkn.259.2024.04.11.09.46.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 09:46:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141066-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=pass header.i=@kernel.org header.s=k20201202 header.b=WB9pt5su; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-141066-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141066-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 D84A91C22A9B for ; Thu, 11 Apr 2024 16:46:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 132891D4291; Thu, 11 Apr 2024 15:39:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WB9pt5su" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 295741D4280; Thu, 11 Apr 2024 15:39:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712849988; cv=none; b=qijKxSS+Q2m2rq+XJqY+Q3SXGGpFiWTN0Vehmef0E+QOozm/tqS1bumYABTK2SYuT9V+9w64PW+nu59JlCxD7NNtE5QYaTy1yUvIxgCaLXq4X8PxTqMJMfx+7tivvsLY+J3NHoI6lm04Fy1p1oRdSFcCykiJT50ccEyRzKq0f2s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712849988; c=relaxed/simple; bh=BAaUVpCnVLVHiTGwbzDBqzGX029scJjx0KK1ilZVLbM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=idq/7VxW/6IBBCVk+dzOWW9OIjFxqDC+AdOCT1phN/7AcJiSwXYj8wHKNmgLT98sY3nCXe8DqteVoN7PpgBE/qfgQ9yGLZhsmDWeOd6rQD+JBcmnNzY4u/GLDQNxWMS1awKWF4c0pHwKXVy+cI8jKaJKa/Hs9dd4tX48nYquxB4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WB9pt5su; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACD1CC072AA; Thu, 11 Apr 2024 15:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712849987; bh=BAaUVpCnVLVHiTGwbzDBqzGX029scJjx0KK1ilZVLbM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WB9pt5suMDCAZ+xxIXJxK9uDd7v0cMO1K2Y4ucIbBGO8Zaf8PQTbLSvsHZ3YQoisE PHwvD+U/QBFUeEhGXeQlOxlHO0AyeLynSlilsv6NtidFwvk1m6m+xnkX5LRXuX7ENf THdjOeZ0iOIV/Vv0eiuvTz3MNz4dyNRqtZ+GLUi30sFczshA3hKVfoyjSGFC80Ad+F Ni21755PZqbAYz12ggyuS+YnYlXdDOkAf9XcxdjL7HCmboTIQXlvBLTFlFQ4k8bvi8 KPVwqYC4jQno1yKDQMxNs0X/grVOYt1ffexNVoexNSLCGQEGAz56gVyVVFp8dAS8zF BhmGTvR7EObrQ== Date: Thu, 11 Apr 2024 08:39:45 -0700 From: Nathan Chancellor To: John Stultz Cc: LKML , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Stephen Boyd , Nick Desaulniers , Bill Wendling , Justin Stitt , Oleg Nesterov , Andrew Morton , Edward Liaw , Carlos Llamas , kernel-team@android.com, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 2/3] selftests: timers: Fix uninitialized variable warning in ksft_min_kernel_version Message-ID: <20240411153945.GA2507795@dev-arch.thelio-3990X> References: <20240410232637.4135564-1-jstultz@google.com> <20240410232637.4135564-2-jstultz@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240410232637.4135564-2-jstultz@google.com> On Wed, Apr 10, 2024 at 04:26:29PM -0700, John Stultz wrote: > Building with clang, I see the following warning: > > In file included from posix_timers.c:17: > ./../kselftest.h:398:6: warning: variable 'major' is used uninitialized whenever '||' condition is true [-Wsometimes-uninitialized] > if (uname(&info) || sscanf(info.release, "%u.%u.", &major, &minor) != 2) > ^~~~~~~~~~~~ > ./../kselftest.h:401:9: note: uninitialized use occurs here > return major > min_major || (major == min_major && minor >= min_minor); > ^~~~~ > > This is a bit of a red-herring as if the uname() call did fail, > we would hit ksft_exit_fail_msg() which should exit. Correct, although we have not really conveyed that to the compiler, right? exit() is noreturn, which means all functions that call exit() unconditionally are also noreturn, such as ksft_exit_fail_msg(). LLVM will figure this out once it performs inlining and such but that happens after clang's static analysis phase that this warning occurs in. I think a better solution would be to add __noreturn to the functions in tools/testing/selftests/kselftest.h that call exit(), so that the compiler is aware of this through all pipeline phases, maybe something like this? It resolves the wawrning for me. diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index 050c5fd01840..29364c9f3332 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -83,6 +83,7 @@ #define KSFT_XPASS 3 #define KSFT_SKIP 4 +#define __noreturn __attribute__((__noreturn__)) #define __printf(a, b) __attribute__((format(printf, a, b))) /* counters */ @@ -324,13 +325,13 @@ void ksft_test_result_code(int exit_code, const char *test_name, break; \ } } while (0) -static inline int ksft_exit_pass(void) +static inline __noreturn int ksft_exit_pass(void) { ksft_print_cnts(); exit(KSFT_PASS); } -static inline int ksft_exit_fail(void) +static inline __noreturn int ksft_exit_fail(void) { ksft_print_cnts(); exit(KSFT_FAIL); @@ -357,7 +358,7 @@ static inline int ksft_exit_fail(void) ksft_cnt.ksft_xfail + \ ksft_cnt.ksft_xskip) -static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...) +static inline __noreturn __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...) { int saved_errno = errno; va_list args; @@ -372,7 +373,7 @@ static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...) exit(KSFT_FAIL); } -static inline void ksft_exit_fail_perror(const char *msg) +static inline __noreturn void ksft_exit_fail_perror(const char *msg) { #ifndef NOLIBC ksft_exit_fail_msg("%s: %s (%d)\n", msg, strerror(errno), errno); @@ -385,19 +386,19 @@ static inline void ksft_exit_fail_perror(const char *msg) #endif } -static inline int ksft_exit_xfail(void) +static inline __noreturn int ksft_exit_xfail(void) { ksft_print_cnts(); exit(KSFT_XFAIL); } -static inline int ksft_exit_xpass(void) +static inline __noreturn int ksft_exit_xpass(void) { ksft_print_cnts(); exit(KSFT_XPASS); } -static inline __printf(1, 2) int ksft_exit_skip(const char *msg, ...) +static inline __noreturn __printf(1, 2) int ksft_exit_skip(const char *msg, ...) { int saved_errno = errno; va_list args;