* [PATCH] fs: Prefer strlcpy() over snprintf()
@ 2008-05-09 11:42 Jean Delvare
2008-05-09 12:15 ` Steven Whitehouse
0 siblings, 1 reply; 3+ messages in thread
From: Jean Delvare @ 2008-05-09 11:42 UTC (permalink / raw)
To: LKML; +Cc: Joel Becker, Steven Whitehouse, Andries Brouwer
strlcpy is faster than snprintf when you don't use the returned value.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Andries Brouwer <aeb@cwi.nl>
---
A quick grep suggests that there's about 80 more similar cases in the kernel
tree which could be fixed.
fs/configfs/dir.c | 2 +-
fs/gfs2/ops_fstype.c | 4 ++--
fs/partitions/check.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
--- linux-2.6.26-rc1.orig/fs/configfs/dir.c 2008-05-09 12:52:51.000000000 +0200
+++ linux-2.6.26-rc1/fs/configfs/dir.c 2008-05-09 13:20:24.000000000 +0200
@@ -1041,7 +1041,7 @@ static int configfs_mkdir(struct inode *
goto out_put;
}
- snprintf(name, dentry->d_name.len + 1, "%s", dentry->d_name.name);
+ strlcpy(name, dentry->d_name.name, dentry->d_name.len + 1);
mutex_lock(&subsys->su_mutex);
group = NULL;
--- linux-2.6.26-rc1.orig/fs/gfs2/ops_fstype.c 2008-05-09 12:52:51.000000000 +0200
+++ linux-2.6.26-rc1/fs/gfs2/ops_fstype.c 2008-05-09 13:20:24.000000000 +0200
@@ -142,8 +142,8 @@ static int init_names(struct gfs2_sbd *s
if (!table[0])
table = sdp->sd_vfs->s_id;
- snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto);
- snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table);
+ strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN);
+ strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN);
table = sdp->sd_table_name;
while ((table = strchr(table, '/')))
--- linux-2.6.26-rc1.orig/fs/partitions/check.c 2008-05-09 12:52:51.000000000 +0200
+++ linux-2.6.26-rc1/fs/partitions/check.c 2008-05-09 13:20:24.000000000 +0200
@@ -123,7 +123,7 @@ static int (*check_part[])(struct parsed
char *disk_name(struct gendisk *hd, int part, char *buf)
{
if (!part)
- snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name);
+ strlcpy(buf, hd->disk_name, BDEVNAME_SIZE);
else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1]))
snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, part);
else
--
Jean Delvare
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fs: Prefer strlcpy() over snprintf()
2008-05-09 11:42 [PATCH] fs: Prefer strlcpy() over snprintf() Jean Delvare
@ 2008-05-09 12:15 ` Steven Whitehouse
2008-05-09 15:35 ` Jean Delvare
0 siblings, 1 reply; 3+ messages in thread
From: Steven Whitehouse @ 2008-05-09 12:15 UTC (permalink / raw)
To: Jean Delvare; +Cc: LKML, Joel Becker, Andries Brouwer
Hi,
The patch looks good, but could you break this into bits? Its easier for
me just to put the GFS2 bit through my git tree and the other bits
should probably go via another route,
Steve.
On Fri, 2008-05-09 at 13:42 +0200, Jean Delvare wrote:
> strlcpy is faster than snprintf when you don't use the returned value.
>
> Signed-off-by: Jean Delvare <khali@linux-fr.org>
> Cc: Joel Becker <joel.becker@oracle.com>
> Cc: Steven Whitehouse <swhiteho@redhat.com>
> Cc: Andries Brouwer <aeb@cwi.nl>
> ---
> A quick grep suggests that there's about 80 more similar cases in the kernel
> tree which could be fixed.
>
> fs/configfs/dir.c | 2 +-
> fs/gfs2/ops_fstype.c | 4 ++--
> fs/partitions/check.c | 2 +-
> 3 files changed, 4 insertions(+), 4 deletions(-)
>
> --- linux-2.6.26-rc1.orig/fs/configfs/dir.c 2008-05-09 12:52:51.000000000 +0200
> +++ linux-2.6.26-rc1/fs/configfs/dir.c 2008-05-09 13:20:24.000000000 +0200
> @@ -1041,7 +1041,7 @@ static int configfs_mkdir(struct inode *
> goto out_put;
> }
>
> - snprintf(name, dentry->d_name.len + 1, "%s", dentry->d_name.name);
> + strlcpy(name, dentry->d_name.name, dentry->d_name.len + 1);
>
> mutex_lock(&subsys->su_mutex);
> group = NULL;
> --- linux-2.6.26-rc1.orig/fs/gfs2/ops_fstype.c 2008-05-09 12:52:51.000000000 +0200
> +++ linux-2.6.26-rc1/fs/gfs2/ops_fstype.c 2008-05-09 13:20:24.000000000 +0200
> @@ -142,8 +142,8 @@ static int init_names(struct gfs2_sbd *s
> if (!table[0])
> table = sdp->sd_vfs->s_id;
>
> - snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto);
> - snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table);
> + strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN);
> + strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN);
>
> table = sdp->sd_table_name;
> while ((table = strchr(table, '/')))
> --- linux-2.6.26-rc1.orig/fs/partitions/check.c 2008-05-09 12:52:51.000000000 +0200
> +++ linux-2.6.26-rc1/fs/partitions/check.c 2008-05-09 13:20:24.000000000 +0200
> @@ -123,7 +123,7 @@ static int (*check_part[])(struct parsed
> char *disk_name(struct gendisk *hd, int part, char *buf)
> {
> if (!part)
> - snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name);
> + strlcpy(buf, hd->disk_name, BDEVNAME_SIZE);
> else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1]))
> snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, part);
> else
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fs: Prefer strlcpy() over snprintf()
2008-05-09 12:15 ` Steven Whitehouse
@ 2008-05-09 15:35 ` Jean Delvare
0 siblings, 0 replies; 3+ messages in thread
From: Jean Delvare @ 2008-05-09 15:35 UTC (permalink / raw)
To: Steven Whitehouse; +Cc: LKML, Joel Becker, Andries Brouwer
Hi Steven,
On Fri, 09 May 2008 13:15:54 +0100, Steven Whitehouse wrote:
> The patch looks good, but could you break this into bits? Its easier for
> me just to put the GFS2 bit through my git tree and the other bits
> should probably go via another route,
Thanks for the review. No problem, I'll split the patch and send the
individual bits to their respective maintainers now.
--
Jean Delvare
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-05-09 15:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-09 11:42 [PATCH] fs: Prefer strlcpy() over snprintf() Jean Delvare
2008-05-09 12:15 ` Steven Whitehouse
2008-05-09 15:35 ` Jean Delvare
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox