From: Joe Perches <joe@perches.com>
To: Alexandra Winter <wintera@linux.ibm.com>,
David Miller <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org, linux-s390@vger.kernel.org,
Heiko Carstens <hca@linux.ibm.com>,
Thorsten Winkler <twinkler@linux.ibm.com>,
Jules Irenge <jbi.octave@gmail.com>
Subject: Re: [PATCH net-next 3/4] s390/qeth: Convert sysfs sprintf to sysfs_emit
Date: Tue, 07 Feb 2023 08:06:16 -0800 [thread overview]
Message-ID: <c6dc6cf574379a937fdc7718c0516fbdcd82a729.camel@perches.com> (raw)
In-Reply-To: <20230206172754.980062-4-wintera@linux.ibm.com>
On Mon, 2023-02-06 at 18:27 +0100, Alexandra Winter wrote:
> From: Thorsten Winkler <twinkler@linux.ibm.com>
>
> Following the advice of the Documentation/filesystems/sysfs.rst.
> All sysfs related show()-functions should only use sysfs_emit() or
> sysfs_emit_at() when formatting the value to be returned to user space.
[]
> diff --git a/drivers/s390/net/qeth_l3_sys.c b/drivers/s390/net/qeth_l3_sys.c
[]
> @@ -607,14 +606,12 @@ static ssize_t qeth_l3_dev_ip_add_show(struct device *dev, char *buf,
> if (entry_len + 1 > PAGE_SIZE - str_len - 1)
> break;
>
> - entry_len = scnprintf(buf, PAGE_SIZE - str_len, "%s\n",
> - addr_str);
> + entry_len = sysfs_emit_at(buf, str_len, "%s\n", addr_str);
> str_len += entry_len;
> - buf += entry_len;
> }
> mutex_unlock(&card->ip_lock);
>
> - return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
> + return str_len ? str_len : sysfs_emit(buf, "\n");
> }
>
> static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
One of the intended uses of sysfs_emit is to not require the
knowlege of buf as PAGE_SIZE so it could possibly be
extended/changed.
So perhaps the use of entry_len is useless and the PAGE_SIZE use
above should be removed.
The below though could emit a partial line, dunno if that's a
good thing or not but sysfs is not supposed to emit multiple
lines anyway.
---
diff --git a/drivers/s390/net/qeth_l3_sys.c b/drivers/s390/net/qeth_l3_sys.c
index 1082380b21f85..a2a332f29f5c4 100644
--- a/drivers/s390/net/qeth_l3_sys.c
+++ b/drivers/s390/net/qeth_l3_sys.c
@@ -367,35 +367,24 @@ static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
enum qeth_prot_versions proto)
{
struct qeth_ipato_entry *ipatoe;
- int str_len = 0;
+ int len = 0;
mutex_lock(&card->ip_lock);
list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
char addr_str[40];
- int entry_len;
if (ipatoe->proto != proto)
continue;
- entry_len = qeth_l3_ipaddr_to_string(proto, ipatoe->addr,
- addr_str);
- if (entry_len < 0)
+ if (qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str) < 0)
continue;
- /* Append /%mask to the entry: */
- entry_len += 1 + ((proto == QETH_PROT_IPV4) ? 2 : 3);
- /* Enough room to format %entry\n into null terminated page? */
- if (entry_len + 1 > PAGE_SIZE - str_len - 1)
- break;
-
- entry_len = scnprintf(buf, PAGE_SIZE - str_len,
- "%s/%i\n", addr_str, ipatoe->mask_bits);
- str_len += entry_len;
- buf += entry_len;
+ len += sysfs_emit_at(buf, len, "%s/%i\n",
+ addr_str, ipatoe->mask_bits);
}
mutex_unlock(&card->ip_lock);
- return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
+ return len ?: sysfs_emit(buf, "\n");
}
static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
next prev parent reply other threads:[~2023-02-07 16:13 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-06 17:27 [PATCH net-next 0/4] s390/net: updates 2023-02-06 Alexandra Winter
2023-02-06 17:27 ` [PATCH net-next 1/4] s390/ctcm: cleanup indenting Alexandra Winter
2023-02-07 15:25 ` Simon Horman
2023-02-06 17:27 ` [PATCH net-next 2/4] s390/qeth: Use constant for IP address buffers Alexandra Winter
2023-02-07 15:26 ` Simon Horman
2023-02-06 17:27 ` [PATCH net-next 3/4] s390/qeth: Convert sysfs sprintf to sysfs_emit Alexandra Winter
2023-02-07 15:37 ` Simon Horman
2023-02-07 16:06 ` Joe Perches [this message]
2023-02-08 18:30 ` Alexandra Winter
2023-02-06 17:27 ` [PATCH net-next 4/4] s390/qeth: Convert sprintf/snprintf to scnprintf Alexandra Winter
2023-02-07 15:42 ` Simon Horman
2023-02-08 14:37 ` David Laight
2023-02-08 14:40 ` Simon Horman
2023-02-08 18:19 ` Alexandra Winter
2023-02-09 9:38 ` Simon Horman
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=c6dc6cf574379a937fdc7718c0516fbdcd82a729.camel@perches.com \
--to=joe@perches.com \
--cc=davem@davemloft.net \
--cc=hca@linux.ibm.com \
--cc=jbi.octave@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=twinkler@linux.ibm.com \
--cc=wintera@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;
as well as URLs for NNTP newsgroup(s).