All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] string: use min in sized_strscpy
Date: Tue, 19 May 2026 12:37:40 -0700	[thread overview]
Message-ID: <20260519123740.458d905f958f39d41cb130fd@linux-foundation.org> (raw)
In-Reply-To: <20260514165601.527883-3-thorsten.blum@linux.dev>

On Thu, 14 May 2026 18:56:03 +0200 Thorsten Blum <thorsten.blum@linux.dev> wrote:

> Use min() and drop the limit variable to simplify sized_strscpy().

Why is this code so messy.   Never seen so many typecasts per inch.

> @@ -125,11 +126,8 @@ ssize_t sized_strscpy(char *dest, const char *src, size_t count)
>  	 * If src is unaligned, don't cross a page boundary,
>  	 * since we don't know if the next page is mapped.
>  	 */
> -	if ((long)src & (sizeof(long) - 1)) {
> -		size_t limit = PAGE_SIZE - ((long)src & (PAGE_SIZE - 1));
> -		if (limit < max)
> -			max = limit;
> -	}
> +	if ((long)src & (sizeof(long) - 1))

That looks like IS_ALIGNED()?

> +		max = min(PAGE_SIZE - ((long)src & (PAGE_SIZE - 1)), max);

That looks like a dog's breakfast.

And a bit like ALIGN_DOWN.  Not quite, but I'm sure we have helpers for
whatever this is doing.

>  #else
>  	/* If src or dest is unaligned, don't do word-at-a-time. */
>  	if (((long) dest | (long) src) & (sizeof(long) - 1))

gargh.


Oh well, not your fault.  I'll grab the patch, thanks.

      parent reply	other threads:[~2026-05-19 19:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-14 16:56 [PATCH] string: use min in sized_strscpy Thorsten Blum
2026-05-15  6:45 ` Andy Shevchenko
2026-05-15 15:09   ` Thorsten Blum
2026-05-17  5:56     ` Andy Shevchenko
2026-05-17 14:14     ` David Laight
2026-05-19 19:37 ` Andrew Morton [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=20260519123740.458d905f958f39d41cb130fd@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=andy@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thorsten.blum@linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.