mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lasse Collin <lasse.collin@tukaani.org>
To: T Makphaibulchoke <tmac@hp.com>
Cc: linux@arm.linux.org.uk, schwidefsky@de.ibm.com,
	heiko.carstens@de.ibm.com, linux390@de.ibm.com,
	lethal@linux-sh.org, hpa@zytor.com, tglx@linutronix.de,
	mingo@redhat.com, x86@kernel.org, kaloz@openwrt.org,
	nicolas.pitre@linaro.org, jj@chaosbits.net,
	matt.fleming@intel.com, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org,
	linux-sh@vger.kernel.org
Subject: Re: [PATCH v2] lib/decompress_unxz.c: removing all memory helper functions
Date: Tue, 12 Jun 2012 19:18:04 +0300	[thread overview]
Message-ID: <20120612191804.4211462a@tukaani.org> (raw)
In-Reply-To: <1339470307-28223-1-git-send-email-tmac@hp.com>

On 2012-06-11 T Makphaibulchoke wrote:
> --- /dev/null
> +++ b/lib/boot/mem.c
> @@ -0,0 +1,58 @@
> +/*
> + * Small subset of simple memory helper functions required by different
> + * compressors for preboot environment.
> + */
> +
> +#include <linux/string.h>
> +
> +#ifndef __HAVE_PREBOOT_ARCH_MEMCPY
> +void *memcpy(void *__dest, __const void *__src, size_t __n)
> +{
> +	return __builtin_memcpy(__dest, __src, __n);
> +}
> +#endif

GCC will replace __builtin_memcpy above with a call to memcpy, creating
an infinite loop. I confirmed this on x86_64 by first uncommenting the
memcpy from arch/x86/boot/compressed/string.c.

You need to provide a memcpy implementation yourself without using
__builtin functions. For example, copy the memcpy implementation from
lib/string.c.

> +#ifndef __HAVE_PREBOOT_ARCH_MEMMOVE
> +void *memmove(void *__dest, __const void *__src, size_t count)
> +{
> +	unsigned char *d = __dest;
> +	const unsigned char *s = __src;
> +
> +	if (__dest == __src)
> +		return __dest;
> +
> +	if (__dest < __src)
> +		return memcpy(__dest, __src, count);
> +
> +	while (count--)
> +		d[count] = s[count];
> +	return __dest;
> +}
> +#endif

The use of memcpy when __dest < __src is OK with some memcpy
implementations, but in a generic case it isn't guaranteed to work.
I think it would be better to just copy memmove from lib/string.c.

-- 
Lasse Collin  |  IRC: Larhzu @ IRCnet & Freenode

  parent reply	other threads:[~2012-06-12 16:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-12  3:05 T Makphaibulchoke
2012-06-12  3:16 ` H. Peter Anvin
2012-06-12 14:35   ` Russell King - ARM Linux
2012-06-14 13:47     ` Russell King - ARM Linux
2012-06-14 14:35       ` H. Peter Anvin
2012-06-14 15:44         ` Russell King - ARM Linux
2012-06-14 16:15           ` H. Peter Anvin
2012-06-13  9:32   ` Martin Schwidefsky
2012-06-14 18:23   ` Russell King - ARM Linux
2012-06-12  3:27 ` Paul Mundt
2012-06-12 16:18 ` Lasse Collin [this message]
2012-06-12 17:26   ` Nicolas Pitre
2012-06-12 17:30     ` H. Peter Anvin
2012-06-12 17:40       ` Joe Perches
2012-06-12 19:45         ` Thavatchai Makphaibulcboke
2012-06-12 17:44       ` Nicolas Pitre
2012-06-12 17:48         ` H. Peter Anvin
2012-06-12 17:49           ` H. Peter Anvin

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=20120612191804.4211462a@tukaani.org \
    --to=lasse.collin@tukaani.org \
    --cc=heiko.carstens@de.ibm.com \
    --cc=hpa@zytor.com \
    --cc=jj@chaosbits.net \
    --cc=kaloz@openwrt.org \
    --cc=lethal@linux-sh.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=linux390@de.ibm.com \
    --cc=linux@arm.linux.org.uk \
    --cc=matt.fleming@intel.com \
    --cc=mingo@redhat.com \
    --cc=nicolas.pitre@linaro.org \
    --cc=schwidefsky@de.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=tmac@hp.com \
    --cc=x86@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

all inboxes | Powered by JetHome®