From 6dcb168442a8a1749fc44433db451b7c755abd39 Mon Sep 17 00:00:00 2001 From: Patrick Venture Date: Tue, 4 Dec 2018 09:44:27 -0800 Subject: [PATCH] fru: add fru_cc_rq2big helper method for code checks Add fru_cc_rq2big helper method to reduce duplicate code checking for specific size-based IPMI response codes. Signed-off-by: Patrick Venture --- lib/ipmi_fru.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/ipmi_fru.c b/lib/ipmi_fru.c index bc26191..918ddda 100644 --- a/lib/ipmi_fru.c +++ b/lib/ipmi_fru.c @@ -101,6 +101,12 @@ static const char * chassis_type_desc[] = { "Blade Enclosure" }; +static inline bool fru_cc_rq2big(int code) { + return (code == IPMI_CC_REQ_DATA_INV_LENGTH + || code == IPMI_CC_REQ_DATA_FIELD_EXCEED + || code == IPMI_CC_CANT_RET_NUM_REQ_BYTES); +} + /* From lib/dimm_spd.c: */ int ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id); @@ -598,16 +604,14 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, break; } - if (rsp->ccode == IPMI_CC_REQ_DATA_INV_LENGTH - || rsp->ccode == IPMI_CC_REQ_DATA_FIELD_EXCEED - || rsp->ccode == IPMI_CC_CANT_RET_NUM_REQ_BYTES) { + if (fru_cc_rq2big(rsp->ccode)) { if (fru->max_write_size > 8) { fru->max_write_size -= 8; lprintf(LOG_INFO, "Retrying FRU write with request size %d", fru->max_write_size); continue; } - } else if(rsp->ccode == 0x80) { + } else if (rsp->ccode == 0x80) { rsp->ccode = 0; // Write protected section protected_bloc = 1; @@ -732,9 +736,7 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, if (rsp->ccode) { /* if we get C7h or C8h or CAh return code then we requested too * many bytes at once so try again with smaller size */ - if ((rsp->ccode == IPMI_CC_REQ_DATA_INV_LENGTH - || rsp->ccode == IPMI_CC_REQ_DATA_FIELD_EXCEED - || rsp->ccode == IPMI_CC_CANT_RET_NUM_REQ_BYTES) + if (fru_cc_rq2big(rsp->ccode) && fru->max_read_size > 8) { if (fru->max_read_size > 32) { /* subtract read length more aggressively */ @@ -840,10 +842,7 @@ read_fru_area_section(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, if (rsp->ccode) { /* if we get C7 or C8 or CA return code then we requested too * many bytes at once so try again with smaller size */ - if ((rsp->ccode == IPMI_CC_REQ_DATA_INV_LENGTH - || rsp->ccode == IPMI_CC_REQ_DATA_FIELD_EXCEED - || rsp->ccode == IPMI_CC_CANT_RET_NUM_REQ_BYTES) - && (--fru_data_rqst_size > 8)) { + if (fru_cc_rq2big(rsp->ccode) && (--fru_data_rqst_size > 8)) { lprintf(LOG_INFO, "Retrying FRU read with request size %d", fru_data_rqst_size);