Skip to contentSkip to conversation

Avoid using perror

PATCH In review Stephen Hemminger 3 participants 7 messages Dec 28, 2025 – Feb 3

lore
Share & tools
lore
#0 lore raw

cover Avoid using perror

The DPDK uses its own logging library exclusively and drivers and libraries should not be printing directly. One function that was missed was perror() and some code was using it.

This series adds a checkpatch warning and fixes the places that were using it.

Stephen Hemminger (4):
checkpatches: warn if perror is used
bus/dpaa: replace perror with log
telemetry: replace perror with log
common/dpaax: replace use of perror with log

 devtools/checkpatches.sh              | 2 +-
 drivers/bus/dpaa/base/qbman/process.c | 8 ++++----
 drivers/common/dpaax/dpaa_of.c        | 2 +-
 lib/telemetry/telemetry.c             | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/4 checkpatches: warn if perror is used

The function perror is another way to print to stderr, which should be discouraged in drivers and libraries.

---
 devtools/checkpatches.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
devtools/checkpatches.sh +1 -1
index 9a8199659f..1c6099ac82 100755
@@ -73,7 +73,7 @@ check_forbidden_additions() { # <patch>
 
 	# no output on stdout or stderr
 	awk -v FOLDERS="lib drivers" \
-		-v EXPRESSIONS="\\\<printf\\\> \\\<fprintf\\\(stdout, \\\<fprintf\\\(stderr," \
+		-v EXPRESSIONS="perror\\\( \\\<printf\\\> \\\<fprintf\\\(stdout, \\\<fprintf\\\(stderr," \
 		-v RET_ON_FAIL=1 \
 		-v MESSAGE='Writing to stdout or stderr' \
 		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
Signature · 1 line
2.51.0
#2 lore raw

PATCH 2/4 bus/dpaa: replace perror with log

In reply to Stephen Hemminger

Use existing logging instead of calling perror.

---
 drivers/bus/dpaa/base/qbman/process.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/bus/dpaa/base/qbman/process.c +4 -4
index 2d805c5bd9..77362cd6e5 100644
@@ -142,7 +142,7 @@ int process_portal_map(struct dpaa_ioctl_portal_map *params)
 
 	ret = ioctl(fd, DPAA_IOCTL_PORTAL_MAP, params);
 	if (ret) {
-		perror("ioctl(DPAA_IOCTL_PORTAL_MAP)");
+		DPAA_BUS_ERR("Failed ioctl DPAA_IOCTL_PORTAL_MAP: %s", strerror(errno));
 		return ret;
 	}
 	return 0;
@@ -157,7 +157,7 @@ int process_portal_unmap(struct dpaa_portal_map *map)
 
 	ret = ioctl(fd, DPAA_IOCTL_PORTAL_UNMAP, map);
 	if (ret) {
-		perror("ioctl(DPAA_IOCTL_PORTAL_UNMAP)");
+		DPAA_BUS_ERR("Failed ioctl DPAA_IOCTL_PORTAL_UNMAP: %s", strerror(errno));
 		return ret;
 	}
 	return 0;
@@ -215,7 +215,7 @@ static int process_portal_allocate(struct dpaa_ioctl_raw_portal *portal)
 
 	ret = ioctl(fd, DPAA_IOCTL_ALLOC_RAW_PORTAL, portal);
 	if (ret) {
-		perror("ioctl(DPAA_IOCTL_ALLOC_RAW_PORTAL)");
+		DPAA_BUS_ERR("Failed ioctl DPAA_IOCTL_ALLOC_RAW_PORTAL: %s", strerror(errno));
 		return ret;
 	}
 	return 0;
@@ -230,7 +230,7 @@ static int process_portal_free(struct dpaa_ioctl_raw_portal *portal)
 
 	ret = ioctl(fd, DPAA_IOCTL_FREE_RAW_PORTAL, portal);
 	if (ret) {
-		perror("ioctl(DPAA_IOCTL_FREE_RAW_PORTAL)");
+		DPAA_BUS_ERR("Failed ioctl DPAA_IOCTL_FREE_RAW_PORTAL: %s", strerror(errno));
 		return ret;
 	}
 	return 0;
Signature · 1 line
2.51.0
#3 lore raw

PATCH 3/4 telemetry: replace perror with log

In reply to Stephen Hemminger

Use logging instead of print to stderr.

---
 lib/telemetry/telemetry.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/telemetry/telemetry.c +2 -2
index cf4324421d..b109d076d4 100644
@@ -365,7 +365,7 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s)
 	used += prefix_used;
 	used += strlcat(out_buf + used, "}", sizeof(out_buf) - used);
 	if (write(s, out_buf, used) < 0)
-		perror("Error writing to socket");
+		TMTY_LOG_LINE(ERR, "Error writing to socket: %s", strerror(errno));
 }
 
 static void
@@ -384,7 +384,7 @@ perform_command(const struct cmd_callback *cb, const char *cmd, const char *para
 		int used = snprintf(out_buf, sizeof(out_buf), "{\"%.*s\":null}",
 				MAX_CMD_LEN, cmd ? cmd : "none");
 		if (write(s, out_buf, used) < 0)
-			perror("Error writing to socket");
+			TMTY_LOG_LINE(ERR, "Error writing to socket: %s", strerror(errno));
 		return;
 	}
 	output_json(cmd, &data, s);
Signature · 1 line
2.51.0
#5 lore raw

PATCH 4/4 common/dpaax: replace use of perror with log

In reply to Stephen Hemminger

Use log functions instead of perror.

---
 drivers/common/dpaax/dpaa_of.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/common/dpaax/dpaa_of.c +1 -1
index 23035f530d..d44c893bb4 100644
@@ -117,7 +117,7 @@ iterate_dir(struct dirent **d, int num, struct dt_dir *dt)
 		case DT_DIR:
 			subdir = malloc(sizeof(*subdir));
 			if (!subdir) {
-				perror("malloc");
+				DPAAX_LOG(ERR, "malloc failed");
 				return -ENOMEM;
 			}
 			strlcpy(subdir->node.node.name, d[loop]->d_name,
Signature · 1 line
2.51.0
#6 lore raw
In reply to Stephen Hemminger
Quoted 14 lines · Stephen Hemminger

The DPDK uses its own logging library exclusively and drivers and libraries should not be printing directly. One function that was missed was perror() and some code was using it.

This series adds a checkpatch warning and fixes the places that were using it.

Stephen Hemminger (4):
checkpatches: warn if perror is used
bus/dpaa: replace perror with log
telemetry: replace perror with log
common/dpaax: replace use of perror with log

Quoted 5 lines
 devtools/checkpatches.sh              | 2 +-
 drivers/bus/dpaa/base/qbman/process.c | 8 ++++----
 drivers/common/dpaax/dpaa_of.c        | 2 +-
 lib/telemetry/telemetry.c             | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

Series applied, thanks.

Signature · 1 line
David Marchand