1 Star 0 Fork 12

src-oepkgs-oE-rv/ipmitool

forked from src-openEuler/ipmitool 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
fru-swap-free-calls-for-free_n.patch 12.82 KB
一键复制 编辑 原始数据 按行查看 历史
hexiaowen 提交于 2019-09-30 10:53 . Package init
From a8b3b6282b3d2bb7fa0e54ce47b06302a96439d7 Mon Sep 17 00:00:00 2001
From: Patrick Venture <venture@google.com>
Date: Tue, 25 Dec 2018 06:12:01 -0800
Subject: [PATCH 113/119] fru: swap free() calls for free_n()
Swap calls to free() with calls to free_n() to leverage helper method
and handle clearing pointers after freeing in one step.
Signed-off-by: Patrick Venture <venture@google.com>
---
lib/ipmi_fru.c | 182 ++++++++++++++-----------------------------------
1 file changed, 50 insertions(+), 132 deletions(-)
diff --git a/lib/ipmi_fru.c b/lib/ipmi_fru.c
index 5057dc3..ad99ebe 100644
--- a/lib/ipmi_fru.c
+++ b/lib/ipmi_fru.c
@@ -428,8 +428,7 @@ free_fru_bloc(t_ipmi_fru_bloc *bloc)
while (bloc) {
del = bloc;
bloc = bloc->next;
- free(del);
- del = NULL;
+ free_n(&del);
}
}
@@ -878,8 +877,7 @@ fru_area_print_multirec_bloc(struct ipmi_intf * intf, struct fru_info * fru,
lprintf(LOG_DEBUG ,"Multi-Record area ends at: %i (%xh)",i,i);
- free(fru_data);
- fru_data = NULL;
+ free_n(&fru_data);
}
@@ -920,8 +918,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
/* read in the full fru */
if (read_fru_area(intf, fru, id, offset, fru_len, fru_data) < 0) {
- free(fru_data);
- fru_data = NULL;
+ free_n(&fru_data);
return;
}
@@ -943,8 +940,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Chassis Part Number : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
@@ -952,8 +948,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Chassis Serial : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
/* read any extra fields */
@@ -964,8 +959,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Chassis Extra : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
if (i == j) {
@@ -973,10 +967,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
}
}
- if (fru_data != NULL) {
- free(fru_data);
- fru_data = NULL;
- }
+ free_n(&fru_data);
}
/* fru_area_print_board - Print FRU Board Area
@@ -1018,8 +1009,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru,
/* read in the full fru */
if (read_fru_area(intf, fru, id, offset, fru_len, fru_data) < 0) {
- free(fru_data);
- fru_data = NULL;
+ free_n(&fru_data);
return;
}
@@ -1041,8 +1031,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Board Mfg : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
@@ -1050,8 +1039,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Board Product : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
@@ -1059,8 +1047,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Board Serial : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
@@ -1068,8 +1055,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Board Part Number : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
@@ -1077,8 +1063,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0 && verbose > 0) {
printf(" Board FRU ID : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
/* read any extra fields */
@@ -1089,17 +1074,13 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Board Extra : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
if (i == j)
break;
}
- if (fru_data != NULL) {
- free(fru_data);
- fru_data = NULL;
- }
+ free_n(&fru_data);
}
/* fru_area_print_product - Print FRU Product Area
@@ -1140,8 +1121,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru,
/* read in the full fru */
if (read_fru_area(intf, fru, id, offset, fru_len, fru_data) < 0) {
- free(fru_data);
- fru_data = NULL;
+ free_n(&fru_data);
return;
}
@@ -1157,8 +1137,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Product Manufacturer : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
@@ -1166,8 +1145,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Product Name : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
@@ -1175,8 +1153,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Product Part Number : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
@@ -1184,8 +1161,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Product Version : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
@@ -1193,8 +1169,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Product Serial : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
@@ -1202,8 +1177,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Product Asset Tag : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
@@ -1211,8 +1185,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0 && verbose > 0) {
printf(" Product FRU ID : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
/* read any extra fields */
@@ -1223,17 +1196,13 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru,
if (strlen(fru_area) > 0) {
printf(" Product Extra : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
if (i == j)
break;
}
- if (fru_data != NULL) {
- free(fru_data);
- fru_data = NULL;
- }
+ free_n(&fru_data);
}
/* fru_area_print_multirec - Print FRU Multi Record Area
@@ -1425,7 +1394,7 @@ fru_area_print_multirec(struct ipmi_intf * intf, struct fru_info * fru,
lprintf(LOG_DEBUG ,"Multi-Record area ends at: %i (%xh)", last_off, last_off);
- free(fru_data);
+ free_n(&fru_data);
}
/* ipmi_fru_query_new_value - Query new values to replace original FRU content
@@ -1462,7 +1431,7 @@ int ipmi_fru_query_new_value(uint8_t *data,int offset, size_t len)
for( i=0;i<len;i++ ){
ret = scanf("%x", holder+i);
if (ret != 1) {
- free(holder);
+ free_n(&holder);
return FALSE;
}
}
@@ -1470,8 +1439,7 @@ int ipmi_fru_query_new_value(uint8_t *data,int offset, size_t len)
data[offset++] = (unsigned char) *(holder+i);
}
/* &data[offset++] */
- free(holder);
- holder = NULL;
+ free_n(&holder);
status = TRUE;
}
else{
@@ -3154,12 +3122,7 @@ ipmi_fru_print_all(struct ipmi_intf * intf)
/* restore previous target */
intf->target_addr = save_addr;
}
-
- if (mc) {
- free(mc);
- mc = NULL;
- }
-
+ free_n(&mc);
continue;
}
@@ -3170,15 +3133,11 @@ ipmi_fru_print_all(struct ipmi_intf * intf)
fru = (struct sdr_record_fru_locator *)
ipmi_sdr_get_record(intf, header, itr);
if (fru == NULL || !fru->logical) {
- if (fru) {
- free(fru);
- fru = NULL;
- }
+ free_n(&fru);
continue;
}
rc = ipmi_fru_print(intf, fru);
- free(fru);
- fru = NULL;
+ free_n(&fru);
}
ipmi_sdr_end(intf, itr);
@@ -3254,14 +3213,12 @@ ipmi_fru_read_to_bin(struct ipmi_intf * intf,
printf("Done\n");
} else {
lprintf(LOG_ERR, "Error opening file %s\n", pFileName);
- free(pFruBuf);
- pFruBuf = NULL;
+ free_n(&pFruBuf);
return;
}
fclose(pFile);
}
- free(pFruBuf);
- pFruBuf = NULL;
+ free_n(&pFruBuf);
}
static void
@@ -3325,8 +3282,7 @@ ipmi_fru_write_from_bin(struct ipmi_intf * intf,
lprintf(LOG_INFO,"Done");
}
- free(pFruBuf);
- pFruBuf = NULL;
+ free_n(&pFruBuf);
}
/* ipmi_fru_write_help() - print help text for 'write'
@@ -3529,8 +3485,7 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id ,
i += h->len + sizeof (struct fru_multirec_header);
} while (!(h->format & 0x80) && (error != 1));
- free(fru_data);
- fru_data = NULL;
+ free_n(&fru_data);
}
return 0;
}
@@ -3714,8 +3669,7 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id ,
i += h->len + sizeof (struct fru_multirec_header);
} while (!(h->format & 0x80) && (error != 1));
- free(fru_data);
- fru_data = NULL;
+ free_n(&fru_data);
}
return 0;
}
@@ -3755,33 +3709,21 @@ ipmi_fru_upg_ekeying(struct ipmi_intf * intf,
if (ipmi_fru_get_multirec_from_file(pFileName, buf, fileMultiRecSize,
offFileMultiRec) != 0) {
lprintf(LOG_ERR, "Failed to get multirec from file '%s'.", pFileName);
- if (buf != NULL) {
- free(buf);
- buf = NULL;
- }
+ free_n(&buf);
return (-1);
}
if (ipmi_fru_get_adjust_size_from_buffer(buf, &fileMultiRecSize) != 0) {
lprintf(LOG_ERR, "Failed to adjust size from buffer.");
- if (buf != NULL) {
- free(buf);
- buf = NULL;
- }
+ free_n(&buf);
return (-1);
}
if (write_fru_area(intf, &fruInfo, fruId, 0, offFruMultiRec,
fileMultiRecSize, buf) != 0) {
lprintf(LOG_ERR, "Failed to write FRU area.");
- if (buf != NULL) {
- free(buf);
- buf = NULL;
- }
+ free_n(&buf);
return (-1);
}
- if (buf != NULL) {
- free(buf);
- buf = NULL;
- }
+ free_n(&buf);
lprintf(LOG_INFO, "Done upgrading Ekey.");
return 0;
}
@@ -4283,8 +4225,7 @@ ipmi_fru_read_internal_use(struct ipmi_intf * intf, uint8_t id, char * pFileName
else
{
lprintf(LOG_ERR, "Error opening file %s\n", pFileName);
- free(frubuf);
- frubuf = NULL;
+ free_n(&frubuf);
return -1;
}
fclose(pFile);
@@ -4292,8 +4233,7 @@ ipmi_fru_read_internal_use(struct ipmi_intf * intf, uint8_t id, char * pFileName
}
printf("\n");
- free(frubuf);
- frubuf = NULL;
+ free_n(&frubuf);
}
}
@@ -4376,8 +4316,7 @@ ipmi_fru_write_internal_use(struct ipmi_intf * intf, uint8_t id, char * pFileNam
lprintf(LOG_ERR, "Unable to read file: %i\n", fru_read_size);
}
- free(frubuf);
- frubuf = NULL;
+ free_n(&frubuf);
}
fclose(fp);
fp = NULL;
@@ -4778,10 +4717,7 @@ f_type, uint8_t f_index, char *f_string)
/*Seek to field index */
for (i=0; i <= f_index; i++) {
fru_field_offset_tmp = fru_field_offset;
- if (fru_area != NULL) {
- free(fru_area);
- fru_area = NULL;
- }
+ free_n(&fru_area);
fru_area = (uint8_t *) get_fru_area_str(fru_data, &fru_field_offset);
}
@@ -4827,14 +4763,8 @@ f_type, uint8_t f_index, char *f_string)
}
ipmi_fru_set_field_string_out:
- if (fru_data != NULL) {
- free(fru_data);
- fru_data = NULL;
- }
- if (fru_area != NULL) {
- free(fru_area);
- fru_area = NULL;
- }
+ free_n(&fru_data);
+ free_n(&fru_area);
return rc;
}
@@ -4956,10 +4886,7 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId,
3) Seek to field index */
for (i = 0;i <= f_index; i++) {
fru_field_offset_tmp = fru_field_offset;
- if (fru_area != NULL) {
- free(fru_area);
- fru_area = NULL;
- }
+ free_n(&fru_area);
fru_area = (uint8_t *) get_fru_area_str(fru_data_old, &fru_field_offset);
}
@@ -5191,18 +5118,9 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId,
printf("Done.\n");
ipmi_fru_set_field_string_rebuild_out:
- if (fru_area != NULL) {
- free(fru_area);
- fru_area = NULL;
- }
- if (fru_data_new != NULL) {
- free(fru_data_new);
- fru_data_new = NULL;
- }
- if (fru_data_old != NULL) {
- free(fru_data_old);
- fru_data_old = NULL;
- }
+ free_n(&fru_area);
+ free_n(&fru_data_new);
+ free_n(&fru_data_old);
return rc;
}
--
2.19.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-oepkgs-oe-rv/ipmitool.git
git@gitee.com:src-oepkgs-oe-rv/ipmitool.git
src-oepkgs-oe-rv
ipmitool
ipmitool
master

搜索帮助