summaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2017-01-10 07:08:55 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2017-01-12 07:40:00 +0100
commitf36c383bcc053da35edcbc3ca1dfffe78993e3e0 (patch)
treefb047b17634d839a84ba31fcd54c9e0d5e703406 /arch
parenta97345102e9c438b846023b9fc6a8e834c87ea7b (diff)
downloadbarebox-f36c383bcc053da35edcbc3ca1dfffe78993e3e0.tar.gz
i.MX: ocotp: Move memory reversing into a subroutine
Move memory reversing, found in imx_ocotp_get_mac and imx_ocotp_set_mac, into a subroutine to avoid code duplication. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/mach-imx/ocotp.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/arch/arm/mach-imx/ocotp.c b/arch/arm/mach-imx/ocotp.c
index 68ff0ce..7f625d8 100644
--- a/arch/arm/mach-imx/ocotp.c
+++ b/arch/arm/mach-imx/ocotp.c
@@ -397,19 +397,26 @@ static void imx_ocotp_init_dt(struct device_d *dev, void __iomem *base)
}
}
+static void memreverse(void *dest, const void *src, size_t n)
+{
+ char *destp = dest;
+ const char *srcp = src + n - 1;
+
+ while(n--)
+ *destp++ = *srcp--;
+}
+
static int imx_ocotp_get_mac(struct param_d *param, void *priv)
{
struct ocotp_priv *ocotp_priv = priv;
char buf[8];
- int i, ret;
+ int ret;
ret = regmap_bulk_read(ocotp_priv->map, MAC_OFFSET, buf, MAC_BYTES);
if (ret < 0)
return ret;
- for (i = 0; i < 6; i++)
- ocotp_priv->ethaddr[i] = buf[5 - i];
-
+ memreverse(ocotp_priv->ethaddr, buf, 6);
return 0;
}
@@ -417,10 +424,9 @@ static int imx_ocotp_set_mac(struct param_d *param, void *priv)
{
struct ocotp_priv *ocotp_priv = priv;
char buf[8];
- int i, ret;
+ int ret;
- for (i = 0; i < 6; i++)
- buf[5 - i] = ocotp_priv->ethaddr[i];
+ memreverse(buf, ocotp_priv->ethaddr, 6);
buf[6] = 0; buf[7] = 0;
ret = regmap_bulk_write(ocotp_priv->map, MAC_OFFSET, buf, MAC_BYTES);