Skip to contentSkip to conversation

perf config: Check error cases of {show_spec, set}_config()

PATCH Applied Taeung Song 3 participants 3 messages Jun 17, 2017 – Jun 20, 2017 perf events

v4 of 5 Applied Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/5 perf config: Check error cases of {show_spec, set}_config()

show_spec_config() and set_config() can be called multiple times in the loop in cmd_config().
However, The error cases of them wasn't checked, so fix it.

---
 tools/perf/builtin-config.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tools/perf/builtin-config.c +15 -2
index 7545966..bb1be79 100644
@@ -225,10 +225,23 @@ int cmd_config(int argc, const char **argv)
 				break;
 			}
 
-			if (value == NULL)
+			if (value == NULL) {
 				ret = show_spec_config(set, var);
-			else
+				if (ret < 0) {
+					pr_err("%s is not configured: %s\n",
+					       var, config_filename);
+					free(arg);
+					break;
+				}
+			} else {
 				ret = set_config(set, config_filename, var, value);
+				if (ret < 0) {
+					pr_err("Failed to set '%s=%s' on %s\n",
+					       var, value, config_filename);
+					free(arg);
+					break;
+				}
+			}
 			free(arg);
 		}
 	}
Signature · 1 line
2.7.4
maintainer Applied
#1 lore raw

Em Sat, Jun 17, 2017 at 12:46:37PM +0900, Taeung Song escreveu:

Quoted 3 lines

show_spec_config() and set_config() can be called multiple times in the loop in cmd_config().
However, The error cases of them wasn't checked, so fix it.

Thanks, applied.

Quoted 40 lines
---
 tools/perf/builtin-config.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tools/perf/builtin-config.c +15 -2
index 7545966..bb1be79 100644
@@ -225,10 +225,23 @@ int cmd_config(int argc, const char **argv)
 				break;
 			}
 
-			if (value == NULL)
+			if (value == NULL) {
 				ret = show_spec_config(set, var);
-			else
+				if (ret < 0) {
+					pr_err("%s is not configured: %s\n",
+					       var, config_filename);
+					free(arg);
+					break;
+				}
+			} else {
 				ret = set_config(set, config_filename, var, value);
+				if (ret < 0) {
+					pr_err("Failed to set '%s=%s' on %s\n",
+					       var, value, config_filename);
+					free(arg);
+					break;
+				}
+			}
 			free(arg);
 		}
 	}
Signature · 1 line
2.7.4
#2 lore raw
In reply to Taeung Song
perf config: Check error cases of {show_spec, set}_config()
Commit-ID:  4f1fd74283582f3f5c34d1c9ed55117d775b4a20
Gitweb:     http://git.kernel.org/tip/4f1fd74283582f3f5c34d1c9ed55117d775b4a20
Author:     Taeung Song <[email protected]>
AuthorDate: Sat, 17 Jun 2017 12:46:37 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 19 Jun 2017 22:05:54 -0300

perf config: Check error cases of {show_spec, set}_config()

show_spec_config() and set_config() can be called multiple times in the loop in cmd_config().

However, The error cases of them wasn't checked, so fix it.

---
 tools/perf/builtin-config.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tools/perf/builtin-config.c +15 -2
index 7545966..bb1be79 100644
@@ -225,10 +225,23 @@ int cmd_config(int argc, const char **argv)
 				break;
 			}
 
-			if (value == NULL)
+			if (value == NULL) {
 				ret = show_spec_config(set, var);
-			else
+				if (ret < 0) {
+					pr_err("%s is not configured: %s\n",
+					       var, config_filename);
+					free(arg);
+					break;
+				}
+			} else {
 				ret = set_config(set, config_filename, var, value);
+				if (ret < 0) {
+					pr_err("Failed to set '%s=%s' on %s\n",
+					       var, value, config_filename);
+					free(arg);
+					break;
+				}
+			}
 			free(arg);
 		}
 	}