From patchwork Mon Aug 26 16:11:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 143395 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 827FA4586E; Mon, 26 Aug 2024 18:12:29 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 13AB9400EF; Mon, 26 Aug 2024 18:12:29 +0200 (CEST) Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by mails.dpdk.org (Postfix) with ESMTP id D91B04003C for ; Mon, 26 Aug 2024 18:12:27 +0200 (CEST) Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-20230059241so35944695ad.3 for ; Mon, 26 Aug 2024 09:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1724688747; x=1725293547; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d9KFe2vVv2m1L6wAOBbSUCyXlpL2MDiFAttiakYVrCs=; b=n65E+ZU4TQiW8S30C8/3jNmDBrOwVtt+EhbHUPlRdkbXEnMHJTAShdXxdB4VXyT4BE WuMYVX2frBfl3wjCIJ+icCdqmobfnQh6VlJDI61CQe5tqI32EZ6NruM48jPlpMc6gvZy wl7JrUhNkW/U++etek5gAI1mqLKpvKqK2eT0O+VW1cChE79R8h2h71XI747DNbYw95DG j6PINUDqtl6yiRJnI/uvMSdf/RSsOHw8t5zym8RlHLPCb6jM6wGHjO+eBNBuk89nHF7E 2eD2FPH4cFugmuzI0/2m7EYwtDVizM09e4tbuYrCHnwcVqEcljVWxnJ1yo1MYFukoamN 7T5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724688747; x=1725293547; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d9KFe2vVv2m1L6wAOBbSUCyXlpL2MDiFAttiakYVrCs=; b=RkO6qntIsYc6T1nK4aPhxXLNwaNtAz5ViLaDV4I4LSIdt/7Twsw1F736C/6tDvBoWp PkZ2Av9IWJ/MhYoCi6+svGE/NYVD9vnYtDFDWZkAvAfoKhFNlsSDVKvyLFSpprYGJm0d 9Jwd3T+uQDJZxOtf2BEI0rolXdnXPzRREFOiEYznLkLa5FyTZhvDV1aEqVJuKHNg2+gz KCo3oPIZhamTpJKHVCGxrzKjv0KFGUHC1T5+5IzsZ7ZEqRHLscqmbObrzv9HFCEKTi3+ ADuVI/b9VgctbdT6c1ANCjh5lJanQlGq+n5ETtZtbCUjCF+duUgw3RCi4ukYb71d2KfJ eD9g== X-Gm-Message-State: AOJu0YwWJe92Dn/CDqO6nHV649uisW4A70KyIOKz7folPl1nTdEPoXfs EPBul4b8E546pfWYb1zgm/a8sTIXE1WOansMFhYakw+8tFhBV9oEcNoXVzN6hcAvWa8vfNBUBzq eznw+bA== X-Google-Smtp-Source: AGHT+IGNRdnGbEBvGYwZti+mjXb7VADi2kgOf2a6PgZIDg+yrOi9GCIav1+6vq2lzHPcfoqM8dTGuQ== X-Received: by 2002:a17:903:41ca:b0:202:ac8:991f with SMTP id d9443c01a7336-2039e48b9a9mr103915215ad.26.1724688746821; Mon, 26 Aug 2024 09:12:26 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2038557e6eesm69218115ad.73.2024.08.26.09.12.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 09:12:26 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Sachin Saxena , Hemant Agrawal , Sachin Saxena Subject: [PATCH v3] bus/fslmc/dpaa2: replace system("echo ...") with file i/o Date: Mon, 26 Aug 2024 09:11:13 -0700 Message-ID: <20240826161216.10135-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20220602214957.150071-1-stephen@networkplumber.org> References: <20220602214957.150071-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 Reviewed-by: Sachin Saxena --- 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(-) 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)