linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] drivers core: Miscellaneous changes for sysfs_emit
Date: Mon,  7 Sep 2020 10:58:08 -0700	[thread overview]
Message-ID: <536145200969138069f3ba6f7ed9d0f09ba1609c.1599501047.git.joe@perches.com> (raw)
In-Reply-To: <cover.1599501047.git.joe@perches.com>

Change a few additional instances that could use sysfs_emit that
the coccinelle script could not convert.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/base/class.c    |  2 +-
 drivers/base/cpu.c      | 18 +++++++++---------
 drivers/base/node.c     | 15 +++------------
 drivers/base/platform.c |  4 +---
 4 files changed, 14 insertions(+), 25 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index bcd410e6d70a..c3451481194e 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -478,7 +478,7 @@ ssize_t show_class_attr_string(struct class *class,
 	struct class_attribute_string *cs;
 
 	cs = container_of(attr, struct class_attribute_string, attr);
-	return snprintf(buf, PAGE_SIZE, "%s\n", cs->str);
+	return sysfs_emit(buf, "%s\n", cs->str);
 }
 
 EXPORT_SYMBOL_GPL(show_class_attr_string);
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 232f8146a8c4..d3dc48bf6b0f 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -241,30 +241,30 @@ unsigned int total_cpus;
 static ssize_t print_cpus_offline(struct device *dev,
 				  struct device_attribute *attr, char *buf)
 {
-	int n = 0, len = PAGE_SIZE-2;
+	int len = 0;
 	cpumask_var_t offline;
 
 	/* display offline cpus < nr_cpu_ids */
 	if (!alloc_cpumask_var(&offline, GFP_KERNEL))
 		return -ENOMEM;
 	cpumask_andnot(offline, cpu_possible_mask, cpu_online_mask);
-	n = scnprintf(buf, len, "%*pbl", cpumask_pr_args(offline));
+	len += sysfs_emit_at(buf, len, "%*pbl", cpumask_pr_args(offline));
 	free_cpumask_var(offline);
 
 	/* display offline cpus >= nr_cpu_ids */
 	if (total_cpus && nr_cpu_ids < total_cpus) {
-		if (n && n < len)
-			buf[n++] = ',';
+		len += sysfs_emit_at(buf, len, "%s", ",");
 
 		if (nr_cpu_ids == total_cpus-1)
-			n += scnprintf(&buf[n], len - n, "%u", nr_cpu_ids);
+			len += sysfs_emit_at(buf, len, "%u", nr_cpu_ids);
 		else
-			n += scnprintf(&buf[n], len - n, "%u-%d",
-						      nr_cpu_ids, total_cpus-1);
+			len += sysfs_emit_at(buf, len, "%u-%d",
+					     nr_cpu_ids, total_cpus-1);
 	}
 
-	n += scnprintf(&buf[n], len - n, "\n");
-	return n;
+	len += sysfs_emit_at(buf, len, "%s", "\n");
+
+	return len;
 }
 static DEVICE_ATTR(offline, 0444, print_cpus_offline, NULL);
 
diff --git a/drivers/base/node.c b/drivers/base/node.c
index f10e8236aba8..e6092b81644d 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -945,17 +945,6 @@ void unregister_one_node(int nid)
  * node states attributes
  */
 
-static ssize_t print_nodes_state(enum node_states state, char *buf)
-{
-	int n;
-
-	n = scnprintf(buf, PAGE_SIZE - 1, "%*pbl",
-		      nodemask_pr_args(&node_states[state]));
-	buf[n++] = '\n';
-	buf[n] = '\0';
-	return n;
-}
-
 struct node_attr {
 	struct device_attribute attr;
 	enum node_states state;
@@ -965,7 +954,9 @@ static ssize_t show_node_state(struct device *dev,
 			       struct device_attribute *attr, char *buf)
 {
 	struct node_attr *na = container_of(attr, struct node_attr, attr);
-	return print_nodes_state(na->state, buf);
+
+	return sysfs_emit(buf, "%*pbl\n",
+			  nodemask_pr_args(&node_states[na->state]));
 }
 
 #define _NODE_ATTR(name, state) \
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 0e03168c657c..927047f9e6a4 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -1023,9 +1023,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
 	if (len != -ENODEV)
 		return len;
 
-	len = snprintf(buf, PAGE_SIZE, "platform:%s\n", pdev->name);
-
-	return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
+	return sysfs_emit(buf, "platform:%s\n", pdev->name);
 }
 static DEVICE_ATTR_RO(modalias);
 
-- 
2.26.0


  parent reply	other threads:[~2020-09-07 17:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-07 17:58 [PATCH 0/4] drivers core: Use sysfs_emit functions Joe Perches
2020-09-07 17:58 ` [PATCH 1/4] drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions Joe Perches
     [not found]   ` <202009080519.SXudMmrU%lkp@intel.com>
2020-09-07 22:58     ` Joe Perches
2020-09-08  8:27   ` Greg Kroah-Hartman
2020-09-08  8:33     ` Joe Perches
2020-09-07 17:58 ` [PATCH 2/4] drivers core: Remove strcat uses around sysfs_emit and neaten Joe Perches
2020-09-08  1:54   ` kernel test robot
2020-09-08  8:32   ` Greg Kroah-Hartman
2020-09-08  8:40     ` Joe Perches
2020-09-07 17:58 ` [PATCH 3/4] drivers core: Reindent a couple uses around sysfs_emit Joe Perches
2020-09-07 17:58 ` Joe Perches [this message]
2020-09-07 22:59   ` [PATCH 4/4] drivers core: Miscellaneous changes for sysfs_emit kernel test robot
2020-09-07 19:58 ` [PATCH 5/4] drivers core: Convert class uses of sprintf to sysfs_emit Joe Perches

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=536145200969138069f3ba6f7ed9d0f09ba1609c.1599501047.git.joe@perches.com \
    --to=joe@perches.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.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).