From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6678642A3D; Tue, 2 May 2023 11:54:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EB59B40E2D; Tue, 2 May 2023 11:54:33 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2086.outbound.protection.outlook.com [40.107.21.86]) by mails.dpdk.org (Postfix) with ESMTP id B8958406A2 for ; Tue, 2 May 2023 11:54:32 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NS4pwmwbkMVWf0oP14gY76UFHllXLw7XVciNMMhQib2/ZJZw6g72s9QOW0LX89xbdb/e1jb1hFCgTP7PQevd1gVUDMVHubCJi56XTcPmQ9/7GIRLTmer1ON0/q7CppWpRiw3rT53183b2ZzZYCflLN84lctm0Ek4BFmBydhv7njgiM2eBaOycno4jt1j6NfS6WxZxaEc6ffkb0xuNqY0K1lJl4LsjcTI5rm3uAEWcN1Wd17/cPxb7MXRJ5hJ9altlkT+kc1azjBHm1OkimM+dv8gA+tOVODYgX3c95JiEOhrSpo6mZ1Ki/6NPcc/8/HeyT5F3OiZ69QuggdcMckQgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kR5nk+uzvG6R38EWpaUJ3zAtgpixvZ0sFVhQz4Mmab0=; b=GZSZWYbX4Zkc5uW6n2aUcAk6iWpsYnJhGIvwUj0GIOXCStxHP5UjzLSAMh5fNiOaNXLiOBVoGI6kXU9XcGhJURqJzSPxwyDYxqYui+qu1MzhppcS/SJKtbBxNfoe849SW7PWZMcyBFBi9DYnmSH+TDcbFngrylHD234d4AD2Kt7tfr51H9VOyHhG1+qPe7c0Wu0ls+je3hH1BZks8cAzMcBxk8aLQzL8RDjU95lS1LYLTdKwH5vhslcSq0QGZ7wbCvbE+1J20eepAejT1QhgDM/a1GU2aXKKPFhmD3DHFvHzuRa1pTHxEbA+CwdAMaOe0cChfRZIHgFjAAFdUDkVEA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kR5nk+uzvG6R38EWpaUJ3zAtgpixvZ0sFVhQz4Mmab0=; b=ghi2Ny1F1qvyGjrFlLhwCY3etJnQSZrC0buGvSJLUMD5IMKpFGbZw4MiiaYMEZJGsz3cB3432gOlhfqtqZbwswe1bjSgD0EkvaolRJQkdhYKYQQ90LFjZNUi//7FmnD2wYa+8CBzIoCDpGkivvngrvz/JNY1MrHomKiHVUDqMcw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AS8PR04MB8562.eurprd04.prod.outlook.com (2603:10a6:20b:421::9) by VE1PR04MB7327.eurprd04.prod.outlook.com (2603:10a6:800:1ac::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Tue, 2 May 2023 09:54:29 +0000 Received: from AS8PR04MB8562.eurprd04.prod.outlook.com ([fe80::5787:8cca:9d7e:956c]) by AS8PR04MB8562.eurprd04.prod.outlook.com ([fe80::5787:8cca:9d7e:956c%5]) with mapi id 15.20.6340.029; Tue, 2 May 2023 09:54:29 +0000 From: "Sachin Saxena (OSS)" To: dev@dpdk.org, stephen@networkplumber.org Cc: Sachin Saxena Subject: [v2] [RFC] dpaa2: replace system("echo ...") with file i/o Date: Tue, 2 May 2023 15:24:10 +0530 Message-Id: <20230502095410.487696-1-sachin.saxena@oss.nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602214957.150071-1-stephen@networkplumber.org> References: <20220602214957.150071-1-stephen@networkplumber.org> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SG2P153CA0014.APCP153.PROD.OUTLOOK.COM (2603:1096::24) To AS8PR04MB8562.eurprd04.prod.outlook.com (2603:10a6:20b:421::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8562:EE_|VE1PR04MB7327:EE_ X-MS-Office365-Filtering-Correlation-Id: 63d990fe-b7ad-42ef-d0de-08db4af33874 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yALOn3fY2WJf4ad0CshUtfK17nEJ66pDRJ59gi6clECMIsoap/gwZiBBxjcDmiO7ylRN7DQInbr2WsmItUAb+2wot+vnNNFEGX8DUsuSAMtYuhJh3YdXkHSvz230ko3nXYUax1Nyv2yNiIvYm/DEzG8NtGoK4xqYmsIMxDkMCfmY6p73ZrE/l53yVLauGqAaO/F99h4uIcejTPmr06RXDjMzpkfQ7azoniqSPcuIUzFoDd5sn0bYRriHoWI5nfMhsp50r3x6xRx1m6gt5e1bCa0nLrT+1oDLkvHYNScV0jwLl2+TtCnlBe0QFFL3fpCVLcnDWGGyMmV5H2n6xr/oJwJo0XkGZXPA1ye3X+FFdDrh5qY0irUPMJY56haV3R4BfIMuUnoMYDw2niiEiRkANYGwiKB3e0wpX+q7sQb/1j0geuFsNbCYZ+aWCoUxPWVpVhRJdjnoF7P7D75iJNL7LUwO9VzwnvL1ViqpS2Kzk4yaT4nCzLXms4fgWKPD24bveE7WWP2/OWChGCU/w+FGS0/XBFUcAE0+8j4bbrVPYuZ+USApRk9pTErTnETg/ktpJY6XQvnWfowJzcRJXHnBacfqBXvpFEjnVBYMHXdvdsjM8p+hMs5hvkFG3d/f7KEk X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB8562.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(366004)(396003)(376002)(39860400002)(136003)(346002)(451199021)(2616005)(6666004)(52116002)(6486002)(6512007)(26005)(6506007)(1076003)(186003)(86362001)(5660300002)(83380400001)(8676002)(8936002)(38100700002)(2906002)(478600001)(38350700002)(66556008)(66476007)(66946007)(41300700001)(4326008)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?zwVp3+O9+YD7nJ3RvT0buxEKAt6vYB+ZV16na7cG0zNbmEde66TL/rKR/l1e?= =?us-ascii?Q?eJn8VcuSf/dfNArBZGKrB6u6qtZtYG8GhcVnJEgjGU6ktZ4jYzsftsTHJexR?= =?us-ascii?Q?9aHZrIslNX/fM16uB3QhglDm5V6XglqB2mQCdy7pvfT2AsT2cQ3J3y8pKAQh?= =?us-ascii?Q?rX1zie7SAqavMXJKi4QLJm/f+hxJD2gN5mg6imyyHAIf5ePzn8bz7cKxK3H4?= =?us-ascii?Q?xwtPCVrBtONJBonYsIBCNWpQvPvfL6LV8ioS6j+7g0kQ4FMmwODRLK2Po7Wy?= =?us-ascii?Q?48WGsjg7ECdB97U97lTuDPPKmFATbKx4dXiD7IqB68bPcS9ivz6D8pL/R1bZ?= =?us-ascii?Q?fTKWvO0PZlB+wyLnQcdu1THgKG3JYjyNu31JwW/7LwLP8tDAyXefn9BVIlhr?= =?us-ascii?Q?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WHOL7mh+UC+X?= =?us-ascii?Q?c5cfKw86L1ZRFWEq/fl7V5WtqCROWQUKKiSBknFo0C+BqY4y61wMcGcA6EaZ?= =?us-ascii?Q?VMovdsBXG3YsG1xwflcQj5QjBxVEydza/7rdDVFua3LGgrmiAg4bzvdCF+2F?= =?us-ascii?Q?WCrkzNj0uBVDNkFt7+hHv00rY4CCR9lvFPLKzLB0YvBSuUK8othbd98A/cVK?= =?us-ascii?Q?oZ6rIyd/cy3i2tjiLQAnlFnHfUeqE7JF9e6UUUFuyUnVF89QV9TDO1BsC9ok?= =?us-ascii?Q?2EGLkeG8zRjklEQFbofHEszI62xV29TbSs7OfQr9rdErM8dHz4PeoJuuqK4t?= =?us-ascii?Q?1A=3D=3D?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63d990fe-b7ad-42ef-d0de-08db4af33874 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8562.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 09:54:29.2679 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: f6ufWzHF44bczuhJzh1elkBSD2ziCf8j7V/EuKKZ+XcKPh71n3HYdvjT4gwLE8g2xV+tUR/iWFXST2GRpgqRng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7327 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 From: Stephen Hemminger 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 --- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 45 ++++++++++++++++-------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c index 4aec7b2cd8..990cfc5d3b 100644 --- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c @@ -125,14 +125,21 @@ 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 +#define CMD_LEN 300 uint32_t cpu_mask = 1; - int ret; - size_t len = 0; - char *temp = NULL, *token = NULL; - char string[STRING_LEN], command[COMMAND_LEN]; + size_t len = CMD_LEN; + char *temp, *token = NULL; + char string[STRING_LEN]; + char smp_affinity[AFFINITY_LEN]; FILE *file; + temp = (char *)malloc(len * sizeof(char)); + if (temp == NULL) { + DPAA2_BUS_WARN("Unable to allocate temp buffer"); + return; + } + snprintf(string, STRING_LEN, "dpio.%d", dpio_id); file = fopen("/proc/interrupts", "r"); if (!file) { @@ -155,17 +162,27 @@ 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' memory after using the substring '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) -- 2.25.1