DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>,
	stable@dpdk.org, Sunil Kumar Kori <skori@marvell.com>,
	Rakesh Kudurumalla <rkudurumalla@marvell.com>,
	Nithin Dabilpuram <ndabilpuram@marvell.com>,
	Jerin Jacob <jerinj@marvell.com>
Subject: [RFC PATCH v2 20/33] app/graph: fix build with shadow warnings enabled
Date: Fri,  7 Nov 2025 15:50:16 +0000	[thread overview]
Message-ID: <20251107155034.436809-21-bruce.richardson@intel.com> (raw)
In-Reply-To: <20251107155034.436809-1-bruce.richardson@intel.com>

The global variable "conn" conflicted with the local parameter to each
function in the graph conn.c file. To prevent shadowing, use "c" as the
name for the local connection variable throughout the file.

Fixes: 3f90eda5b7fb ("app/graph: add telnet connectivity")
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/graph/conn.c | 134 +++++++++++++++++++++++------------------------
 1 file changed, 67 insertions(+), 67 deletions(-)

diff --git a/app/graph/conn.c b/app/graph/conn.c
index 44934602c7..c5e1c1ae1b 100644
--- a/app/graph/conn.c
+++ b/app/graph/conn.c
@@ -20,12 +20,12 @@
 #define MSG_CMD_TOO_LONG "Command too long."
 
 static int
-data_event_handle(struct conn *conn, int fd_client)
+data_event_handle(struct conn *c, int fd_client)
 {
 	ssize_t len, i, rc = 0;
 
 	/* Read input message */
-	len = read(fd_client, conn->buf, conn->buf_size);
+	len = read(fd_client, c->buf, c->buf_size);
 	if (len == -1) {
 		if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
 			return 0;
@@ -38,37 +38,37 @@ data_event_handle(struct conn *conn, int fd_client)
 
 	/* Handle input messages */
 	for (i = 0; i < len; i++) {
-		if (conn->buf[i] == '\n') {
+		if (c->buf[i] == '\n') {
 			size_t n;
 
-			conn->msg_in[conn->msg_in_len] = 0;
-			conn->msg_out[0] = 0;
+			c->msg_in[c->msg_in_len] = 0;
+			c->msg_out[0] = 0;
 
-			conn->msg_handle(conn->msg_in, conn->msg_out, conn->msg_out_len_max,
-					 conn->msg_handle_arg);
+			c->msg_handle(c->msg_in, c->msg_out, c->msg_out_len_max,
+					 c->msg_handle_arg);
 
-			n = strlen(conn->msg_out);
+			n = strlen(c->msg_out);
 			if (n) {
-				rc = write(fd_client, conn->msg_out, n);
+				rc = write(fd_client, c->msg_out, n);
 				if (rc == -1)
 					goto exit;
 			}
 
-			conn->msg_in_len = 0;
-		} else if (conn->msg_in_len < conn->msg_in_len_max) {
-			conn->msg_in[conn->msg_in_len] = conn->buf[i];
-			conn->msg_in_len++;
+			c->msg_in_len = 0;
+		} else if (c->msg_in_len < c->msg_in_len_max) {
+			c->msg_in[c->msg_in_len] = c->buf[i];
+			c->msg_in_len++;
 		} else {
 			rc = write(fd_client, MSG_CMD_TOO_LONG, strlen(MSG_CMD_TOO_LONG));
 			if (rc == -1)
 				goto exit;
 
-			conn->msg_in_len = 0;
+			c->msg_in_len = 0;
 		}
 	}
 
 	/* Write prompt */
-	rc = write(fd_client, conn->prompt, strlen(conn->prompt));
+	rc = write(fd_client, c->prompt, strlen(c->prompt));
 	rc = (rc == -1) ? -1 : 0;
 
 exit:
@@ -76,11 +76,11 @@ data_event_handle(struct conn *conn, int fd_client)
 }
 
 static int
-control_event_handle(struct conn *conn, int fd_client)
+control_event_handle(struct conn *c, int fd_client)
 {
 	int rc;
 
-	rc = epoll_ctl(conn->fd_client_group, EPOLL_CTL_DEL, fd_client, NULL);
+	rc = epoll_ctl(c->fd_client_group, EPOLL_CTL_DEL, fd_client, NULL);
 	if (rc == -1)
 		goto exit;
 
@@ -99,7 +99,7 @@ conn_init(struct conn_params *p)
 {
 	int fd_server, fd_client_group, rc;
 	struct sockaddr_in server_address;
-	struct conn *conn = NULL;
+	struct conn *c = NULL;
 	int reuse = 1;
 
 	memset(&server_address, 0, sizeof(server_address));
@@ -115,20 +115,20 @@ conn_init(struct conn_params *p)
 		goto exit;
 
 	/* Memory allocation */
-	conn = calloc(1, sizeof(struct conn));
-	if (conn == NULL)
+	c = calloc(1, sizeof(struct conn));
+	if (c == NULL)
 		goto exit;
 
-	conn->welcome = calloc(1, CONN_WELCOME_LEN_MAX + 1);
-	conn->prompt = calloc(1, CONN_PROMPT_LEN_MAX + 1);
-	conn->buf = calloc(1, p->buf_size);
-	conn->msg_in = calloc(1, p->msg_in_len_max + 1);
-	conn->msg_out = calloc(1, p->msg_out_len_max + 1);
+	c->welcome = calloc(1, CONN_WELCOME_LEN_MAX + 1);
+	c->prompt = calloc(1, CONN_PROMPT_LEN_MAX + 1);
+	c->buf = calloc(1, p->buf_size);
+	c->msg_in = calloc(1, p->msg_in_len_max + 1);
+	c->msg_out = calloc(1, p->msg_out_len_max + 1);
 
-	if ((conn->welcome == NULL) || (conn->prompt == NULL) || (conn->buf == NULL) ||
-	    (conn->msg_in == NULL) || (conn->msg_out == NULL)) {
-		conn_free(conn);
-		conn = NULL;
+	if ((c->welcome == NULL) || (c->prompt == NULL) || (c->buf == NULL) ||
+	    (c->msg_in == NULL) || (c->msg_out == NULL)) {
+		conn_free(c);
+		c = NULL;
 		goto exit;
 	}
 
@@ -138,8 +138,8 @@ conn_init(struct conn_params *p)
 
 	fd_server = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
 	if (fd_server == -1) {
-		conn_free(conn);
-		conn = NULL;
+		conn_free(c);
+		c = NULL;
 		goto exit;
 	}
 
@@ -161,47 +161,47 @@ conn_init(struct conn_params *p)
 		goto free;
 
 	/* Fill in */
-	rte_strscpy(conn->welcome, p->welcome, CONN_WELCOME_LEN_MAX);
-	rte_strscpy(conn->prompt, p->prompt, CONN_PROMPT_LEN_MAX);
-	conn->buf_size = p->buf_size;
-	conn->msg_in_len_max = p->msg_in_len_max;
-	conn->msg_out_len_max = p->msg_out_len_max;
-	conn->msg_in_len = 0;
-	conn->fd_server = fd_server;
-	conn->fd_client_group = fd_client_group;
-	conn->msg_handle = p->msg_handle;
-	conn->msg_handle_arg = p->msg_handle_arg;
+	rte_strscpy(c->welcome, p->welcome, CONN_WELCOME_LEN_MAX);
+	rte_strscpy(c->prompt, p->prompt, CONN_PROMPT_LEN_MAX);
+	c->buf_size = p->buf_size;
+	c->msg_in_len_max = p->msg_in_len_max;
+	c->msg_out_len_max = p->msg_out_len_max;
+	c->msg_in_len = 0;
+	c->fd_server = fd_server;
+	c->fd_client_group = fd_client_group;
+	c->msg_handle = p->msg_handle;
+	c->msg_handle_arg = p->msg_handle_arg;
 
 exit:
-	return conn;
+	return c;
 free:
-	conn_free(conn);
+	conn_free(c);
 	close(fd_server);
-	conn = NULL;
-	return conn;
+	c = NULL;
+	return c;
 }
 
 void
-conn_free(struct conn *conn)
+conn_free(struct conn *c)
 {
-	if (conn == NULL)
+	if (c == NULL)
 		return;
 
-	if (conn->fd_client_group)
-		close(conn->fd_client_group);
+	if (c->fd_client_group)
+		close(c->fd_client_group);
 
-	if (conn->fd_server)
-		close(conn->fd_server);
+	if (c->fd_server)
+		close(c->fd_server);
 
-	free(conn->msg_out);
-	free(conn->msg_in);
-	free(conn->prompt);
-	free(conn->welcome);
-	free(conn);
+	free(c->msg_out);
+	free(c->msg_in);
+	free(c->prompt);
+	free(c->welcome);
+	free(c);
 }
 
 int
-conn_req_poll(struct conn *conn)
+conn_req_poll(struct conn *c)
 {
 	struct sockaddr_in client_address;
 	socklen_t client_address_length;
@@ -209,12 +209,12 @@ conn_req_poll(struct conn *conn)
 	int fd_client, rc;
 
 	/* Check input arguments */
-	if (conn == NULL)
+	if (c == NULL)
 		return -1;
 
 	/* Server socket */
 	client_address_length = sizeof(client_address);
-	fd_client = accept4(conn->fd_server, (struct sockaddr *)&client_address,
+	fd_client = accept4(c->fd_server, (struct sockaddr *)&client_address,
 			    &client_address_length, SOCK_NONBLOCK);
 	if (fd_client == -1) {
 		if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
@@ -227,20 +227,20 @@ conn_req_poll(struct conn *conn)
 	event.events = EPOLLIN | EPOLLRDHUP | EPOLLHUP;
 	event.data.fd = fd_client;
 
-	rc = epoll_ctl(conn->fd_client_group, EPOLL_CTL_ADD, fd_client, &event);
+	rc = epoll_ctl(c->fd_client_group, EPOLL_CTL_ADD, fd_client, &event);
 	if (rc == -1) {
 		close(fd_client);
 		goto exit;
 	}
 
 	/* Client */
-	rc = write(fd_client, conn->welcome, strlen(conn->welcome));
+	rc = write(fd_client, c->welcome, strlen(c->welcome));
 	if (rc == -1) {
 		close(fd_client);
 		goto exit;
 	}
 
-	rc = write(fd_client, conn->prompt, strlen(conn->prompt));
+	rc = write(fd_client, c->prompt, strlen(c->prompt));
 	if (rc == -1) {
 		close(fd_client);
 		goto exit;
@@ -253,17 +253,17 @@ conn_req_poll(struct conn *conn)
 }
 
 int
-conn_msg_poll(struct conn *conn)
+conn_msg_poll(struct conn *c)
 {
 	int fd_client, rc, rc_data = 0, rc_control = 0;
 	struct epoll_event event;
 
 	/* Check input arguments */
-	if (conn == NULL)
+	if (c == NULL)
 		return -1;
 
 	/* Client group */
-	rc = epoll_wait(conn->fd_client_group, &event, 1, 0);
+	rc = epoll_wait(c->fd_client_group, &event, 1, 0);
 	if ((rc == -1) || rc == 0)
 		return rc;
 
@@ -271,11 +271,11 @@ conn_msg_poll(struct conn *conn)
 
 	/* Data available */
 	if (event.events & EPOLLIN)
-		rc_data = data_event_handle(conn, fd_client);
+		rc_data = data_event_handle(c, fd_client);
 
 	/* Control events */
 	if (event.events & (EPOLLRDHUP | EPOLLERR | EPOLLHUP))
-		rc_control = control_event_handle(conn, fd_client);
+		rc_control = control_event_handle(c, fd_client);
 
 	if (rc_data || rc_control)
 		return -1;
-- 
2.48.1


  parent reply	other threads:[~2025-11-07 15:53 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-06 14:09 [RFC PATCH 00/19] Fix building much of DPDK with -Wshadow Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 01/19] eal: fix variable shadowing Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 02/19] ethdev: fix variable shadowing issues Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 03/19] eventdev: " Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 04/19] net: remove shadowed variable Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 05/19] graph: fix variable shadowing errors Bruce Richardson
2025-11-06 15:50   ` Stephen Hemminger
2025-11-06 16:33     ` Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 06/19] pipeline: fix variable shadowing Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 07/19] table: fix issues with " Bruce Richardson
2025-11-06 19:37   ` Stephen Hemminger
2025-11-06 19:58     ` Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 08/19] power: rename variable to eliminate shadowing Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 09/19] pcapng: rename variable to fix shadowing Bruce Richardson
2025-11-06 15:51   ` Stephen Hemminger
2025-11-06 14:09 ` [RFC PATCH 10/19] telemetry: make socket handler typedef private Bruce Richardson
2025-11-07  2:43   ` fengchengwen
2025-11-06 14:09 ` [RFC PATCH 11/19] bbdev: fix variable shadowing Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 12/19] bus/pci: remove shadowed variables Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 13/19] net/intel: rename function param to avoid shadow warnings Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 14/19] net/e1000: fix build with shadow warnings enabled Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 15/19] net/i40e: " Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 16/19] net/ice: " Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 17/19] net/cpfl: " Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 18/19] net/ixgbe: " Bruce Richardson
2025-11-06 14:09 ` [RFC PATCH 19/19] app/test-pmd: " Bruce Richardson
2025-11-07 15:49 ` [RFC PATCH v2 00/33] build DPDK with -Wshadow Bruce Richardson
2025-11-07 15:49   ` [RFC PATCH v2 01/33] eal: add more min/max helpers Bruce Richardson
2025-11-07 15:49   ` [RFC PATCH v2 02/33] eal: fix variable shadowing Bruce Richardson
2025-11-07 15:49   ` [RFC PATCH v2 03/33] ethdev: fix variable shadowing issues Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 04/33] eventdev: " Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 05/33] net: remove shadowed variable Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 06/33] pipeline: fix variable shadowing Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 07/33] table: fix issues with " Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 08/33] power: rename variable to eliminate shadowing Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 09/33] pcapng: rename variable to fix shadowing Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 10/33] telemetry: make socket handler typedef private Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 11/33] bbdev: fix variable shadowing Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 12/33] bus/pci: remove shadowed variables Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 13/33] net/intel: rename function param to avoid shadow warnings Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 14/33] net/e1000: fix build with shadow warnings enabled Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 15/33] net/i40e: " Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 16/33] net/ice: " Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 17/33] net/cpfl: " Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 18/33] net/ixgbe: " Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 19/33] app/test-pmd: " Bruce Richardson
2025-11-07 15:50   ` Bruce Richardson [this message]
2025-11-07 15:50   ` [RFC PATCH v2 21/33] app/pdump: fix warning about shadowed variable Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 22/33] app/test-bbdev: use RTE_MAX3 to remove variable shadowing Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 23/33] app/test-compress-perf: fix " Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 24/33] app/test-crypto-perf: fix shadowed variable Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 25/33] app/test-dma-perf: renamed " Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 26/33] app/test-eventdev: fix build with shadow warnings enabled Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 27/33] app/test-flow-perf: remove unneeded variable Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 28/33] app/test-security-perf: fix build with shadow warnings Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 29/33] app/test-pipeline: remove unnecessary variable Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 30/33] drivers: disable variable shadowing warnings for drivers Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 31/33] app/test: disable shadowing warnings for unit tests Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 32/33] examples: ignore variable shadowing warnings Bruce Richardson
2025-11-07 15:50   ` [RFC PATCH v2 33/33] build: enable shadowed variable warnings Bruce Richardson
2025-11-07 16:02   ` [RFC PATCH v2 00/33] build DPDK with -Wshadow Stephen Hemminger
2025-11-07 16:13     ` Bruce Richardson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251107155034.436809-21-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=ndabilpuram@marvell.com \
    --cc=rkudurumalla@marvell.com \
    --cc=skori@marvell.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).