From: Ingo Molnar <mingo@kernel.org>
To: Jordan Borgner <mail@jordan-borgner.de>
Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
x86@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com
Subject: Re: [PATCH] arch/x86/boot/memory.c: Touched up coding-style issues
Date: Sun, 28 Oct 2018 11:46:14 +0100 [thread overview]
Message-ID: <20181028104614.GA98913@gmail.com> (raw)
In-Reply-To: <20181027223231.pyigrae7mhl2xil2@JordanDesktop>
* Jordan Borgner <mail@jordan-borgner.de> wrote:
> Added missing parentheses to sizeof() function in detect_memory_e820().
>
> Removed unnecessary braces in detect_memory_e801().
>
> Replaced three if-statements with a ternary if-statement and
> removed an unnecessary integer variable in detect_memory().
>
> This is my first patch I hope it is okay.
>
> Signed-off-by: Jordan Borgner <mail@jordan-borgner.de>
> ---
> linux-4.19/arch/x86/boot/memory.c | 24 +++++++-----------------
> 1 file changed, 7 insertions(+), 17 deletions(-)
>
> diff --git a/linux-4.19/arch/x86/boot/memory.c b/linux-4.19/arch/x86/boot/memory.c
> index d9c28c8..a6124af 100644
> --- a/linux-4.19/arch/x86/boot/memory.c
> +++ b/linux-4.19/arch/x86/boot/memory.c
> @@ -26,7 +26,7 @@ static int detect_memory_e820(void)
>
> initregs(&ireg);
> ireg.ax = 0xe820;
> - ireg.cx = sizeof buf;
> + ireg.cx = sizeof(buf);
> ireg.edx = SMAP;
> ireg.di = (size_t)&buf;
That's legit - could you do a single patch that only changes all the
'sizeof x' patterns in arch/x86/ to 'sizeof(x)']?
>
> @@ -88,11 +88,11 @@ static int detect_memory_e801(void)
> oreg.bx = oreg.dx;
> }
>
> - if (oreg.ax > 15*1024) {
> + if (oreg.ax > 15*1024)
> return -1; /* Bogus! */
> - } else if (oreg.ax == 15*1024) {
> + else if (oreg.ax == 15*1024)
> boot_params.alt_mem_k = (oreg.bx << 6) + oreg.ax;
> - } else {
> + else
> /*
> * This ignores memory above 16MB if we have a memory
> * hole there. If someone actually finds a machine
> @@ -101,7 +101,6 @@ static int detect_memory_e801(void)
> * map.
> */
> boot_params.alt_mem_k = oreg.ax;
> - }
The original code was better - multi-screen-line statements require curly
braces in general.
>
> return 0;
> }
> @@ -121,16 +120,7 @@ static int detect_memory_88(void)
>
> int detect_memory(void)
> {
> - int err = -1;
> -
> - if (detect_memory_e820() > 0)
> - err = 0;
> -
> - if (!detect_memory_e801())
> - err = 0;
> -
> - if (!detect_memory_88())
> - err = 0;
> -
> - return err;
> + return (detect_memory_e820() > 0 ||
> + !detect_memory_e801() ||
> + !detect_memory_88()) ? 0 : -1;
Here too I think the original flow of logic was easier to read - more
compact is not always better.
Also, please investigate whether the return value is actually *used*, and
if not then please send a separate patch that simplifies the code.
Thanks,
Ingo
prev parent reply other threads:[~2018-10-28 10:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-27 22:32 [PATCH] arch/x86/boot/memory.c: Touched up coding-style issues Jordan Borgner
2018-10-27 22:55 ` Joe Perches
2018-10-28 10:46 ` Ingo Molnar [this message]
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=20181028104614.GA98913@gmail.com \
--to=mingo@kernel.org \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mail@jordan-borgner.de \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.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