lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c6dc6cf574379a937fdc7718c0516fbdcd82a729.camel@perches.com>
Date:   Tue, 07 Feb 2023 08:06:16 -0800
From:   Joe Perches <joe@...ches.com>
To:     Alexandra Winter <wintera@...ux.ibm.com>,
        David Miller <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>
Cc:     netdev@...r.kernel.org, linux-s390@...r.kernel.org,
        Heiko Carstens <hca@...ux.ibm.com>,
        Thorsten Winkler <twinkler@...ux.ibm.com>,
        Jules Irenge <jbi.octave@...il.com>
Subject: Re: [PATCH net-next 3/4] s390/qeth: Convert sysfs sprintf to
 sysfs_emit

On Mon, 2023-02-06 at 18:27 +0100, Alexandra Winter wrote:
> From: Thorsten Winkler <twinkler@...ux.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,

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ