From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 03/18] [RFC] at91: Make IS_ERR work for I/O pointers
Date: Tue, 16 Feb 2016 17:29:04 -0800 [thread overview]
Message-ID: <1455672559-25061-4-git-send-email-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <1455672559-25061-1-git-send-email-andrew.smirnov@gmail.com>
Having this functionality partially "broken" opens the door for subtle
bugs in peripheral drivers for AT91 platform since it not straight out
obvious that IS_ERR might return a false positive.
It also makes it much harder to judge the correctness of the driver
code, for example it is perfectly fine to use IS_ERR in at91-i2c.c since
I2C controller's register file is located at 0xFFFA_C000 (which it
doesn't but that's the subject for another patch), however one couldn't
help but wonder how the code it sam9_smc.c could possibly work given how
that module is located at 0xFFFF_EC00.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
scripts/include/linux/err.h | 66 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/scripts/include/linux/err.h b/scripts/include/linux/err.h
index bdc3dd8..f6ce0d0 100644
--- a/scripts/include/linux/err.h
+++ b/scripts/include/linux/err.h
@@ -29,6 +29,69 @@
*/
#define MAX_ERRNO 4095
+#ifdef CONFIG_ARCH_AT91
+
+/*
+ * AT91 maps all of its peripherals' register files into last 256MB of
+ * address space. This means that if no appropriate action is taken
+ * ERR_PTR et al. would not work. We also don't have the luxury of
+ * guaranted to be enabled MMU, so remapping is not an option. Instead
+ * we do a little bit of additional arithmetic and "move" all of the
+ * error codes to the page right before AT91's peripheral memory starts
+ * (0xEFFF_0000 to 0xEFFF_FFFF)
+ */
+
+static inline bool IS_ERR_VALUE(unsigned long x)
+{
+ return x >= 0xEFFF0000 &&
+ x <= 0xEFFFFFFF;
+}
+
+static inline void * __must_check ERR_PTR(long error_)
+{
+ /*
+ * We need to remap all errnos from 0xFFFF_0000 - 0xFFFF_FFFF
+ * to 0xEFFF_0000 - 0xEFFF_FFFF
+ *
+ * Given that
+ *
+ * errno_ == 0xFFFF_FFFF - (abs(errno_) - 1)
+ *
+ * and what we want it to be is
+ *
+ * errno_ == 0xEFFF_FFFF - (abs(errno_) - 1)
+ *
+ * desired remapping can be acheived by the following code:
+ */
+ unsigned long e = error_;
+
+ BUG_ON(error_ < -MAX_ERRNO);
+ /*
+ * Since we know that e is not going to be smaller then
+ * 0xFFFF_0000 instead of substracting 0x1000_0000 from 'e' we
+ * can just "convert" most significant nibble of the value to
+ * 'e' using bitwise and
+ */
+ e &= 0xEFFFFFFF;
+
+ return (void *) e;
+}
+
+static inline long __must_check PTR_ERR(__force const void *ptr)
+{
+ unsigned long e = (unsigned long) error;
+
+ /*
+ * This is the "inverse transformation" corresponding to the
+ * code above
+ */
+ e |= 0xF0000000;
+
+ return (long) e;
+}
+
+#else
+
#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
static inline void * __must_check ERR_PTR(long error_)
@@ -41,6 +104,9 @@ static inline long __must_check PTR_ERR(__force const void *ptr)
return (long) ptr;
}
+#endif
+
+
static inline bool __must_check IS_ERR(__force const void *ptr)
{
return IS_ERR_VALUE((unsigned long)ptr);
--
2.5.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2016-02-17 1:30 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-17 1:29 [PATCH 00/17] RFC for additional 'nvmem' plumbing Andrey Smirnov
2016-02-17 1:29 ` [PATCH 01/18] common: Add EPROBE_DEFER to strerror Andrey Smirnov
2016-02-17 1:29 ` [PATCH 02/18] base: driver.c: Coalesce error checking code Andrey Smirnov
2016-02-17 1:29 ` Andrey Smirnov [this message]
2016-02-17 8:34 ` [PATCH 03/18] [RFC] at91: Make IS_ERR work for I/O pointers Sascha Hauer
2016-02-17 20:39 ` Andrey Smirnov
2016-02-18 10:26 ` Sascha Hauer
2016-02-17 1:29 ` [PATCH 04/18] [RFC] base/driver.c: Remove dev_request_mem_region_err_null Andrey Smirnov
2016-02-17 1:29 ` [PATCH 05/18] i2c-at91: Use IS_ERR instead of checking for NULL Andrey Smirnov
2016-02-17 1:29 ` [PATCH 06/18] clk-imx6: Call clk_enable on mmdc_ch0_axi_podf Andrey Smirnov
2016-02-17 1:29 ` [PATCH 07/18] fec_imx: Deallocate clocks when probe fails Andrey Smirnov
2016-02-17 1:29 ` [PATCH 08/18] [RFC] base: Introduce dev_request_mem_resource Andrey Smirnov
2016-02-17 1:29 ` [PATCH 09/18] fec_imx: Deallocate I/O resources if probe fails Andrey Smirnov
2016-02-17 1:29 ` [PATCH 10/18] fec_imx: Free phy_reset GPIO if when " Andrey Smirnov
2016-02-17 1:29 ` [PATCH 11/18] fec_imx: Use FEC_ECNTRL_RESET instead of a magic number Andrey Smirnov
2016-02-17 1:29 ` [PATCH 12/18] fec_imx: Impelemnt reset timeout Andrey Smirnov
2016-02-17 8:43 ` Sascha Hauer
2016-02-17 1:29 ` [PATCH 13/18] fec_imx: Deallocate DMA buffers when probe fails Andrey Smirnov
2016-02-17 1:29 ` [PATCH 14/18] fec_imx: Unregister MDIO " Andrey Smirnov
2016-02-17 1:29 ` [PATCH 15/18] [RFC] net: eth: Always use DEVICE_ID_DYNAMIC Andrey Smirnov
2016-02-17 2:40 ` Trent Piepho
2016-02-17 4:16 ` Andrey Smirnov
2016-02-18 19:30 ` Trent Piepho
2016-02-19 17:17 ` Andrey Smirnov
2016-02-17 1:29 ` [PATCH 16/18] [RFC] nvmem: Add of_nvmem_cell_from_cell_np Andrey Smirnov
2016-02-17 1:29 ` [PATCH 17/18] [RFC] nvmem: Add nvmem-ro-of-blob driver Andrey Smirnov
2016-02-17 8:52 ` Sascha Hauer
2016-02-17 20:40 ` Andrey Smirnov
2016-02-17 1:29 ` [PATCH 18/18] [RFC] nvmem: Add nvmem-sg driver Andrey Smirnov
2016-02-17 3:09 ` [PATCH 00/17] RFC for additional 'nvmem' plumbing Trent Piepho
2016-02-17 4:20 ` Andrey Smirnov
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=1455672559-25061-4-git-send-email-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--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