Avoid using perror
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
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
@@ -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
PATCH 2/4 bus/dpaa: replace perror with log
In reply to Stephen HemmingerUse 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
@@ -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
PATCH 3/4 telemetry: replace perror with log
In reply to Stephen HemmingerUse logging instead of print to stderr.
--- lib/telemetry/telemetry.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/telemetry/telemetry.c +2 -2
@@ -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 *paraint 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
Re: [PATCH 3/4] telemetry: replace perror with log
Quoted 7 lines · Stephen Hemminger
Use logging instead of print to stderr.
Signed-off-by Stephen Hemminger <[email protected]>--- lib/telemetry/telemetry.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
PATCH 4/4 common/dpaax: replace use of perror with log
In reply to Stephen HemmingerUse 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
@@ -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
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