From: Simon Horman <simon.horman@corigine.com>
To: Alexandra Winter <wintera@linux.ibm.com>
Cc: David Miller <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
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>,
Joe Perches <joe@perches.com>
Subject: Re: [PATCH net-next v2 3/4] s390/qeth: Convert sysfs sprintf to sysfs_emit
Date: Thu, 9 Feb 2023 12:27:31 +0100 [thread overview]
Message-ID: <Y+TYo2UXuVQuXGrY@corigine.com> (raw)
In-Reply-To: <20230209110424.1707501-4-wintera@linux.ibm.com>
On Thu, Feb 09, 2023 at 12:04:23PM +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.
>
> Reported-by: Jules Irenge <jbi.octave@gmail.com>
> Reported-by: Joe Perches <joe@perches.com>
> Reviewed-by: Alexandra Winter <wintera@linux.ibm.com>
> Signed-off-by: Thorsten Winkler <twinkler@linux.ibm.com>
> Signed-off-by: Alexandra Winter <wintera@linux.ibm.com>
...
> diff --git a/drivers/s390/net/qeth_l3_sys.c b/drivers/s390/net/qeth_l3_sys.c
> index 6143dd485810..f3986c6e21b9 100644
> --- a/drivers/s390/net/qeth_l3_sys.c
> +++ b/drivers/s390/net/qeth_l3_sys.c
...
> @@ -367,35 +367,21 @@ 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;
> + char addr_str[INET6_ADDRSTRLEN];
> + int offset = 0;
>
> mutex_lock(&card->ip_lock);
> list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
> - char addr_str[INET6_ADDRSTRLEN];
> - int entry_len;
> -
> if (ipatoe->proto != proto)
> continue;
>
> - entry_len = qeth_l3_ipaddr_to_string(proto, ipatoe->addr,
> - addr_str);
> - if (entry_len < 0)
> - continue;
Here the return code of qeth_l3_ipaddr_to_string() is checked for an error.
> -
> - /* 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;
> + qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str);
But here it is not. Is that ok?
Likewise in qeth_l3_dev_ip_add_show().
> + offset += sysfs_emit_at(buf, offset, "%s/%i\n",
> + addr_str, ipatoe->mask_bits);
> }
> mutex_unlock(&card->ip_lock);
>
> - return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
> + return offset ? offset : sysfs_emit(buf, "\n");
> }
>
> static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
> @@ -501,7 +487,7 @@ static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
> {
> struct qeth_card *card = dev_get_drvdata(dev);
>
> - return sprintf(buf, "%u\n", card->ipato.invert6 ? 1 : 0);
> + return sysfs_emit(buf, "%u\n", card->ipato.invert6 ? 1 : 0);
> }
>
> static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
> @@ -586,35 +572,22 @@ static ssize_t qeth_l3_dev_ip_add_show(struct device *dev, char *buf,
> enum qeth_ip_types type)
> {
> struct qeth_card *card = dev_get_drvdata(dev);
> + char addr_str[INET6_ADDRSTRLEN];
> struct qeth_ipaddr *ipaddr;
> - int str_len = 0;
> + int offset = 0;
> int i;
>
> mutex_lock(&card->ip_lock);
> hash_for_each(card->ip_htable, i, ipaddr, hnode) {
> - char addr_str[INET6_ADDRSTRLEN];
> - int entry_len;
> -
> if (ipaddr->proto != proto || ipaddr->type != type)
> continue;
>
> - entry_len = qeth_l3_ipaddr_to_string(proto, (u8 *)&ipaddr->u,
> - addr_str);
> - if (entry_len < 0)
> - continue;
> -
> - /* Enough room to format %addr\n into null terminated page? */
> - if (entry_len + 1 > PAGE_SIZE - str_len - 1)
> - break;
> -
> - entry_len = scnprintf(buf, PAGE_SIZE - str_len, "%s\n",
> - addr_str);
> - str_len += entry_len;
> - buf += entry_len;
> + qeth_l3_ipaddr_to_string(proto, (u8 *)&ipaddr->u, addr_str);
> + offset += sysfs_emit_at(buf, offset, "%s\n", addr_str);
> }
> mutex_unlock(&card->ip_lock);
>
> - return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
> + return offset ? offset : sysfs_emit(buf, "\n");
> }
>
> static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
> --
> 2.37.2
>
next prev parent reply other threads:[~2023-02-09 11:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-09 11:04 [PATCH net-next v2 0/4] s390/net: updates 2023-02-06 Alexandra Winter
2023-02-09 11:04 ` [PATCH net-next v2 1/4] s390/ctcm: cleanup indenting Alexandra Winter
2023-02-09 11:04 ` [PATCH net-next v2 2/4] s390/qeth: Use constant for IP address buffers Alexandra Winter
2023-02-09 11:24 ` Simon Horman
2023-02-09 11:04 ` [PATCH net-next v2 3/4] s390/qeth: Convert sysfs sprintf to sysfs_emit Alexandra Winter
2023-02-09 11:27 ` Simon Horman [this message]
2023-02-09 12:57 ` Alexandra Winter
2023-02-09 13:32 ` Simon Horman
2023-02-09 11:04 ` [PATCH net-next v2 4/4] s390/qeth: Convert sprintf/snprintf to scnprintf Alexandra Winter
2023-02-11 4:00 ` [PATCH net-next v2 0/4] s390/net: updates 2023-02-06 patchwork-bot+netdevbpf
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=Y+TYo2UXuVQuXGrY@corigine.com \
--to=simon.horman@corigine.com \
--cc=davem@davemloft.net \
--cc=hca@linux.ibm.com \
--cc=jbi.octave@gmail.com \
--cc=joe@perches.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.