From patchwork Thu Jun 2 21:49:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 112282 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 DE274A0548; Thu, 2 Jun 2022 23:50:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8B61440691; Thu, 2 Jun 2022 23:50:03 +0200 (CEST) Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by mails.dpdk.org (Postfix) with ESMTP id 962DE4021E for ; Thu, 2 Jun 2022 23:50:02 +0200 (CEST) Received: by mail-pj1-f54.google.com with SMTP id d12-20020a17090abf8c00b001e2eb431ce4so5891053pjs.1 for ; Thu, 02 Jun 2022 14:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wwCm2fRueHUgdly/QYTEo2w2NTXNVEe+gpbOj3jZH7U=; b=HlaN9tI3kBUHmNnHrIXAwVKTsD81c7G/82kxcbWU86E0iTaehPJPzwXdjeb2qOBxUN 1rUW/MVDhmj4EXh4v1C/4qgf4d5QubCDbIi8AYxDUwqCygOQdqh789+4DchS1zARDxce LhzhHqCwrZ9AsxFJYaxMb68O/0EWiVF/tn1eVGeUpQtq56Htms9nWkII4wbSlNHwCHEW +7c4IiqNxCFiwMGKBrlzmUc+bAVp1p+gA7tTWLyx2AoZxd1FaI4GYe1hMtOyXGZI0Dy3 artVR4RzSAONmTJ0fW6kNDawQHlWuJiSuRok6cMlOuJsk8S9k/aPv/caN5VFV0dwGaCu i48g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wwCm2fRueHUgdly/QYTEo2w2NTXNVEe+gpbOj3jZH7U=; b=GTuqhDolLK4VDqEWuGY0BOStZwmTUry7AKzJbOdIPa0QRgDjPS0hWXPAPX4pscvRhu AqMhmjGdR9UKKInnjz4uK3zwn/0MrHcc1XF7p9BMbWl5Ws4U/rcJAaw1akpP03FG45Wl Ro2zlTjfnyUUpKbqC/IiCvox/mxeizf3iQNP8Txp4owwgFWzLl8ZXfMOvN4vTwzbeouA Sg/38INmF8H4YrzjTZFK8krD2gnbWjw0iDBfBDPnrc2PCNQwb6Qs/mYFLhWyFD8bl7Un sMv/EV3B70m/GJGAna2cHlEdxtWtJW0eigpaRn2DsMTvphIwuvNOKy8V+vuujlT7VnNf HRCQ== X-Gm-Message-State: AOAM532Zs6ONxY8TN3W+vnw6DVaOJ8dD6jUhU1Dx0kQLZ6JVcUkIMR8n mE1NcF8Qn8n+EE1h/3JbFG0H1+ldkyARkg== X-Google-Smtp-Source: ABdhPJyXv0Orp4W/hLwBo803vAe71SlLKOQcuEvdWFZ5WQRMLXi6Zz37mLItmx7nE2LNnahGjFdrmw== X-Received: by 2002:a17:902:bcc6:b0:15f:4990:baec with SMTP id o6-20020a170902bcc600b0015f4990baecmr6863071pls.102.1654206601313; Thu, 02 Jun 2022 14:50:01 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id m1-20020a17090a34c100b001e31c510f10sm6302449pjf.54.2022.06.02.14.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 14:50:00 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Hemant Agrawal , Sachin Saxena Subject: [RFC] dpaa2: replace system("echo ...") with file i/o Date: Thu, 2 Jun 2022 14:49:57 -0700 Message-Id: <20220602214957.150071-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 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 --- 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); }