Re: [PATCH v2 next] drivers/md/md: Use bounded strings ops when setting disk->disk_name

David Laight <[email protected]>
Newsgroups gmane.linux.raid
Message-ID <20260626115246.3477f614@pumpkin>
On Fri, 26 Jun 2026 08:51:40 +0000
[email protected] wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Low] Inconsistent coding style for the sizeof operator in newly added code.
> --
> 
> commit 663613700e83a5bb9c1749d80b4fae68752645fb
> Author: David Laight <[email protected]>
> 
> drivers/md/md: Use bounded strings ops when setting disk->disk_name
> 
> This commit replaces unbounded strcpy() and sprintf() with bounded strscpy()
> and snprintf() operations when setting the disk_name in md_alloc() to improve
> safety.
> 
> > diff --git a/drivers/md/md.c b/drivers/md/md.c
> > index d1465bcd86c81..afbdc52a11270 100644
> > --- a/drivers/md/md.c
> > +++ b/drivers/md/md.c
> > @@ -6354,11 +6354,11 @@ struct mddev *md_alloc(dev_t dev, char *name)  
> [ ... ]
> >  	if (name)
> > -		strcpy(disk->disk_name, name);
> > +		strscpy(disk->disk_name, name);
> >  	else if (partitioned)
> > -		sprintf(disk->disk_name, "md_d%d", unit);
> > +		snprintf(disk->disk_name, sizeof(disk->disk_name), "md_d%d", unit);
> >  	else
> > -		sprintf(disk->disk_name, "md%d", unit);
> > +		snprintf(disk->disk_name, sizeof (disk->disk_name), "md%d", unit);  
> 
> [Severity: Low]
> This isn't a bug, but there is an inconsistent coding style for the sizeof
> operator here in md_alloc(). The adjacent branch uses sizeof(disk->disk_name)
> without a space, while this newly added branch includes a space. The kernel
> coding style prefers no space after sizeof.
> 

B****r I only fixed one of them :-(

	David
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.