Skip to contentSkip to conversation

block: simplify string handling in elv_iosched_store()

PATCH Applied Li Zefan 2 participants 2 messages Oct 14, 2008 Block layer

lore
Share & tools
lore

Li Zefan

author
#0 lore raw

PATCH 1/1 block: simplify string handling in elv_iosched_store()

strlcpy() guarantees the dest buffer is NULL teminated.

---
 block/elevator.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)
block/elevator.c +2 -7
index 0451892..9482ffa 100644
@@ -1166,15 +1166,10 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,
 			  size_t count)
 {
 	char elevator_name[ELV_NAME_MAX];
-	size_t len;
 	struct elevator_type *e;
 
-	elevator_name[sizeof(elevator_name) - 1] = '\0';
-	strncpy(elevator_name, name, sizeof(elevator_name) - 1);
-	len = strlen(elevator_name);
-
-	if (len && elevator_name[len - 1] == '\n')
-		elevator_name[len - 1] = '\0';
+	strlcpy(elevator_name, name, sizeof(elevator_name));
+	strstrip(elevator_name);
 
 	e = elevator_get(elevator_name);
 	if (!e) {
Signature · 1 line
1.5.4.rc3
Applied
#1 lore raw
Quoted 6 lines · Li Zefan

strlcpy() guarantees the dest buffer is NULL teminated.

---
 block/elevator.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)

Applied, thanks

Signature · 1 line
Jens Axboe