linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] pseries/hotplug-memory.c: Replace nested ifs by switch-case
@ 2019-08-01 22:52 Leonardo Bras
  2019-08-02  7:21 ` David Hildenbrand
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Leonardo Bras @ 2019-08-01 22:52 UTC (permalink / raw)
  To: linuxppc-dev, linux-kernel
  Cc: Leonardo Bras, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman, Nathan Fontenot, Pavel Tatashin,
	Greg Kroah-Hartman, Andrew Morton, David Hildenbrand,
	Nathan Lynch, YueHaibing, Mahesh Salgaonkar, Rob Herring

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(-)

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] pseries/hotplug-memory.c: Replace nested ifs by switch-case
  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-10 10:20 ` Michael Ellerman
  2 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand @ 2019-08-02  7:21 UTC (permalink / raw)
  To: Leonardo Bras, linuxppc-dev, linux-kernel
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Nathan Fontenot, Pavel Tatashin, Greg Kroah-Hartman,
	Andrew Morton, Nathan Lynch, YueHaibing, Mahesh Salgaonkar,
	Rob Herring

On 02.08.19 00:52, Leonardo Bras wrote:
> 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(-)

More LOC but seems to be the right thing to do

Reviewed-by: David Hildenbrand <david@redhat.com>

> 
> 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;
> 


-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] pseries/hotplug-memory.c: Replace nested ifs by switch-case
  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
  2019-08-10 10:20 ` Michael Ellerman
  2 siblings, 1 reply; 5+ messages in thread
From: Michael Ellerman @ 2019-08-02 12:26 UTC (permalink / raw)
  To: Leonardo Bras, linuxppc-dev, linux-kernel
  Cc: Leonardo Bras, Benjamin Herrenschmidt, Paul Mackerras,
	Nathan Fontenot, Pavel Tatashin, Greg Kroah-Hartman,
	Andrew Morton, David Hildenbrand, Nathan Lynch, YueHaibing,
	Mahesh Salgaonkar, Rob Herring

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"

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] pseries/hotplug-memory.c: Replace nested ifs by switch-case
  2019-08-02 12:26 ` Michael Ellerman
@ 2019-08-02 13:18   ` Leonardo Bras
  0 siblings, 0 replies; 5+ messages in thread
From: Leonardo Bras @ 2019-08-02 13:18 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev, linux-kernel
  Cc: Nathan Lynch, Pavel Tatashin, David Hildenbrand,
	Greg Kroah-Hartman, YueHaibing, Mahesh Salgaonkar,
	Paul Mackerras, Nathan Fontenot, Andrew Morton, Rob Herring

[-- 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 --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] pseries/hotplug-memory.c: Replace nested ifs by switch-case
  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-10 10:20 ` Michael Ellerman
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2019-08-10 10:20 UTC (permalink / raw)
  To: Leonardo Bras, linuxppc-dev, linux-kernel
  Cc: Nathan Lynch, Pavel Tatashin, Greg Kroah-Hartman,
	David Hildenbrand, YueHaibing, Mahesh Salgaonkar, Paul Mackerras,
	Nathan Fontenot, Leonardo Bras, Andrew Morton, Rob Herring

On Thu, 2019-08-01 at 22:52:51 UTC, Leonardo Bras wrote:
> 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>
> Reviewed-by: David Hildenbrand <david@redhat.com>

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/9616dda1aaddb2080122aaeab96ad7fc064e36b4

cheers

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-10 10:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2019-08-10 10:20 ` Michael Ellerman

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).