dm vdo: Fix W=1 allmodconfig build error
Subsystems (2)
PATCH 1/1 dm vdo: Fix W=1 allmodconfig build error
For an allmodconfig build, I currently get this error when building with W=1:
$ make W=1 drivers/md/dm-vdo/vdo.o
CALL scripts/checksyscalls.sh
DESCEND objtool
INSTALL libsubcmd_headers
CC [M] drivers/md/dm-vdo/vdo.o
drivers/md/dm-vdo/vdo.c: In function ‘vdo_make’:
drivers/md/dm-vdo/vdo.c:564:5: error: ‘%s’ directive output may be truncated writing up to 55 bytes into a region of size 16 [-Werror=format-truncation=]
"%s%u", MODULE_NAME, instance);
^~
drivers/md/dm-vdo/vdo.c:563:2: note: ‘snprintf’ output between 2 and 66 bytes into a destination of size 16
snprintf(vdo->thread_name_prefix, sizeof(vdo->thread_name_prefix),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"%s%u", MODULE_NAME, instance);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Fix by defining MAX_VDO_WORK_QUEUE_NAME_LEN to be sum of MODULE_NAME_LEN plus 11 - 11 comes from number of characters required to print max unsigned int plus NUL terminator.
Also relocate the include of sched.h to the only c file which it is actually needed.
drivers/md/dm-vdo/funnel-workqueue.c +1 -0
@@ -11,6 +11,7 @@#include <linux/err.h> #include <linux/kthread.h> #include <linux/percpu.h> +#include <linux/sched.h> #include "funnel-queue.h" #include "logger.h"
drivers/md/dm-vdo/funnel-workqueue.h +1 -3
@@ -6,12 +6,10 @@#ifndef VDO_WORK_QUEUE_H #define VDO_WORK_QUEUE_H -#include <linux/sched.h> /* for TASK_COMM_LEN */ -#include "types.h" enum { -MAX_VDO_WORK_QUEUE_NAME_LEN =TASK_COMM_LEN , +MAX_VDO_WORK_QUEUE_NAME_LEN =MODULE_NAME_LEN +11 , }; struct vdo_work_queue_type {
Signature · 1 line
2.31.1
Matthew Sakai
maintainerHi John,
I'm all for getting rid of warnings where we can, but I'm not convinced this is the right approach here.
First, we use snprintf here because we really do want to limit the
string to 15 bytes. Making this constant larger doesn't maintain that. This change also increases the size of struct vdo (in vdo.h) by about 50 bytes. While that's not a lot, it does seem unnecessary.
In practice, we know that the our module name is only about 6 bytes, and the instance number will never be more than 3, so snprintf will never actually truncate anything here. Would checking for a non-zero return value suppress the error?
I'm also confused because I don't understand the difference between this line and the similar use of snprintf at drivers/md/dm-vdo/funnel-workqueue.c:430, which I presume does not trigger a warning?
Anyway, I'd be happy with a version that suppresses the warning without changing the size of any structures.
Matt Sakai
Quoted 57 lines · John Garry
For an allmodconfig build, I currently get this error when building with W=1:
$ make W=1 drivers/md/dm-vdo/vdo.o CALL scripts/checksyscalls.sh DESCEND objtool INSTALL libsubcmd_headers CC [M] drivers/md/dm-vdo/vdo.o drivers/md/dm-vdo/vdo.c: In function ‘vdo_make’: drivers/md/dm-vdo/vdo.c:564:5: error: ‘%s’ directive output may be truncated writing up to 55 bytes into a region of size 16 [-Werror=format-truncation=] "%s%u", MODULE_NAME, instance); ^~ drivers/md/dm-vdo/vdo.c:563:2: note: ‘snprintf’ output between 2 and 66 bytes into a destination of size 16 snprintf(vdo->thread_name_prefix, sizeof(vdo->thread_name_prefix), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%s%u", MODULE_NAME, instance); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Fix by defining
MAX_VDO_WORK_QUEUE_NAME_LENto be sum ofMODULE_NAME_LENplus 11 - 11 comes from number of characters required to print max unsigned int plus NUL terminator.Also relocate the include of
sched.hto the only c file which it is actually needed.Signed-off-by John Garry <[email protected]>drivers/md/dm-vdo/funnel-workqueue.c +1
-0@@ -11,6 +11,7 @@#include <linux/err.h> #include <linux/kthread.h> #include <linux/percpu.h> +#include <linux/sched.h> #include "funnel-queue.h" #include "logger.h" drivers/md/dm-vdo/funnel-workqueue.h +1
-3@@ -6,12 +6,10 @@#ifndef VDO_WORK_QUEUE_H #define VDO_WORK_QUEUE_H -#include <linux/sched.h> /* for TASK_COMM_LEN */ -#include "types.h" enum { -MAX_VDO_WORK_QUEUE_NAME_LEN =TASK_COMM_LEN , +MAX_VDO_WORK_QUEUE_NAME_LEN =MODULE_NAME_LEN +11 , }; struct vdo_work_queue_type {
Quoted 1 line · Matthew Sakai
Hi John,
Hi Matt,
Quoted 5 lines
I'm all for getting rid of warnings where we can, but I'm not convinced this is the right approach here.
First, we use snprintf here because we really do want to limit the string to 15 bytes.
Out of curiosity, why is that?
BTW, as I understand, for CONFIG_DM_VDO=m, the module name is "dm_vdo". So why different MODULE_NAME if MODULE is not defined ("dm-vdo")?
Quoted 5 lines
Making this constant larger doesn't maintain that. This change also increases the size of struct vdo (in
vdo.h) by about 50 bytes. While that's not a lot, it does seem unnecessary.In practice, we know that the our module name is only about 6 bytes, and the instance number will never be more than 3, so snprintf will never actually truncate anything here. Would checking for a non-zero return value suppress the error?
I'm also confused because I don't understand the difference between this line and the similar use of snprintf at
drivers/md/dm-vdo/funnel-workqueue.c:430, which I presume does not trigger a warning?
For that snprintf usage, the compiler just doesn't know the possible length of @name, as it is a pointer. That is why it is a good reason to use snprintf.
Quoted 5 lines
Anyway, I'd be happy with a version that suppresses the warning without changing the size of any structures.
Matt Sakai
Thanks,
John
Matthew Sakai
maintainerQuoted 6 lines · John Garry
Quoted 1 line · Matthew Sakai
Hi John,
Hi Matt,
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
I'm all for getting rid of warnings where we can, but I'm not convinced this is the right approach here.
First, we use snprintf here because we really do want to limit the string to 15 bytes.
Out of curiosity, why is that?
A dm-vdo target creates several threads to do its work. The thread_name_prefix is intended to be a short string at the start of the thread name that allows users to easily distinguish these dm-vdo threads from all others on the system. But it should not be so long that the dm-vdo threads cannot be distinguished from each other.
Now that we're talking about it, I think it's probably even better not to use the full module name, but instead use a short static string like "vdo".
Quoted 1 line
BTW, as I understand, for
CONFIG_DM_VDO=m, the module name is "dm_vdo". So why differentMODULE_NAMEif MODULE is not defined ("dm-vdo")?
That is a historical artifact and it should just get removed. The module name should just be a constant string. I could write up a patch to do this if you don't want to. It might take me a couple of days though because I'm still dealing with some holiday backlog.
Even after we do this, I still think the prefix string should no longer rely on the module name.
Quoted 9 lines
Quoted 5 lines
Making this constant larger doesn't maintain that. This change also increases the size of struct vdo (in
vdo.h) by about 50 bytes. While that's not a lot, it does seem unnecessary.In practice, we know that the our module name is only about 6 bytes, and the instance number will never be more than 3, so snprintf will never actually truncate anything here. Would checking for a non-zero return value suppress the error?
I'm also confused because I don't understand the difference between this line and the similar use of snprintf at
drivers/md/dm-vdo/funnel-workqueue.c:430, which I presume does not trigger a warning?For that snprintf usage, the compiler just doesn't know the possible length of @name, as it is a pointer. That is why it is a good reason to use snprintf.
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Anyway, I'd be happy with a version that suppresses the warning without changing the size of any structures.
Matt Sakai
Thanks,
John
Matt
Quoted 3 lines · Matthew Sakai
Quoted 1 line
BTW, as I understand, for
CONFIG_DM_VDO=m, the module name is "dm_vdo". So why differentMODULE_NAMEif MODULE is not defined ("dm- vdo")?That is a historical artifact and it should just get removed. The module name should just be a constant string. I could write up a patch to do this if you don't want to.
Yes, please do when you get a chance.
Thanks
Quoted 3 lines
It might take me a couple of days though because I'm still dealing with some holiday backlog.
Even after we do this, I still think the prefix string should no longer rely on the module name.
Matthew Sakai
maintainerIt took longer than I had hoped, but the patch I just sent should fix the warning as well as simplifying the thread names.
Quoted 13 lines · John Garry
Quoted 3 lines · Matthew Sakai
Quoted 1 line
BTW, as I understand, for
CONFIG_DM_VDO=m, the module name is "dm_vdo". So why differentMODULE_NAMEif MODULE is not defined ("dm- vdo")?That is a historical artifact and it should just get removed. The module name should just be a constant string. I could write up a patch to do this if you don't want to.
Yes, please do when you get a chance.
Thanks
Quoted 3 lines
It might take me a couple of days though because I'm still dealing with some holiday backlog.
Even after we do this, I still think the prefix string should no longer rely on the module name.