lkml.org 
[lkml]   [2019]   [Aug]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 1/1] pseries/hotplug-memory.c: Replace nested ifs by switch-case
From
Date
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

\
 
 \ /
  Last update: 2019-08-02 09:22    [W:0.088 / U:5.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site