From: Leonardo Bras <leonardo@linux.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Cc: Nathan Lynch <nathanl@linux.ibm.com>,
Pavel Tatashin <pavel.tatashin@microsoft.com>,
David Hildenbrand <david@redhat.com>,
Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>,
YueHaibing <yuehaibing@huawei.com>,
Paul Mackerras <paulus@samba.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Nathan Fontenot <nfont@linux.vnet.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Rob Herring <robh@kernel.org>
Subject: Re: [PATCH 1/1] pseries/hotplug-memory.c: Replace nested ifs by switch-case
Date: Fri, 02 Aug 2019 10:18:57 -0300 [thread overview]
Message-ID: <e076cff01d58c8b4031f2dfd4eeb0883d71ff495.camel@linux.ibm.com> (raw)
In-Reply-To: <87sgqjkb1z.fsf@concordia.ellerman.id.au>
[-- Attachment #1: Type: text/plain, Size: 2960 bytes --]
On Fri, 2019-08-02 at 22:26 +1000, Michael Ellerman wrote:
> Leonardo Bras <leonardo@linux.ibm.com> writes:
> > I noticed these nested ifs can be easily replaced by switch-cases,
> > which can improve readability.
> >
> > Signed-off-by: Leonardo Bras <leonardo@linux.ibm.com>
> > ---
> > .../platforms/pseries/hotplug-memory.c | 26 +++++++++++++------
> > 1 file changed, 18 insertions(+), 8 deletions(-)
>
> Thanks, this looks sensible.
>
> Please use "powerpc/" as the prefix on your patches, eg. in this case:
>
> "powerpc/pseries/hotplug-memory.c: Replace nested ifs by switch-case"
>
Ok, I will make sure to do that next time.
Thanks!
> I'll fix it up this time when I apply.
>
> cheers
>
> > diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
> > index 46d0d35b9ca4..8e700390f3d6 100644
> > --- a/arch/powerpc/platforms/pseries/hotplug-memory.c
> > +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
> > @@ -880,34 +880,44 @@ int dlpar_memory(struct pseries_hp_errorlog *hp_elog)
> >
> > switch (hp_elog->action) {
> > case PSERIES_HP_ELOG_ACTION_ADD:
> > - if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_COUNT) {
> > + switch (hp_elog->id_type) {
> > + case PSERIES_HP_ELOG_ID_DRC_COUNT:
> > count = hp_elog->_drc_u.drc_count;
> > rc = dlpar_memory_add_by_count(count);
> > - } else if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_INDEX) {
> > + break;
> > + case PSERIES_HP_ELOG_ID_DRC_INDEX:
> > drc_index = hp_elog->_drc_u.drc_index;
> > rc = dlpar_memory_add_by_index(drc_index);
> > - } else if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_IC) {
> > + break;
> > + case PSERIES_HP_ELOG_ID_DRC_IC:
> > count = hp_elog->_drc_u.ic.count;
> > drc_index = hp_elog->_drc_u.ic.index;
> > rc = dlpar_memory_add_by_ic(count, drc_index);
> > - } else {
> > + break;
> > + default:
> > rc = -EINVAL;
> > + break;
> > }
> >
> > break;
> > case PSERIES_HP_ELOG_ACTION_REMOVE:
> > - if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_COUNT) {
> > + switch (hp_elog->id_type) {
> > + case PSERIES_HP_ELOG_ID_DRC_COUNT:
> > count = hp_elog->_drc_u.drc_count;
> > rc = dlpar_memory_remove_by_count(count);
> > - } else if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_INDEX) {
> > + break;
> > + case PSERIES_HP_ELOG_ID_DRC_INDEX:
> > drc_index = hp_elog->_drc_u.drc_index;
> > rc = dlpar_memory_remove_by_index(drc_index);
> > - } else if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_IC) {
> > + break;
> > + case PSERIES_HP_ELOG_ID_DRC_IC:
> > count = hp_elog->_drc_u.ic.count;
> > drc_index = hp_elog->_drc_u.ic.index;
> > rc = dlpar_memory_remove_by_ic(count, drc_index);
> > - } else {
> > + break;
> > + default:
> > rc = -EINVAL;
> > + break;
> > }
> >
> > break;
> > --
> > 2.20.1
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-08-02 13:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-01 22:52 [PATCH 1/1] pseries/hotplug-memory.c: Replace nested ifs by switch-case Leonardo Bras
2019-08-02 7:21 ` David Hildenbrand
2019-08-02 12:26 ` Michael Ellerman
2019-08-02 13:18 ` Leonardo Bras [this message]
2019-08-10 10:20 ` Michael Ellerman
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=e076cff01d58c8b4031f2dfd4eeb0883d71ff495.camel@linux.ibm.com \
--to=leonardo@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mahesh@linux.vnet.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=nathanl@linux.ibm.com \
--cc=nfont@linux.vnet.ibm.com \
--cc=paulus@samba.org \
--cc=pavel.tatashin@microsoft.com \
--cc=robh@kernel.org \
--cc=yuehaibing@huawei.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;
as well as URLs for NNTP newsgroup(s).