lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 02 Aug 2019 10:18:57 -0300
From:   Leonardo Bras <leonardo@...ux.ibm.com>
To:     Michael Ellerman <mpe@...erman.id.au>,
        linuxppc-dev@...ts.ozlabs.org, linux-kernel@...r.kernel.org
Cc:     Nathan Lynch <nathanl@...ux.ibm.com>,
        Pavel Tatashin <pavel.tatashin@...rosoft.com>,
        David Hildenbrand <david@...hat.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        YueHaibing <yuehaibing@...wei.com>,
        Mahesh Salgaonkar <mahesh@...ux.vnet.ibm.com>,
        Paul Mackerras <paulus@...ba.org>,
        Nathan Fontenot <nfont@...ux.vnet.ibm.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Rob Herring <robh@...nel.org>
Subject: Re: [PATCH 1/1] pseries/hotplug-memory.c: Replace nested ifs by
 switch-case

On Fri, 2019-08-02 at 22:26 +1000, Michael Ellerman wrote:
> Leonardo Bras <leonardo@...ux.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@...ux.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

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ