From 0a53156f7281337ac037ea334f7011b54a6f5655 Mon Sep 17 00:00:00 2001
From: Peiyang Wang <wangpeiyang1@huawei.com>
Date: Tue, 20 Aug 2024 16:33:35 +0800
Subject: [PATCH 11/27] hikptool: nic: return real errno if realpath failed in
 NIC module

Return real errno if realpath failed.

Signed-off-by: Peiyang Wang <wangpeiyang1@huawei.com>
---
 net/hikp_net_lib.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/hikp_net_lib.c b/net/hikp_net_lib.c
index 8db4ad5..32b278b 100644
--- a/net/hikp_net_lib.c
+++ b/net/hikp_net_lib.c
@@ -25,7 +25,7 @@
 
 static int hikp_read_net_pci_info(const char *file_path, char *content, size_t len)
 {
-	char path[PATH_MAX + 1] = { 0 };
+	char path[PATH_MAX] = { 0 }; /* PATH_MAX includes the \0 so +1 is not required */
 	int ret;
 	int fd;
 
@@ -35,9 +35,12 @@ static int hikp_read_net_pci_info(const char *file_path, char *content, size_t l
 	if (len > MAX_PCI_ID_LEN + 1 || len < 1)
 		return -EINVAL;
 
-	if (strlen(file_path) > PATH_MAX || realpath(file_path, path) == NULL)
+	if (strlen(file_path) > PATH_MAX)
 		return -ENOENT;
 
+	if (!realpath(file_path, path))
+		return -errno;
+
 	fd = open(path, O_RDONLY);
 	if (fd < 0)
 		return -EPERM;
-- 
2.45.0.windows.1

