public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@intel.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org,
	Kees Cook <keescook@chromium.org>,
	Andy Shevchenko <andy@kernel.org>
Subject: Re: [PATCH 1/2] string: add mem_is_zero() helper to check if memory area is all zeros
Date: Mon, 27 May 2024 17:06:28 +0300	[thread overview]
Message-ID: <87jzjfmjrv.fsf@intel.com> (raw)
In-Reply-To: <CAHp75VcWXCeQo4n67cfq0VQaO-+YW-=iqKx+r4NtFfYnJBTBFA@mail.gmail.com>

On Mon, 27 May 2024, Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> On Mon, May 27, 2024 at 12:43 PM Jani Nikula <jani.nikula@intel.com> 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.


-- 
Jani Nikula, Intel

      reply	other threads:[~2024-05-27 14:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27  9:43 [PATCH 1/2] string: add mem_is_zero() helper to check if memory area is all zeros Jani Nikula
2024-05-27  9:43 ` [PATCH 2/2] drm: use mem_is_zero() instead of !memchr_inv(s, 0, n) Jani Nikula
2024-05-27 13:19   ` Andy Shevchenko
2024-05-27 14:08     ` Jani Nikula
2024-05-27 13:27 ` [PATCH 1/2] string: add mem_is_zero() helper to check if memory area is all zeros Andy Shevchenko
2024-05-27 14:06   ` Jani Nikula [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87jzjfmjrv.fsf@intel.com \
    --to=jani.nikula@intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox