DPDK patches and discussions
 help / color / mirror / Atom feed
* [RFC] dpaa2: replace system("echo ...") with file i/o
@ 2022-06-02 21:49 Stephen Hemminger
  2023-05-02  9:54 ` [v2] " Sachin Saxena (OSS)
  2024-08-26 16:11 ` [PATCH v3] bus/fslmc/dpaa2: " Stephen Hemminger
  0 siblings, 2 replies; 5+ messages in thread
From: Stephen Hemminger @ 2022-06-02 21:49 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Hemant Agrawal, Sachin Saxena

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>
---
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 33 +++++++++++++++---------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
index 22c51c1a82cc..894871aec19e 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);
@@ -153,18 +153,27 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id)
 		fclose(file);
 		return;
 	}
+	free(temp);
+	fclose(file);
 
+	snprintf(smp_affinity, AFFINITY_LEN,
+		 "/proc/irq/%s/smp_affinity", token);
 	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);
 
-	free(temp);
+	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);
 }
 
-- 
2.35.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-17 16:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02 21:49 [RFC] dpaa2: replace system("echo ...") with file i/o Stephen Hemminger
2023-05-02  9:54 ` [v2] " Sachin Saxena (OSS)
2023-05-04  7:36   ` Mattias Rönnblom
2024-08-26 16:11 ` [PATCH v3] bus/fslmc/dpaa2: " Stephen Hemminger
2024-10-17 16:15   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).