Skip to content

Commit

Permalink
block: simplify string handling in elv_iosched_store()
Browse files Browse the repository at this point in the history
strlcpy() guarantees the dest buffer is NULL teminated.

Signed-off-by: Li Zefan <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Li Zefan authored and Jens Axboe committed Oct 17, 2008
1 parent e6d6384 commit ee2e992
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions block/elevator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ee2e992

Please sign in to comment.