[v3] bus/fslmc/dpaa2: replace system("echo ...") with file i/o

Message ID 20240826161216.10135-1-stephen@networkplumber.org (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series [v3] bus/fslmc/dpaa2: replace system("echo ...") with file i/o |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS

Commit Message

Stephen Hemminger Aug. 26, 2024, 4:11 p.m. UTC
Using system() is a bad idea in driver code because it introduces
a number of potential security issues. The codeql analysis tool
flags this a potential security issue.

Instead just use normal stdio to do the same thing.

Compile test only, do not have this hardware and therefore can
not test this.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Reviewed-by: Sachin Saxena <sachin.saxena@oss.nxp.com>
---
v3 - remove unneccessary pre-allocation of the line buffer

 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 32 +++++++++++++++---------
 1 file changed, 20 insertions(+), 12 deletions(-)
  

Patch

diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
index 4aec7b2cd8..d8a98326d9 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
@@ -125,12 +125,12 @@  static void
 dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id)
 {
 #define STRING_LEN	28
-#define COMMAND_LEN	50
+#define AFFINITY_LEN	128
 	uint32_t cpu_mask = 1;
-	int ret;
 	size_t len = 0;
 	char *temp = NULL, *token = NULL;
-	char string[STRING_LEN], command[COMMAND_LEN];
+	char string[STRING_LEN];
+	char smp_affinity[AFFINITY_LEN];
 	FILE *file;
 
 	snprintf(string, STRING_LEN, "dpio.%d", dpio_id);
@@ -155,17 +155,25 @@  dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id)
 	}
 
 	cpu_mask = cpu_mask << cpu_id;
-	snprintf(command, COMMAND_LEN, "echo %X > /proc/irq/%s/smp_affinity",
-		 cpu_mask, token);
-	ret = system(command);
-	if (ret < 0)
-		DPAA2_BUS_DEBUG(
-			"Failed to affine interrupts on respective core");
-	else
-		DPAA2_BUS_DEBUG(" %s command is executed", command);
-
+	snprintf(smp_affinity, AFFINITY_LEN, "/proc/irq/%s/smp_affinity", token);
 	free(temp);
 	fclose(file);
+
+	file = fopen(smp_affinity, "w");
+	if (file == NULL) {
+		DPAA2_BUS_WARN("Failed to open %s", smp_affinity);
+		return;
+	}
+	fprintf(file, "%X\n", cpu_mask);
+	fflush(file);
+
+	if (ferror(file)) {
+		fclose(file);
+		DPAA2_BUS_WARN("Failed to write to %s", smp_affinity);
+		return;
+	}
+
+	fclose(file);
 }
 
 static int dpaa2_dpio_intr_init(struct dpaa2_dpio_dev *dpio_dev)