From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 0C3B8C25B74 for ; Mon, 27 May 2024 14:06:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C76C610E2DB; Mon, 27 May 2024 14:06:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="bC4JckMq"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id AE4B910E285; Mon, 27 May 2024 14:06:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716818794; x=1748354794; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version:content-transfer-encoding; bh=esIMTSoe6zhhWKEKkt5wS7n9Xn3QvTEZP+DHoYjHzU8=; b=bC4JckMqea6m4r3LobZMHRsWXA+pmOWMCvApxDOs5Q9ygN/XlhiXCSR+ V1tKMVG4mXDrPCgXVm+HPj2y+WuqRGC8xho559+kzKL+ndtycosTYaAbC KhDAQZSb0GF9S9GC9EvnZqQU5TF6tI4qwQIXzu5f5AjevcBSWqrvZL/qO KRoG4CHvIyVVgjnyQ5KVFJN40kp/ELITyv86znJWSgdUw1yHwS+FWdjPj HC8kqRdZa6RknB0/4zMp42K1fyh5fk4SfgNyOG7uNuWTY3T4NK2U7mioQ Apj3Krxc1flNXs/xdzz7X7pkcpnB6pytVWsvXdrP6JE6Pd7IiLRsz7cmS A==; X-CSE-ConnectionGUID: R4UZXOdxRtiIcUBQK50ERw== X-CSE-MsgGUID: Yi/9iKfvRJet70ks5u0Aiw== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="24267958" X-IronPort-AV: E=Sophos;i="6.08,192,1712646000"; d="scan'208";a="24267958" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2024 07:06:34 -0700 X-CSE-ConnectionGUID: vqCrNranR/GTPXOOHJpqbw== X-CSE-MsgGUID: a8cmA0bQR5WQoakChsMkzQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,192,1712646000"; d="scan'208";a="35260746" Received: from lfiedoro-mobl.ger.corp.intel.com (HELO localhost) ([10.245.246.200]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2024 07:06:32 -0700 From: Jani Nikula To: Andy Shevchenko Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Kees Cook , Andy Shevchenko Subject: Re: [PATCH 1/2] string: add mem_is_zero() helper to check if memory area is all zeros In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20240527094320.2653177-1-jani.nikula@intel.com> Date: Mon, 27 May 2024 17:06:28 +0300 Message-ID: <87jzjfmjrv.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On Mon, 27 May 2024, Andy Shevchenko wrote: > On Mon, May 27, 2024 at 12:43=E2=80=AFPM Jani Nikula wrote: >> >> Almost two thirds of the memchr_inv() usages check if the memory area is >> all zeros, with no interest in where in the buffer the first non-zero >> byte is located. Checking for !memchr_inv(s, 0, n) is also not very >> intuitive or discoverable. Add an explicit mem_is_zero() helper for this >> use case. > > ... > >> +static inline bool mem_is_zero(const void *s, size_t n) >> +{ >> + return !memchr_inv(s, 0, n); >> +} > > There are potential users for the 0xff check as well. Hence the > following question: > Are we going to have a new function per byte in question, or do we > come up with a common denominator, like mem_is_all_of(mem, byte)? No. As I wrote in the commit message rationale, "Almost two thirds of the memchr_inv() usages check if the memory area is all zeros". This is by far the most common use case of memchr_inv(). BR, Jani. --=20 Jani Nikula, Intel