Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2072172lqb; Mon, 27 May 2024 07:06:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU4j528upr4ycrKVMELnAV4nA+WANh/QZMXr6WYZVg6uPq3zif660i7MhAF8xJ/Ll88ItOxzFHBRQFama5Smdu7BGd6Slzdl5ESOHYEGw== X-Google-Smtp-Source: AGHT+IFmvGP4kjQbEbDT2g0fl+g+oN5j0HQdkwC5X+fRoxaFxeWx8J3r5Cd4cXQHbDyhcvzOJmJ4 X-Received: by 2002:a05:6a00:4006:b0:6f3:eb71:af9d with SMTP id d2e1a72fcca58-6f8f45d8a37mr10942113b3a.28.1716818762549; Mon, 27 May 2024 07:06:02 -0700 (PDT) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f8fcfd8749si6164578b3a.150.2024.05.27.07.06.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:06:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190693-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="ZoPsV5/f"; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-190693-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190693-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5B816B28803 for ; Mon, 27 May 2024 13:27:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55A8A15EFB2; Mon, 27 May 2024 13:27:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZoPsV5/f" Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06F3215EFAC for ; Mon, 27 May 2024 13:27:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716816465; cv=none; b=AS0ZoWA/sp08qd2ajKWnBfVIe/1Po61ySz3xJi2tZg3T33A4HAcjZAdNYzE6nX6V2BKcbL8NW+4pQIxdlQ/JzoDPrj51TOblqynSRcf4XfSZ3MIDGIRH+9H0t5yoRLQbU/SsCaV5JoLTfjWvANSFhkAsGodG94APcHSfS6IVfC0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716816465; c=relaxed/simple; bh=TuIFBfTPCEqP6bHPkoDibmXslNfsgD9MX9uClz3Xr40=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=tlMryzpvae0P2ZikrfPyq20PQOX7qWStu7CZr4YEoku8RjraqV7xjEg2EAr1s0pNFENz6+YPIDpsqb4R34FLRZ/NlZlc06A8aKgIDlYorBPqlsfS9tt/yc/zC2KAHtmq6cVuDFrTS6sInmpFOe+Rq6nqGu/6PIKrt9sNjS7894g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZoPsV5/f; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5788eaf5366so2079637a12.2 for ; Mon, 27 May 2024 06:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716816462; x=1717421262; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2PiCS/M86gUVosiM8K3s52DAeVhft4izSu+PTRcDU+c=; b=ZoPsV5/fEBCGdFIQuKCZyTCUDWfXaZPDkOUAgGApiJ5ZmaOW9+pwDKQ6M+HEzDhu0B KKIjUqgCtgA7qqmjsxTheYGDIg+MsDkYhlYM228qsu4HsStkOfE3IsDw9B6cZtiN6Th1 GN92T1N0h4rKDQ+nPEzxmw6chh/PEW1J+AK6GMq6S26bS/KcsAVMxTCaqtBUAgnCYFLe 2RDzfa0bPegmk8hQTsAe487HFQmwBz61t/DnlMmzxJ7XxWmD247lBv8dFEMxWcsfqn+K vaK8bJOM2gKHuaYFx4arOk5xoA3/lhuXMgA90ywczx1hGZawyHiiD/KzyFWzyKrj/FPw 0hrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716816462; x=1717421262; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2PiCS/M86gUVosiM8K3s52DAeVhft4izSu+PTRcDU+c=; b=phxMIQli41NyEyTrbJ3X25tXX2fqYTTJ26mtGv3HiynWZnT/2P/E+1VAxtZnhNWN1v BLg79xKCYwaxDufRUpDFv2QPMvjZOdwSvVpL2V2UCMS/XJ16QXInWSFQ3kyH97nDaieq AII2UpdJDp3eD5RMz4rADNAW7sOAHLFdWVVXdBG6RZM0hAsK+TVQ9Sb2HbofB4olmMaE 7M1FMNDQJ3+JhkBBLHTjWk/YaGYk2gnva0yNtyjZJ8i88LhOKUke5iQc+Hf249xtvCSb ntKc9rUOjQytRsAVLyLm9N2zRv81QNUMHz/yIk5vGRVt9jVgzdJ2TN82Vae9oMJGcQqt PhgA== X-Gm-Message-State: AOJu0YxDIHP+PtXkhp31C9deCkbK41x8AET31X1RlmiQeRQP238DiPuw h2nZEc1F5U6vPPyiPSflkgCi8T5WqzpOUSCvf+5MU8n2jN0AzXXAPH7ZEYl5qkz5fHZxxe89uFC /86CmD2UNkiEAuE6tW0KM7clK7z8= X-Received: by 2002:a17:906:7f15:b0:a62:e9c:f621 with SMTP id a640c23a62f3a-a6265148c46mr662007966b.58.1716816462000; Mon, 27 May 2024 06:27:42 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240527094320.2653177-1-jani.nikula@intel.com> In-Reply-To: <20240527094320.2653177-1-jani.nikula@intel.com> From: Andy Shevchenko Date: Mon, 27 May 2024 16:27:05 +0300 Message-ID: Subject: Re: [PATCH 1/2] string: add mem_is_zero() helper to check if memory area is all zeros To: Jani Nikula Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, Kees Cook , Andy Shevchenko Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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)? --=20 With Best Regards, Andy Shevchenko