Skip to contentSkip to conversation

hte: Use kasprintf() instead of fixed buffer formatting

PATCH Superseded Andy Shevchenko 2 participants 4 messages Oct 10, 2023 – Oct 27, 2023 HTE

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hte: Use kasprintf() instead of fixed buffer formatting

Improve readability and maintainability by replacing a hardcoded string allocation and formatting by the use of the kasprintf() helper.

---
 drivers/hte/hte.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/hte/hte.c +4 -9
index 1fd8d2d4528b..23a6eeb8c506 100644
@@ -17,8 +17,6 @@
 #include <linux/debugfs.h>
 #include <linux/device.h>
 
-#define HTE_TS_NAME_LEN		10
-
 /* Global list of the HTE devices */
 static DEFINE_SPINLOCK(hte_lock);
 static LIST_HEAD(hte_devices);
@@ -389,13 +387,10 @@ static int __hte_req_ts(struct hte_ts_desc *desc, hte_ts_cb_t cb,
 
 	atomic_inc(&gdev->ts_req);
 
-	ei->line_name = NULL;
-	if (!desc->attr.name) {
-		ei->line_name = kzalloc(HTE_TS_NAME_LEN, GFP_KERNEL);
-		if (ei->line_name)
-			scnprintf(ei->line_name, HTE_TS_NAME_LEN, "ts_%u",
-				  desc->attr.line_id);
-	}
+	if (desc->attr.name)
+		ei->line_name = NULL;
+	else
+		ei->line_name = kasprintf(GFP_KERNEL, "ts_%u", desc->attr.line_id);
 
 	hte_ts_dbgfs_init(desc->attr.name == NULL ?
 			  ei->line_name : desc->attr.name, ei);
Signature · 1 line
2.40.0.1.gaa8946217a0b
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Andy Shevchenko

Improve readability and maintainability by replacing a hardcoded string allocation and formatting by the use of the kasprintf() helper.

---
 drivers/hte/hte.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/hte/hte.c +0 -6
index 1fd8d2d4528b..23a6eeb8c506 100644
@@ -17,8 +17,6 @@
 #include <linux/debugfs.h>
 #include <linux/device.h>
 
-#define HTE_TS_NAME_LEN		10
-
 /* Global list of the HTE devices */
 static DEFINE_SPINLOCK(hte_lock);
 static LIST_HEAD(hte_devices);
@@ -389,13 +387,10 @@ static int __hte_req_ts(struct hte_ts_desc *desc, hte_ts_cb_t cb,
 
 	atomic_inc(&gdev->ts_req);
 
-	ei->line_name = NULL;
-	if (!desc->attr.name) {
-		ei->line_name = kzalloc(HTE_TS_NAME_LEN, GFP_KERNEL);
-		if (ei->line_name)

drivers/hte/hte.c static int __hte_req_ts(struct hte_ts_desc *desc, hte_ts_cb_t cb, · line 396

Quoted 10 lines
drivers/hte/hte.c +4 -3
-			scnprintf(ei->line_name, HTE_TS_NAME_LEN, "ts_%u",
-				  desc->attr.line_id);
-	}
+	if (desc->attr.name)
+		ei->line_name = NULL;
+	else
+		ei->line_name = kasprintf(GFP_KERNEL, "ts_%u", desc->attr.line_id);
 
 	hte_ts_dbgfs_init(desc->attr.name == NULL ?
 			  ei->line_name : desc->attr.name, ei);
#2 lore raw
Quoted 3 lines · Dipen Patel
Quoted 2 lines · Andy Shevchenko

Improve readability and maintainability by replacing a hardcoded string allocation and formatting by the use of the kasprintf() helper.

...

Quoted 3 lines

drivers/hte/hte.c static int __hte_req_ts(struct hte_ts_desc *desc, hte_ts_cb_t cb, · line 396

Quoted 2 lines
drivers/hte/hte.c +0 -0
 	hte_ts_dbgfs_init(desc->attr.name == NULL ?
 			  ei->line_name : desc->attr.name, ei);

Thanks!

Who is the maintainer of this code?
If not you, shouldn't MAINTAINERS to be updated to reflect that?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#3 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Dipen Patel
Quoted 2 lines · Andy Shevchenko

Improve readability and maintainability by replacing a hardcoded string allocation and formatting by the use of the kasprintf() helper.

...

Quoted 9 lines
Quoted 3 lines

drivers/hte/hte.c static int __hte_req_ts(struct hte_ts_desc *desc, hte_ts_cb_t cb, · line 396

Quoted 2 lines
drivers/hte/hte.c +0 -0
 	hte_ts_dbgfs_init(desc->attr.name == NULL ?
 			  ei->line_name : desc->attr.name, ei);

Thanks!

Who is the maintainer of this code?
If not you, shouldn't MAINTAINERS to be updated to reflect that?

I am the maintainer, I am not sure how did I miss this patch for my for-next. Let me push this right away.