nvme: work around -Wformat-security warning

Passing a string variable into dev_set_name() causes a warning
when building with -Wformat-security enabled:

drivers/nvme/host/core.c: In function 'nvme_cdev_add':
drivers/nvme/host/core.c:3911:9: error: format not a string literal and no format arguments [-Werror=format-security]
 3911 |         ret = dev_set_name(cdev_device, name);

Remove the temporary strings and let dev_set_name() do the
same thing internally.

Fixes: 26acdaa357 ("nvme: fix crash and memory leak during invalid cdev teardown")
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
Reviewed-by: John Garry <john.garry@linux.dev>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
This commit is contained in:
Arnd Bergmann 2026-09-16 13:44:51 +02:00 committed by Keith Busch
parent c20bba234f
commit 6b8a5367e9
3 changed files with 17 additions and 22 deletions

View File

@ -3931,9 +3931,9 @@ void nvme_cdev_del(struct cdev *cdev, struct device *cdev_device)
put_device(cdev_device);
}
int nvme_cdev_add(const char *name, struct cdev *cdev,
struct device *cdev_device,
const struct file_operations *fops, struct module *owner)
int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device,
const struct file_operations *fops, struct module *owner,
int ctrl, int head)
{
int minor, ret;
@ -3941,7 +3941,7 @@ int nvme_cdev_add(const char *name, struct cdev *cdev,
if (minor < 0)
return minor;
ret = dev_set_name(cdev_device, name);
ret = dev_set_name(cdev_device, "ng%dn%d", ctrl, head);
if (ret) {
ida_free(&nvme_ns_chr_minor_ida, minor);
return ret;
@ -3982,17 +3982,14 @@ static const struct file_operations nvme_ns_chr_fops = {
static void nvme_add_ns_cdev(struct nvme_ns *ns)
{
char name[32];
ns->cdev_device.parent = ns->ctrl->device;
snprintf(name, sizeof(name), "ng%dn%d", ns->ctrl->instance,
ns->head->instance);
nvme_get_ns(ns); /* Undone in nvme_cdev_rel() */
if (nvme_cdev_add(name, &ns->cdev, &ns->cdev_device,
&nvme_ns_chr_fops, ns->ctrl->ops->module)) {
dev_err(ns->ctrl->device, "Unable to create the %s device\n",
name);
if (nvme_cdev_add(&ns->cdev, &ns->cdev_device,
&nvme_ns_chr_fops, ns->ctrl->ops->module,
ns->ctrl->instance, ns->head->instance)) {
dev_err(ns->ctrl->device, "Unable to create the ng%dn%d device\n",
ns->ctrl->instance, ns->head->instance);
nvme_put_ns(ns);
return;
}

View File

@ -646,17 +646,15 @@ static const struct file_operations nvme_ns_head_chr_fops = {
static void nvme_add_ns_head_cdev(struct nvme_ns_head *head)
{
char name[32];
head->cdev_device.parent = &head->subsys->dev;
snprintf(name, sizeof(name), "ng%dn%d", head->subsys->instance,
head->instance);
nvme_get_ns_head(head); /* Undone in nvme_cdev_rel() */
if (nvme_cdev_add(name, &head->cdev, &head->cdev_device,
&nvme_ns_head_chr_fops, THIS_MODULE)) {
if (nvme_cdev_add(&head->cdev, &head->cdev_device,
&nvme_ns_head_chr_fops, THIS_MODULE,
head->subsys->instance, head->instance)) {
dev_err(disk_to_dev(head->disk),
"Unable to create the %s device\n", name);
"Unable to create the ng%dn%d device\n",
head->subsys->instance, head->instance);
nvme_put_ns_head(head);
return;
}

View File

@ -1013,9 +1013,9 @@ int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi,
void nvme_get_ns_head(struct nvme_ns_head *head);
bool nvme_tryget_ns_head(struct nvme_ns_head *head);
void nvme_put_ns_head(struct nvme_ns_head *head);
int nvme_cdev_add(const char *name, struct cdev *cdev,
struct device *cdev_device,
const struct file_operations *fops, struct module *owner);
int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device,
const struct file_operations *fops, struct module *owner,
int ctrl, int head);
void nvme_cdev_del(struct cdev *cdev, struct device *cdev_device);
int nvme_ioctl(struct block_device *bdev, blk_mode_t mode,
unsigned int cmd, unsigned long arg);