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 3439245D0B; Fri, 15 Nov 2024 07:08:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0476A42F6B; Fri, 15 Nov 2024 07:07:56 +0100 (CET) Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by mails.dpdk.org (Postfix) with ESMTP id 2AE9442F65 for ; Fri, 15 Nov 2024 07:07:52 +0100 (CET) Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2ea09a033e2so341530a91.3 for ; Thu, 14 Nov 2024 22:07:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1731650871; x=1732255671; 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=mBv2iEvk6fFTypuJumFG5q7VhfNRQUyBuZZ1jXzqG1NkPuPEJ7O8rlIjEUsGbAe0Ln xuTgiwiBBKw5pBwhmski3t0LcyqM3wFRvmOEhoWZQ87Gqt2wL0fHRk6UH5N+SurB6+g8 jxQijHhP8mg1MOvwilXysC2rOfvAsWBEDHsjMHrr9t+MRKJnM8jd6LWSL3Wz0d4gbvVN o+wCX0CDajfiR4Wt9lHeudzqL1wn4Yz0lGv267U48VrHRHb9gnaOJYLyl2i24f6/zFZO 1bHDTch/Y4DesRUeK1cWXeE8dmqEt35O2GNIVhl/PeYIswLy3FPc9k667xgbzGJLJtpU QLlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731650871; x=1732255671; 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=DTM4ouA57LtJDehaJ1KTwgrVDq+4Trhju9G4yAsz65coVJVv3DOM6BBWf7NP6gB9He cuYLSBD0Hhi068Mx93zfrOlrst7kLP+uMX2Z9yHcTAqn3XLo68Bqt2grM4OqwsvI1cjY 2YMewZC+at0rgfASabftp8xgvGp0A1/ySIZGmPzd6shmWeu2VaJsF8+f+TmjsbDeaRAe IPST6OYgYHcD2HwqrBvxUU8hlzlDPIvTzVmcxfuyFgDOpGizsIkGbLnz6SV2oq/v24gE F1NVMH7Bq8H8J1UqFNgjO1SmSWAdFX2N4R/k4+UxVkw0q2XfzgZEpSI44VLqPWAaXWoJ CIdg== X-Gm-Message-State: AOJu0YygXlWhED6lO3EOSzse6nlXS9J2fQF69sNqMtOcEpk27/xgaQtU 2LClylwtF8yllKdz4rDBNTFokqnfSsXpM7dn3MJLoXeTu9bpt3AoLuC2eeZ0p6uboA1o27tJ0VP y X-Google-Smtp-Source: AGHT+IHAfzx6DunAKum7gS+uZoV9d9hTZkFte4uLWvphmCNlFQiVfBQS4hwa9MI030kMPBFOLnnQ3g== X-Received: by 2002:a17:90b:1b45:b0:2e5:632e:68ee with SMTP id 98e67ed59e1d1-2ea1551e430mr1970679a91.19.1731650871270; Thu, 14 Nov 2024 22:07:51 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ea06f4856esm2123781a91.23.2024.11.14.22.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 22:07:50 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , tduszynski@marvell.com, Jakub Palider Subject: [PATCH 03/16] raw/cnxk_gpio: fix file descriptor leak Date: Thu, 14 Nov 2024 22:05:40 -0800 Message-ID: <20241115060738.313190-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241115060738.313190-1-stephen@networkplumber.org> References: <20241115060738.313190-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