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 5BB73C4363A for ; Fri, 30 Oct 2020 13:06:46 +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 9539A221FA for ; Fri, 30 Oct 2020 13:06:45 +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="kZFM86jc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9539A221FA 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 BF3FE6EDCA; Fri, 30 Oct 2020 13:06:44 +0000 (UTC) Received: from mail.codeweavers.com (mail.codeweavers.com [50.203.203.244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6B7B56EDCA for ; Fri, 30 Oct 2020 13:06:43 +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=R2/ghOpOjvgrCGIYN63OqPcGbiz0fn9E7LgbNQCb4hs=; b=kZFM86jcrj7ul4/iUDPbgAn+PG zajC2fNkiqwCfhZpYWkq92JawuK+9Zr0kJbBbjTPE47PqYUGCPtvgQqdSSh8w0lecFcUR3rMgP9+W JSOr/MdGULGCTP8DpWwuxVtNJ8qfY4Bf/q/Ey0hPOPgqLvEQ9uOny1ZIRXaloOchtYMQ=; 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 1kYU76-0005At-6S; Fri, 30 Oct 2020 08:06:42 -0500 From: Paul Gofman To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm v2 2/2] include: Avoid potentially infinite loop in log2_int(). Date: Fri, 30 Oct 2020 16:06:12 +0300 Message-Id: <20201030130612.590543-2-pgofman@codeweavers.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201030130612.590543-1-pgofman@codeweavers.com> References: <20201030130612.590543-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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Signed-off-by: Paul Gofman --- v2: - simplify log2_int implementation. util_math.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/util_math.h b/util_math.h index e2fa95f5..32297349 100644 --- a/util_math.h +++ b/util_math.h @@ -33,16 +33,11 @@ static inline unsigned log2_int(unsigned x) { - unsigned l; + unsigned l = 0; - if (x < 2) { - return 0; - } - for (l = 2; ; l++) { - if ((unsigned)(1 << l) > x) { - return l - 1; - } - } - return 0; + while (x >>= 1) + ++l; + + return l; } #endif /*_UTIL_MATH_H_*/ -- 2.28.0 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel