public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: Julian Wiedmann <jwi@linux.ibm.com>
To: David Miller <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>
Cc: netdev <netdev@vger.kernel.org>,
	linux-s390 <linux-s390@vger.kernel.org>,
	Heiko Carstens <hca@linux.ibm.com>,
	Ursula Braun <ubraun@linux.ibm.com>,
	Karsten Graul <kgraul@linux.ibm.com>,
	Julian Wiedmann <jwi@linux.ibm.com>
Subject: [PATCH net-next 3/9] s390/qeth: clean up string ops in qeth_l3_parse_ipatoe()
Date: Wed, 23 Sep 2020 10:36:54 +0200	[thread overview]
Message-ID: <20200923083700.44624-4-jwi@linux.ibm.com> (raw)
In-Reply-To: <20200923083700.44624-1-jwi@linux.ibm.com>

Indicate the max number of to-be-parsed characters, and avoid copying
the address sub-string.

Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
---
 drivers/s390/net/qeth_l3_sys.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/s390/net/qeth_l3_sys.c b/drivers/s390/net/qeth_l3_sys.c
index ca9c95b6bf35..05fa986e30fc 100644
--- a/drivers/s390/net/qeth_l3_sys.c
+++ b/drivers/s390/net/qeth_l3_sys.c
@@ -409,21 +409,22 @@ static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
 static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
 		  u8 *addr, int *mask_bits)
 {
-	const char *start, *end;
-	char *tmp;
-	char buffer[40] = {0, };
+	const char *start;
+	char *sep, *tmp;
+	int rc;
 
-	start = buf;
-	/* get address string */
-	end = strchr(start, '/');
-	if (!end || (end - start >= 40)) {
+	/* Expected input pattern: %addr/%mask */
+	sep = strnchr(buf, 40, '/');
+	if (!sep)
 		return -EINVAL;
-	}
-	strncpy(buffer, start, end - start);
-	if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
-		return -EINVAL;
-	}
-	start = end + 1;
+
+	/* Terminate the %addr sub-string, and parse it: */
+	*sep = '\0';
+	rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
+	if (rc)
+		return rc;
+
+	start = sep + 1;
 	*mask_bits = simple_strtoul(start, &tmp, 10);
 	if (!strlen(start) ||
 	    (tmp == start) ||
-- 
2.17.1

  parent reply	other threads:[~2020-09-23  8:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23  8:36 [PATCH net-next 0/9] s390/qeth: updates 2020-09-23 Julian Wiedmann
2020-09-23  8:36 ` [PATCH net-next 1/9] s390/qeth: don't init refcount twice for mcast IPs Julian Wiedmann
2020-09-23  8:36 ` [PATCH net-next 2/9] s390/qeth: relax locking for ipato config data Julian Wiedmann
2020-09-23  8:36 ` Julian Wiedmann [this message]
2020-09-23  9:55   ` [PATCH net-next 3/9] s390/qeth: clean up string ops in qeth_l3_parse_ipatoe() David Laight
2020-09-23 10:43     ` Julian Wiedmann
2020-09-23  8:36 ` [PATCH net-next 4/9] s390/qeth: replace deprecated simple_stroul() Julian Wiedmann
2020-09-23  8:36 ` [PATCH net-next 5/9] s390/qeth: tighten ucast IP locking Julian Wiedmann
2020-09-23  8:36 ` [PATCH net-next 6/9] s390/qeth: cancel cmds earlier during teardown Julian Wiedmann
2020-09-23  8:36 ` [PATCH net-next 7/9] s390/qeth: consolidate online code Julian Wiedmann
2020-09-23  8:36 ` [PATCH net-next 8/9] s390/qeth: consolidate teardown code Julian Wiedmann
2020-09-23  8:37 ` [PATCH net-next 9/9] s390/qeth: remove forward declarations in L2 code Julian Wiedmann
2020-09-23 19:08 ` [PATCH net-next 0/9] s390/qeth: updates 2020-09-23 David Miller

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=20200923083700.44624-4-jwi@linux.ibm.com \
    --to=jwi@linux.ibm.com \
    --cc=davem@davemloft.net \
    --cc=hca@linux.ibm.com \
    --cc=kgraul@linux.ibm.com \
    --cc=kuba@kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ubraun@linux.ibm.com \
    /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