Skip to contentSkip to conversation

counter/counter-sysfs: use sysfs_emit everywhere

PATCH In review David Lechner 3 participants 5 messages Oct 17, 2021 – Oct 18, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 counter/counter-sysfs: use sysfs_emit everywhere

In the counter subsystem, we are already using sysfs_emit(), but there were a few places where we were still using sprintf() in *_show() functions. For consistency and added protections, use sysfs_emit() everywhere.

---
 drivers/counter/counter-sysfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/counter/counter-sysfs.c +4 -4
index 7bf8882ff54d..8c2d7c29ea59 100644
@@ -113,7 +113,7 @@ static ssize_t counter_comp_u8_show(struct device *dev,
 		/* data should already be boolean but ensure just to be safe */
 		data = !!data;
 
-	return sprintf(buf, "%u\n", (unsigned int)data);
+	return sysfs_emit(buf, "%u\n", (unsigned int)data);
 }
 
 static ssize_t counter_comp_u8_store(struct device *dev,
@@ -196,7 +196,7 @@ static ssize_t counter_comp_u32_show(struct device *dev,
 	case COUNTER_COMP_COUNT_MODE:
 		return sysfs_emit(buf, "%s\n", counter_count_mode_str[data]);
 	default:
-		return sprintf(buf, "%u\n", (unsigned int)data);
+		return sysfs_emit(buf, "%u\n", (unsigned int)data);
 	}
 }
 
@@ -300,7 +300,7 @@ static ssize_t counter_comp_u64_show(struct device *dev,
 	if (err < 0)
 		return err;
 
-	return sprintf(buf, "%llu\n", (unsigned long long)data);
+	return sysfs_emit(buf, "%llu\n", (unsigned long long)data);
 }
 
 static ssize_t counter_comp_u64_store(struct device *dev,
@@ -539,7 +539,7 @@ static ssize_t counter_comp_id_show(struct device *dev,
 {
 	const size_t id = (size_t)to_counter_attribute(attr)->comp.priv;
 
-	return sprintf(buf, "%zu\n", id);
+	return sysfs_emit(buf, "%zu\n", id);
 }
 
 static int counter_comp_id_attr_create(struct device *const dev,
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · David Lechner

In the counter subsystem, we are already using sysfs_emit(), but there were a few places where we were still using sprintf() in *_show() functions. For consistency and added protections, use sysfs_emit() everywhere.

Quoted 47 lines
---
 drivers/counter/counter-sysfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/counter/counter-sysfs.c +4 -4
index 7bf8882ff54d..8c2d7c29ea59 100644
@@ -113,7 +113,7 @@ static ssize_t counter_comp_u8_show(struct device *dev,
 		/* data should already be boolean but ensure just to be safe */
 		data = !!data;
 
-	return sprintf(buf, "%u\n", (unsigned int)data);
+	return sysfs_emit(buf, "%u\n", (unsigned int)data);
 }
 
 static ssize_t counter_comp_u8_store(struct device *dev,
@@ -196,7 +196,7 @@ static ssize_t counter_comp_u32_show(struct device *dev,
 	case COUNTER_COMP_COUNT_MODE:
 		return sysfs_emit(buf, "%s\n", counter_count_mode_str[data]);
 	default:
-		return sprintf(buf, "%u\n", (unsigned int)data);
+		return sysfs_emit(buf, "%u\n", (unsigned int)data);
 	}
 }
 
@@ -300,7 +300,7 @@ static ssize_t counter_comp_u64_show(struct device *dev,
 	if (err < 0)
 		return err;
 
-	return sprintf(buf, "%llu\n", (unsigned long long)data);
+	return sysfs_emit(buf, "%llu\n", (unsigned long long)data);
 }
 
 static ssize_t counter_comp_u64_store(struct device *dev,
@@ -539,7 +539,7 @@ static ssize_t counter_comp_id_show(struct device *dev,
 {
 	const size_t id = (size_t)to_counter_attribute(attr)->comp.priv;
 
-	return sprintf(buf, "%zu\n", id);
+	return sysfs_emit(buf, "%zu\n", id);
 }
 
 static int counter_comp_id_attr_create(struct device *const dev,
Signature · 1 line
2.25.1
#2 lore raw
Quoted 10 lines · William Breathitt Gray
Quoted 7 lines · David Lechner

In the counter subsystem, we are already using sysfs_emit(), but there were a few places where we were still using sprintf() in *_show() functions. For consistency and added protections, use sysfs_emit() everywhere.

Thanks, want me to take this directly on top of the previous pull request?

greg k-h

#3 lore raw
Quoted 10 lines · Greg KH
Quoted 9 lines · William Breathitt Gray
Quoted 7 lines · David Lechner

In the counter subsystem, we are already using sysfs_emit(), but there were a few places where we were still using sprintf() in *_show() functions. For consistency and added protections, use sysfs_emit() everywhere.

Quoted 6 lines
Quoted 1 line

Thanks, want me to take this directly on top of the previous pull request?

greg k-h

Yes, that should be a fine path forward for this patch.

Thank you,

William Breathitt Gray

#4 lore raw
Quoted 11 lines · William Breathitt Gray
Quoted 10 lines · Greg KH
Quoted 9 lines · William Breathitt Gray
Quoted 7 lines · David Lechner

In the counter subsystem, we are already using sysfs_emit(), but there were a few places where we were still using sprintf() in *_show() functions. For consistency and added protections, use sysfs_emit() everywhere.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Thanks, want me to take this directly on top of the previous pull request?

greg k-h

Yes, that should be a fine path forward for this patch.

Great! Can you also ack the other patch from David as well?

thanks,

greg k-h