From patchwork Wed Oct 28 10:06:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Gofman X-Patchwork-Id: 11862683 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 B0FEFC4363A for ; Wed, 28 Oct 2020 10:06:22 +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 25B75246A7 for ; Wed, 28 Oct 2020 10:06:21 +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="tmz8Vv3e" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25B75246A7 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 0C85A6E09C; Wed, 28 Oct 2020 10:06:21 +0000 (UTC) Received: from mail.codeweavers.com (mail.codeweavers.com [50.203.203.244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 81D006E09C for ; Wed, 28 Oct 2020 10:06:19 +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: 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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=6Nz/iRdy9kd+9psMnMTqsojf4xuuX3dsb0mdKOh+BRo=; b=tmz8Vv3ecuD+BFkIA/rUvwRB0c cq2V8fmVGwTL8oKJtVhqyNASfNDFTuzIf39C6rTOl48r7QsS1i1+GGeB8rdDw4gYDevwdw/Whc33H 7vFg03LywChQjPQRs4FP7pdo53raOL+o5lT877blKk+pVxZ9CC4J0EY259itcaQ4pN9c=; 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 1kXiLP-0006Qe-IU; Wed, 28 Oct 2020 05:06:17 -0500 From: Paul Gofman To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 1/2] include: Factor out log2_int() function. Date: Wed, 28 Oct 2020 13:06:01 +0300 Message-Id: <20201028100602.168752-1-pgofman@codeweavers.com> X-Mailer: git-send-email 2.28.0 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 --- radeon/radeon_surface.c | 20 +------------------- util_math.h | 14 ++++++++++++++ xf86drm.c | 16 ---------------- 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/radeon/radeon_surface.c b/radeon/radeon_surface.c index ea0a27a9..c59dcc83 100644 --- a/radeon/radeon_surface.c +++ b/radeon/radeon_surface.c @@ -38,6 +38,7 @@ #include "xf86drm.h" #include "radeon_drm.h" #include "radeon_surface.h" +#include "util_math.h" #define CIK_TILE_MODE_COLOR_2D 14 #define CIK_TILE_MODE_COLOR_2D_SCANOUT 10 @@ -47,10 +48,6 @@ #define CIK_TILE_MODE_DEPTH_STENCIL_2D_TILESPLIT_512 3 #define CIK_TILE_MODE_DEPTH_STENCIL_2D_TILESPLIT_ROW_SIZE 4 -#define ALIGN(value, alignment) (((value) + alignment - 1) & ~(alignment - 1)) -#define MAX2(A, B) ((A) > (B) ? (A) : (B)) -#define MIN2(A, B) ((A) < (B) ? (A) : (B)) - /* keep this private */ enum radeon_family { CHIP_UNKNOWN, @@ -887,21 +884,6 @@ static int eg_surface_init(struct radeon_surface_manager *surf_man, return r; } -static unsigned log2_int(unsigned x) -{ - unsigned l; - - if (x < 2) { - return 0; - } - for (l = 2; ; l++) { - if ((unsigned)(1 << l) > x) { - return l - 1; - } - } - return 0; -} - /* compute best tile_split, bankw, bankh, mtilea * depending on surface */ diff --git a/util_math.h b/util_math.h index 35bf4512..e2fa95f5 100644 --- a/util_math.h +++ b/util_math.h @@ -31,4 +31,18 @@ #define __align_mask(value, mask) (((value) + (mask)) & ~(mask)) #define ALIGN(value, alignment) __align_mask(value, (__typeof__(value))((alignment) - 1)) +static inline unsigned log2_int(unsigned x) +{ + unsigned l; + + if (x < 2) { + return 0; + } + for (l = 2; ; l++) { + if ((unsigned)(1 << l) > x) { + return l - 1; + } + } + return 0; +} #endif /*_UTIL_MATH_H_*/ diff --git a/xf86drm.c b/xf86drm.c index dbb7c14b..ca4738e1 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -124,22 +124,6 @@ static drmServerInfoPtr drm_server_info; static bool drmNodeIsDRM(int maj, int min); static char *drmGetMinorNameForFD(int fd, int type); -static unsigned log2_int(unsigned x) -{ - unsigned l; - - if (x < 2) { - return 0; - } - for (l = 2; ; l++) { - if ((unsigned)(1 << l) > x) { - return l - 1; - } - } - return 0; -} - - drm_public void drmSetServerInfo(drmServerInfoPtr info) { drm_server_info = info; 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;