[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220113100622.12783-5-farbere@amazon.com>
Date: Thu, 13 Jan 2022 10:06:22 +0000
From: Eliav Farber <farbere@...zon.com>
To: <bp@...en8.de>
CC: <mchehab@...nel.org>, <linux-edac@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <ronenk@...zon.com>,
<talel@...zon.com>, <hhhawa@...zon.com>, <jonnyc@...zon.com>,
<hanochu@...zon.com>, <farbere@...zon.com>
Subject: [PATCH 4/4] EDAC: Refactor edac_align_ptr() flow
Modify flow to be more clear:
- Calculate required alignment based on size.
- Check if *p is aligned and fix if not.
- Set return ptr to to be *p.
- Increase *p by new size for the next call.
Signed-off-by: Eliav Farber <farbere@...zon.com>
---
drivers/edac/edac_mc.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index 3367bf997b73..a3ff5a019fc7 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -241,9 +241,7 @@ EXPORT_SYMBOL_GPL(edac_mem_types);
void *edac_align_ptr(void **p, unsigned size, int n_elems)
{
unsigned align, r;
- void *ptr = *p;
-
- *p += size * n_elems;
+ void *ptr;
/*
* 'p' can possibly be an unaligned item X such that sizeof(X) is
@@ -258,16 +256,22 @@ void *edac_align_ptr(void **p, unsigned size, int n_elems)
else if (size > sizeof(u8))
align = sizeof(u16);
else
- return ptr;
-
- r = (unsigned long)ptr % align;
+ goto out;
- if (r == 0)
- return ptr;
+ /* Calculate alignment, and fix *p if not aligned. */
+ r = (unsigned long)*p % align;
+ if (r)
+ *p += align - r;
- *p += align - r;
+out:
+ /*
+ * Set return ptr to to be *p (after alignment if it was needed),
+ * and increase *p by new size for the next call.
+ */
+ ptr = *p;
+ *p += size * n_elems;
- return (void *)(((unsigned long)ptr) + align - r);
+ return ptr;
}
static void _edac_mc_free(struct mem_ctl_info *mci)
--
2.32.0
Powered by blists - more mailing lists