From patchwork Wed Oct 28 10:06:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Gofman X-Patchwork-Id: 11862685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A2CDC388F7 for ; Wed, 28 Oct 2020 10:06:31 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 941D4246A9 for ; Wed, 28 Oct 2020 10:06:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="u3fI44cE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 941D4246A9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=codeweavers.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A2EF26E0A0; Wed, 28 Oct 2020 10:06:29 +0000 (UTC) Received: from mail.codeweavers.com (mail.codeweavers.com [50.203.203.244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 056F06E0A0 for ; Wed, 28 Oct 2020 10:06:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=6377696661; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ke8ru2nwwTDhxVma02Ma+eTl2gqB9rritpItZX2OXyY=; b=u3fI44cEBiDvjzI5K2GP3f8t7u /18UYdaq1UJ7JV+xW3y/4Qz48M38DICnmMH137AIlxw5ibrjYwKksT6Z16bhdc6Rg8cYM48mWNV9A PaV7rtGAHhuKWYj6V7Mh8CkZXTfixePh9jbxzne6d3aVrHB83fCk3gK1xYg320WMXMZs=; Received: from [10.69.141.123] (helo=dell.localdomain) by mail.codeweavers.com with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kXiLZ-0006Qe-BC; Wed, 28 Oct 2020 05:06:27 -0500 From: Paul Gofman To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 2/2] include: Avoid potentially infinite loop in log2_int(). Date: Wed, 28 Oct 2020 13:06:02 +0300 Message-Id: <20201028100602.168752-2-pgofman@codeweavers.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201028100602.168752-1-pgofman@codeweavers.com> References: <20201028100602.168752-1-pgofman@codeweavers.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Gofman Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Signed-off-by: Paul Gofman --- util_math.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util_math.h b/util_math.h index e2fa95f5..f6bbe192 100644 --- a/util_math.h +++ b/util_math.h @@ -38,6 +38,9 @@ static inline unsigned log2_int(unsigned x) if (x < 2) { return 0; } + if (x & 0x80000000) { + return 31; + } for (l = 2; ; l++) { if ((unsigned)(1 << l) > x) { return l - 1;