From: Eliav Farber <farbere@amazon.com>
To: <bp@alien8.de>
Cc: <mchehab@kernel.org>, <linux-edac@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <ronenk@amazon.com>,
<talel@amazon.com>, <hhhawa@amazon.com>, <jonnyc@amazon.com>,
<hanochu@amazon.com>, <farbere@amazon.com>
Subject: [PATCH 4/4] EDAC: Refactor edac_align_ptr() flow
Date: Thu, 13 Jan 2022 10:06:22 +0000 [thread overview]
Message-ID: <20220113100622.12783-5-farbere@amazon.com> (raw)
In-Reply-To: <20220113100622.12783-1-farbere@amazon.com>
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@amazon.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
next prev parent reply other threads:[~2022-01-13 10:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-13 10:06 [PATCH 0/4] edac_align_ptr() bug fix and refactoring Eliav Farber
2022-01-13 10:06 ` [PATCH 1/4] EDAC: Fix calculation of returned address and next offset in edac_align_ptr() Eliav Farber
2022-01-25 14:37 ` Borislav Petkov
2022-01-27 9:58 ` Farber, Eliav
2022-02-15 12:34 ` Borislav Petkov
2022-02-15 13:06 ` Farber, Eliav
2022-01-13 10:06 ` [PATCH 2/4] EDAC: Remove unnecessary cast to char* in edac_align_ptr() function Eliav Farber
2022-01-26 18:46 ` Borislav Petkov
2022-01-13 10:06 ` [PATCH 3/4] EDAC: Refactor edac_align_ptr() to use u8/u16/u32/u64 data types Eliav Farber
2022-02-15 16:55 ` Borislav Petkov
2022-01-13 10:06 ` Eliav Farber [this message]
2022-02-15 17:08 ` [PATCH 4/4] EDAC: Refactor edac_align_ptr() flow Borislav Petkov
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=20220113100622.12783-5-farbere@amazon.com \
--to=farbere@amazon.com \
--cc=bp@alien8.de \
--cc=hanochu@amazon.com \
--cc=hhhawa@amazon.com \
--cc=jonnyc@amazon.com \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ronenk@amazon.com \
--cc=talel@amazon.com \
/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
Powered by JetHome