From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) (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 A8B02238C03 for ; Wed, 21 Jan 2026 00:18:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768954735; cv=none; b=fmSTfkXCPjk3kCs4sohkqlTWx5lfUqo07xUqHRZuao6syeRNnd2Ul0GzKI84coQULDi4Xc4tjNOQjmotDD82Tuuj0Ns7kAvC+QPYruPD9fYPxzz2V/j/mDY68189ZJrn9KUry+ALf9OjRixUgDIP66tCtrMVBrzSQhPxfO9bgGA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768954735; c=relaxed/simple; bh=GzR2i6+c+TMAqPCH+yoSG4NdgGp0xqhpEvhMysXpF9s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kA9CgMNa2FRqCcdenmZhWNSHxAqOSEfWJg7cCm6Q+skp3sPDwRHd6MOatQoPT8gzKf5vgX3KzNDn1qkPOecD2sQEKVHHjT9fX84kzi8ULB53zYFV61sGQnxQwrSq9P5bo5KR5qO6RmUTMqtKB0bnkgv77Y7BQ9h7ne8Nd92SbE8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com; spf=pass smtp.mailfrom=zytor.com; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b=VDY+hQMK; arc=none smtp.client-ip=198.137.202.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zytor.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="VDY+hQMK" Received: from [IPV6:2601:646:8081:9483:12c5:bc8e:d949:3497] ([IPv6:2601:646:8081:9483:12c5:bc8e:d949:3497]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 60L0HvNi187450 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Tue, 20 Jan 2026 16:18:21 -0800 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 60L0HvNi187450 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025122301; t=1768954702; bh=jboRdd2zfJXaAG9ETcWgSm/RM4D7iTuMwYCVMSxu9FA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=VDY+hQMKz1Nh274iHdaaqVR0p18zmXVnLBezRHGA8SZuznqFY3aLIZNU7EKSqc59I PP/4TswswIZI4ercXKnAk+hAp2VezUk3J+Di80BkMrAazafQ+zXBj65WGrb1wVyWtR lMzQWpEDRILEeWsfQHcnXNe0S9UElW5PfpcfG+ahJPJvbcIstZxbtCKj6OJfWk9nUT dcWuujqBxSLiD7TN/73NFfNqzxg5nXsdxH96kw39sWe2lKjbA02Vw04FAf1l6szGjE 2KdXlNa46ThQ5HZjI/aQDB/0k8p0R5iAjIIRuyo/vT3h7oTPoBOsnZk3OELx/jmpht 8kf7VQy9whV5Q== Message-ID: <02817c9a-e512-427f-bd64-b1420132adf6@zytor.com> Date: Tue, 20 Jan 2026 16:17:52 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] x86/lib: Optimize num_digits() and fix INT_MIN overflow To: David Desobry , David Laight Cc: tglx@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, linux-kernel@vger.kernel.org References: <20260120174748.302078-1-david.desobry@formalgen.com> <20260120214612.73b83cbe@pumpkin> <8923623d-1a23-483d-add7-2fd03a3a2c3d@zytor.com> Content-Language: en-US, sv-SE From: "H. Peter Anvin" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 2026-01-20 16:04, David Desobry wrote: > > Actually, the V3 change:     > if (val < 0) { > -        d++; > -        val = -val; > +        d = 1; > +        v = -val; > +    } else { > +        d = 0; > +        v = val; >      } > reintroduced the undefined behavior for val == INT_MIN. > So this V3 version is incorrect. > I'm not familiar enough with the rest of the codebase to know if changing the > function signature to unsigned int is correct here. It is only ever called with a cpu number, a node number, or a CPU count. Never negative. -hpa