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 0F71845CD8; Mon, 18 Nov 2024 19:22:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7BB20427AD; Mon, 18 Nov 2024 19:22:09 +0100 (CET) Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by mails.dpdk.org (Postfix) with ESMTP id 243924275D for ; Mon, 18 Nov 2024 19:22:06 +0100 (CET) Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2e2ed59a35eso14683a91.0 for ; Mon, 18 Nov 2024 10:22:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1731954125; x=1732558925; 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=idB4WP6eU3pG8m61AUoPHHPpuoFq5WkYc8/o2rRSQvA=; b=U5JdzLkLROgZZSN3i+k3j6tKktTmPv7Bd76BB58KPY2sRXcFLs8gCw6WJYu9Ib/+3j O/RUYq9H3/xQ4aZD56kkhDd9OYTGbVfwRcCp9CJ+nlgV2mrbsuRP4I6U/ZRsA7SVcUmD Y8KZlWPN6blbJpgw9gC6VSXbmrRj/msn2AYXNSk9gDERsMJvVd9ke0d71JkZx2fJ0Ozk ojVN9l5HPtEYjNVC3NM0na7gV7gD35XCPurpx8l2H6W+mhqSQlRw7AGhGnrPykWX69rm JJp3c4k5/rNM26bnXw6IiynvJRszQZAtaKs9gNJIrNywg3Q59XcceSp3VCfJnTyrb1wd SROg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731954125; x=1732558925; 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=idB4WP6eU3pG8m61AUoPHHPpuoFq5WkYc8/o2rRSQvA=; b=NdnIr/BnAiIlqXEFMGwvlTlxSVRIK0XtcK4l3Jt6IedglzvL6VmsfqwzIJQ9NeUuio G2+hfezej2GaUhX5ZIC8aCGIZfunULFc2lAR+G0v0ga8h6d7D28/LcCRTZa4/KDW4F4d axX58CMoe+6YOUO4NWMH3p+YLcBZeu+PtzG5+eqCeIUqHNs2727MUYQekIwJmMsfyfxl jxE+H0WhDU7Uiz7iSz/BqEBV0NHbg2PqfhUPTh25ktyvUEpjRdBGE3EJV5aIw9/vvFGN x11MUovwtwfVMFxP2JTqDoIrY/qfG6Q28l7fbDo88bGcbDUZd+DxLhaJKxsLJSis457f XTXw== X-Gm-Message-State: AOJu0YxF2xYQUfnhUMEIU9HYxdBmJBrAdKdbVbPfApWBXQd8BBAycdxI ZtnblOgb+7pMFdEYEIYeqipMtkjJBPNKMhfAyBSamyBo5Lxh+6lbavY5u8CeCds2n2sq9wEo0bo u X-Google-Smtp-Source: AGHT+IGR4/suYp3pL8JL9RBORmNg2aZoVqIET0POrojiH9It0/CocPke0E2XzvUHbazZOG0sZqmnZA== X-Received: by 2002:a17:90b:4d07:b0:2e2:a6ef:d7a6 with SMTP id 98e67ed59e1d1-2ea155b1b54mr13801811a91.36.1731954125311; Mon, 18 Nov 2024 10:22:05 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ea61869bb2sm2916724a91.12.2024.11.18.10.22.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2024 10:22:04 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , tduszynski@marvell.com Subject: [PATCH v2 03/19] raw/cnxk_gpio: fix file descriptor leak Date: Mon, 18 Nov 2024 10:20:44 -0800 Message-ID: <20241118182153.87042-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241118182153.87042-1-stephen@networkplumber.org> References: <20241115060738.313190-1-stephen@networkplumber.org> <20241118182153.87042-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 The function would leak file if fscanf failed. There is a working version in other file, clone that. Link: https://pvs-studio.com/en/blog/posts/cpp/1183/ Fixes: 0e6557b448fa ("raw/cnxk_gpio: add self test") Cc: tduszynski@marvell.com Signed-off-by: Stephen Hemminger --- drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c b/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c index 2f3973a7b5..a0d9942f20 100644 --- a/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c +++ b/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c @@ -34,24 +34,30 @@ cnxk_gpio_attr_exists(const char *attr) static int cnxk_gpio_read_attr(char *attr, char *val) { + int ret, ret2; FILE *fp; - int ret; fp = fopen(attr, "r"); if (!fp) return -errno; ret = fscanf(fp, "%s", val); - if (ret < 0) - return -errno; - if (ret != 1) - return -EIO; + if (ret < 0) { + ret = -errno; + goto out; + } + if (ret != 1) { + ret = -EIO; + goto out; + } - ret = fclose(fp); - if (ret) - return -errno; + ret = 0; +out: + ret2 = fclose(fp); + if (!ret) + ret = ret2; - return 0; + return ret; } #define CNXK_GPIO_ERR_STR(err, str, ...) do { \ -- 2.45.2