[PATCH] nvme: work around -Wformat-security warning

John Garry john.garry at linux.dev
Thu Sep 17 01:01:43 PDT 2026


On 9/16/26 12:44, Arnd Bergmann wrote:
> From: Arnd Bergmann<arnd at arndb.de>
> 
> 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.
> 

Prior to 26acdaa357cd, we had the caller of nvme_cdev_add() also calling 
dev_set_name(). Maybe it is better to revert to that (but keep the 
functionality to set NVME_NSHEAD_CDEV_LIVE). But then put_device() call 
for errors becomes a bit messy.

...

>   	}
> diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> index 2cff9fcbf740..e0260f4d24fd 100644
> --- a/drivers/nvme/host/nvme.h
> +++ b/drivers/nvme/host/nvme.h
> @@ -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);


nit: maybe @head arg would be better called "ns", as it is the "ns" index.

>   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);
> -- 2.53.0

Regardless of comments:
Reviewed-by: John Garry <john.garry at linux.dev>



More information about the Linux-nvme mailing list