mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 05/18] asm-generic: split off typeconfused readl and friends
Date: Mon, 13 Nov 2023 13:40:43 +0100	[thread overview]
Message-ID: <20231113124043.GP3359458@pengutronix.de> (raw)
In-Reply-To: <20231110214421.2726093-6-a.fatoum@pengutronix.de>

On Fri, Nov 10, 2023 at 10:44:08PM +0100, Ahmad Fatoum wrote:
> The MMIO accessors in barebox like readl have the error prone
> peculiarity of accepting integer arguments to pointers automatically,
> which makes it easy to confuse address and data.
> 
> We will add an alternative less error-probe way for new code, so first

s/error-probe/error-prone/

> split off the typeconfused code into a separate file.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  include/asm-generic/io-typeconfused.h | 75 +++++++++++++++++++++++++++
>  include/asm-generic/io.h              | 57 +-------------------
>  2 files changed, 76 insertions(+), 56 deletions(-)
>  create mode 100644 include/asm-generic/io-typeconfused.h
> 
> diff --git a/include/asm-generic/io-typeconfused.h b/include/asm-generic/io-typeconfused.h
> new file mode 100644
> index 000000000000..d25ed7db2473
> --- /dev/null
> +++ b/include/asm-generic/io-typeconfused.h
> @@ -0,0 +1,75 @@
> +/* Generic I/O port emulation, based on MN10300 code
> + *
> + * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
> + * Written by David Howells (dhowells@redhat.com)
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public Licence
> + * as published by the Free Software Foundation; either version
> + * 2 of the Licence, or (at your option) any later version.
> + */
> +#ifndef __ASM_GENERIC_IO_TYPECONFUSED_H
> +#define __ASM_GENERIC_IO_TYPECONFUSED_H
> +
> +#include <linux/string.h> /* for memset() and memcpy() */
> +#include <linux/compiler.h>
> +#include <linux/types.h>
> +#include <asm/byteorder.h>
> +
> +/*****************************************************************************/
> +/*
> + * Unlike the definitions in <asm-generic/io.h>, these macros don't complain
> + * about integer arguments and just silently cast them to pointers. This is
> + * a common cause of bugs, but lots of existing code depends on this, so
> + * this header is provided as a transitory measure.
> + */
> +
> +#ifndef __raw_readb
> +#define __raw_readb(a)		(__chk_io_ptr(a), *(volatile unsigned char __force  *)(a))
> +#endif
> +
> +#ifndef __raw_readw
> +#define __raw_readw(a)		(__chk_io_ptr(a), *(volatile unsigned short __force *)(a))
> +#endif
> +
> +#ifndef __raw_readl
> +#define __raw_readl(a)		(__chk_io_ptr(a), *(volatile unsigned int __force   *)(a))
> +#endif
> +
> +#ifndef readb
> +#define readb __raw_readb
> +#endif
> +
> +#ifndef readw
> +#define readw(addr) __le16_to_cpu(__raw_readw(addr))
> +#endif
> +
> +#ifndef readl
> +#define readl(addr) __le32_to_cpu(__raw_readl(addr))
> +#endif
> +
> +#ifndef __raw_writeb
> +#define __raw_writeb(v,a)	(__chk_io_ptr(a), *(volatile unsigned char __force  *)(a) = (v))
> +#endif
> +
> +#ifndef __raw_writew
> +#define __raw_writew(v,a)	(__chk_io_ptr(a), *(volatile unsigned short __force *)(a) = (v))
> +#endif
> +
> +#ifndef __raw_writel
> +#define __raw_writel(v,a)	(__chk_io_ptr(a), *(volatile unsigned int __force   *)(a) = (v))
> +#endif
> +
> +#ifndef writeb
> +#define writeb __raw_writeb
> +#endif
> +
> +#ifndef writew
> +#define writew(b,addr) __raw_writew(__cpu_to_le16(b),addr)
> +#endif
> +
> +#ifndef writel
> +#define writel(b,addr) __raw_writel(__cpu_to_le32(b),addr)
> +#endif
> +
> +#endif /* __ASM_GENERIC_IO_TYPECONFUSED_H */
> diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
> index ab439026928a..6383d71746f1 100644
> --- a/include/asm-generic/io.h
> +++ b/include/asm-generic/io.h
> @@ -15,62 +15,7 @@
>  #include <linux/compiler.h>
>  #include <linux/types.h>
>  #include <asm/byteorder.h>
> -
> -/*****************************************************************************/
> -/*
> - * readX/writeX() are used to access memory mapped devices. On some
> - * architectures the memory mapped IO stuff needs to be accessed
> - * differently. On the simple architectures, we just read/write the
> - * memory location directly.
> - */
> -
> -#ifndef __raw_readb
> -#define __raw_readb(a)		(__chk_io_ptr(a), *(volatile unsigned char __force  *)(a))
> -#endif
> -
> -#ifndef __raw_readw
> -#define __raw_readw(a)		(__chk_io_ptr(a), *(volatile unsigned short __force *)(a))
> -#endif
> -
> -#ifndef __raw_readl
> -#define __raw_readl(a)		(__chk_io_ptr(a), *(volatile unsigned int __force   *)(a))
> -#endif
> -
> -#ifndef readb
> -#define readb __raw_readb
> -#endif
> -
> -#ifndef readw
> -#define readw(addr) __le16_to_cpu(__raw_readw(addr))
> -#endif
> -
> -#ifndef readl
> -#define readl(addr) __le32_to_cpu(__raw_readl(addr))
> -#endif
> -
> -#ifndef __raw_writeb
> -#define __raw_writeb(v,a)	(__chk_io_ptr(a), *(volatile unsigned char __force  *)(a) = (v))
> -#endif
> -
> -#ifndef __raw_writew
> -#define __raw_writew(v,a)	(__chk_io_ptr(a), *(volatile unsigned short __force *)(a) = (v))
> -#endif
> -
> -#ifndef __raw_writel
> -#define __raw_writel(v,a)	(__chk_io_ptr(a), *(volatile unsigned int __force   *)(a) = (v))
> -#endif
> -
> -#ifndef writeb
> -#define writeb __raw_writeb
> -#endif
> -
> -#ifndef writew
> -#define writew(b,addr) __raw_writew(__cpu_to_le16(b),addr)
> -#endif
> -
> -#ifndef writel
> -#define writel(b,addr) __raw_writel(__cpu_to_le32(b),addr)
> -#endif
> +#include <asm-generic/io-typeconfused.h>
>  
>  #ifdef CONFIG_64BIT
>  static inline u64 __raw_readq(const volatile void __iomem *addr)
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



  reply	other threads:[~2023-11-13 12:41 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-10 21:44 [PATCH 00/18] prepare for porting OP-TEE communication support Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 01/18] include: provide linux/errno.h Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 02/18] include: add linux/refcount.h Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 03/18] bitops: split off linux/bits.h Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 04/18] include: import <linux/instruction_pointer.h> Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 05/18] asm-generic: split off typeconfused readl and friends Ahmad Fatoum
2023-11-13 12:40   ` Sascha Hauer [this message]
2023-11-10 21:44 ` [PATCH 06/18] asm-generic: migrate relaxed helpers into asm-generic/io.h Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 07/18] include: add linux/io.h with strict prototypes Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 08/18] include: import Linux word-at-a-time.h Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 09/18] string: implement strscpy Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 10/18] of: add CONFIG_OF for Linux compatibility Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 11/18] include: asm-generic/atomic.h: define atomic_cmpxchg Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 12/18] kbuild: build barebox for -std=gnu11 Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 13/18] include: linux/idr.h: implement more Linux API Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 14/18] include: implement dev_warn_once and friends Ahmad Fatoum
2023-11-13 12:38   ` Sascha Hauer
2023-11-10 21:44 ` [PATCH 15/18] include: add blocking notifier aliases Ahmad Fatoum
2023-11-13 12:39   ` Sascha Hauer
2023-11-10 21:44 ` [PATCH 16/18] include: add Linux ktime API Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 17/18] of: define of_devices_ensure_probed_by_compatible Ahmad Fatoum
2023-11-13 12:47   ` Sascha Hauer
2023-11-10 21:44 ` [PATCH 18/18] include: add linux/device.h wrapper around driver.h Ahmad Fatoum

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=20231113124043.GP3359458@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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