Prev: [PATCH] ext2: return -ENODATA for NULL i_file_acl in ext2_xattr_list
Next: [PATCH]trivial: clear the comment on parameters for ext2_xattr_set
From: Dan Carpenter on 13 Jul 2010 11:00 On Mon, Jul 12, 2010 at 10:29:09PM +0800, crosslonelyover wrote: > Hi, > I walked through ext2_xattr_get, and felt that we can > do some optimization on it. For name_len check, it's done > after down xattr_sem and sb_read, both of which are time > consuming operation compared with strlen: > down_read(&EXT2_I(inode)->xattr_sem); > ... > bh = sb_bread(inode->i_sb, EXT2_I(inode)->i_file_acl); > ... > /* find named attribute */ > name_len = strlen(name); > > error = -ERANGE; > if (name_len > 255) > goto cleanup; > > Most of the case, you'll get one valid block, but if the > name len > 255, then the xattr_sem down and sb_bread operation > can be seen as a waste of time. So I think we'd better do > name len check as early as possible. > Following is my patch, and it's against 2.6.35-rc4. > Please check it. > > Signed-off-by: Wang Sheng-Hui <crosslonelyover(a)gmail.com> > --- > fs/ext2/xattr.c | 12 +++++++----- > 1 files changed, 7 insertions(+), 5 deletions(-) For what it's worth, this change looks OK to me. Reviewed-by: Dan Carpenter <error27(a)gmail.com> regards, dan carpenter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
From: Jan Kara on 21 Jul 2010 13:50
> Hi, > I walked through ext2_xattr_get, and felt that we can > do some optimization on it. For name_len check, it's done > after down xattr_sem and sb_read, both of which are time > consuming operation compared with strlen: > down_read(&EXT2_I(inode)->xattr_sem); > ... > bh = sb_bread(inode->i_sb, EXT2_I(inode)->i_file_acl); > ... > /* find named attribute */ > name_len = strlen(name); > > error = -ERANGE; > if (name_len > 255) > goto cleanup; > > Most of the case, you'll get one valid block, but if the > name len > 255, then the xattr_sem down and sb_bread operation > can be seen as a waste of time. So I think we'd better do > name len check as early as possible. > Following is my patch, and it's against 2.6.35-rc4. > Please check it. > > Signed-off-by: Wang Sheng-Hui <crosslonelyover(a)gmail.com> > --- > fs/ext2/xattr.c | 12 +++++++----- > 1 files changed, 7 insertions(+), 5 deletions(-) > > diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c > index 7c39157..0b94d61 100644 > --- a/fs/ext2/xattr.c > +++ b/fs/ext2/xattr.c > @@ -161,6 +161,13 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name, > > if (name == NULL) > return -EINVAL; > + > + /* find named attribute */ > + name_len = strlen(name); > + error = -ERANGE; > + if (name_len > 255) > + goto cleanup; But you cannot go to cleanup here because you don't hold xattr_sem... Honza > + > down_read(&EXT2_I(inode)->xattr_sem); > error = -ENODATA; > if (!EXT2_I(inode)->i_file_acl) -- Jan Kara <jack(a)suse.cz> SuSE CR Labs -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ |