diff mbox series

block: use strncmp() instead of strcmp() for comparing device name

Message ID 20190131092520.20273-1-cgxu519@gmx.com (mailing list archive)
State New, archived
Headers show
Series block: use strncmp() instead of strcmp() for comparing device name | expand

Commit Message

Chengguang Xu Jan. 31, 2019, 9:25 a.m. UTC
We use strlcpy() to copy device name in register_blkdev(),
so if the device name is longer enough(accurately longer
than 15 bytes), the copied name is truncated to 15 bytes.
In this case, it's better to use strncmp() to compare device
name instead of strcmp() in unregister_blkdev(), so that
we can recognize the device name correctly.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 block/genhd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/block/genhd.c b/block/genhd.c
index 1dd8fd6613b8..efc532ae9de9 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -424,7 +424,7 @@  void unregister_blkdev(unsigned int major, const char *name)
 	for (n = &major_names[index]; *n; n = &(*n)->next)
 		if ((*n)->major == major)
 			break;
-	if (!*n || strcmp((*n)->name, name)) {
+	if (!*n || strncmp((*n)->name, name, strlen((*n)->name))) {
 		WARN_ON(1);
 	} else {
 		p = *n;