Skip to contentSkip to conversation

firmware: read firmware size using i_size_read()

PATCH In review Dmitry Kasatkin 4 participants 10 messages Jun 12, 2014 – Jul 8, 2014 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware: read firmware size using i_size_read()

There is no need to read attr because inode structure contains size of the file. Use i_size_read() instead.

---
 drivers/base/firmware_class.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/base/firmware_class.c +1 -14
index c30df50e..9aaa97b 100644
@@ -279,26 +279,13 @@ static const char * const fw_path[] = {
 module_param_string(path, fw_path_para, sizeof(fw_path_para), 0644);
 MODULE_PARM_DESC(path, "customized firmware image search path with a higher priority than default path");
 
-/* Don't inline this: 'struct kstat' is biggish */
-static noinline_for_stack int fw_file_size(struct file *file)
-{
-	struct kstat st;
-	if (vfs_getattr(&file->f_path, &st))
-		return -1;
-	if (!S_ISREG(st.mode))
-		return -1;
-	if (st.size != (int)st.size)
-		return -1;
-	return st.size;
-}
-
 static int fw_read_file_contents(struct file *file, struct firmware_buf *fw_buf)
 {
 	int size;
 	char *buf;
 	int rc;
 
-	size = fw_file_size(file);
+	size = i_size_read(file_inode(file));
 	if (size <= 0)
 		return -EINVAL;
 	buf = vmalloc(size);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 31 lines · Dmitry Kasatkin

There is no need to read attr because inode structure contains size of the file. Use i_size_read() instead.

---
 drivers/base/firmware_class.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/base/firmware_class.c +0 -13
index c30df50e..9aaa97b 100644
@@ -279,26 +279,13 @@ static const char * const fw_path[] = {
 module_param_string(path, fw_path_para, sizeof(fw_path_para), 0644);
 MODULE_PARM_DESC(path, "customized firmware image search path with a higher priority than default path");
 
-/* Don't inline this: 'struct kstat' is biggish */
-static noinline_for_stack int fw_file_size(struct file *file)
-{
-       struct kstat st;
-       if (vfs_getattr(&file->f_path, &st))
-               return -1;
-       if (!S_ISREG(st.mode))
-               return -1;
-       if (st.size != (int)st.size)
-               return -1;
-       return st.size;
-}
-
 static int fw_read_file_contents(struct file *file, struct firmware_buf *fw_buf)
 {

drivers/base/firmware_class.c static const char * const fw_path[] = {

Quoted 10 lines
drivers/base/firmware_class.c +1 -2
        int size;
        char *buf;
        int rc;
 
-       size = fw_file_size(file);
+       size = i_size_read(file_inode(file));
        if (size <= 0)
                return -EINVAL;
        buf = vmalloc(size);
--

fw_file_size() not only return size of the file, but also check if it is a regular file, and its size.

Thanks,
--
Ming Lei

#2 lore raw

v2 cover read firmware size using i_size_read()

Hi,

You are right about file type.
inode structure also contains information about file type.. There is no need to use vfs_getattr().

Thanks,
Dmitry

Dmitry Kasatkin (1):
firmware: read firmware size using i_size_read()

 drivers/base/firmware_class.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
Signature · 1 line
1.9.1
#3 lore raw

PATCH v2 1/1 firmware: read firmware size using i_size_read()

There is no need to read attr because inode structure contains size of the file. Use i_size_read() instead.

---
 drivers/base/firmware_class.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/base/firmware_class.c +3 -14
index d276e33..e84da14 100644
@@ -279,26 +279,15 @@ static const char * const fw_path[] = {
 module_param_string(path, fw_path_para, sizeof(fw_path_para), 0644);
 MODULE_PARM_DESC(path, "customized firmware image search path with a higher priority than default path");
 
-/* Don't inline this: 'struct kstat' is biggish */
-static noinline_for_stack int fw_file_size(struct file *file)
-{
-	struct kstat st;
-	if (vfs_getattr(&file->f_path, &st))
-		return -1;
-	if (!S_ISREG(st.mode))
-		return -1;
-	if (st.size != (int)st.size)
-		return -1;
-	return st.size;
-}
-
 static int fw_read_file_contents(struct file *file, struct firmware_buf *fw_buf)
 {
 	int size;
 	char *buf;
 	int rc;
 
-	size = fw_file_size(file);
+	if (!S_ISREG(file_inode(file)->i_mode))
+		return -EINVAL;
+	size = i_size_read(file_inode(file));
 	if (size <= 0)
 		return -EINVAL;
 	buf = vmalloc(size);
Signature · 1 line
1.9.1
#7 lore raw
Quoted 9 lines · Dmitry Kasatkin
Quoted 8 lines · Dmitry Kasatkin
Quoted 7 lines · Ming Lei
Quoted 4 lines · Dmitry Kasatkin

There is no need to read attr because inode structure contains size of the file. Use i_size_read() instead.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Hi,

BTW. To what tree it is applied?

Greg will take it in driver-core tree.

Thanks,
--
Ming Lei

#8 lore raw
Quoted 15 lines · Ming Lei
Quoted 13 lines · Dmitry Kasatkin
Quoted 10 lines · Dmitry Kasatkin
Quoted 9 lines · Ming Lei
Quoted 4 lines · Dmitry Kasatkin

There is no need to read attr because inode structure contains size of the file. Use i_size_read() instead.

Quoted 5 lines
Quoted 3 lines

Hi,

BTW. To what tree it is applied?

Greg will take it in driver-core tree.

Yes, I'll catch up on pending patches next week, thanks.

greg k-h

#9 lore raw
In reply to Dmitry Kasatkin
Quoted 9 lines · Dmitry Kasatkin
Quoted 8 lines · Dmitry Kasatkin
Quoted 7 lines · Ming Lei
Quoted 4 lines · Dmitry Kasatkin

There is no need to read attr because inode structure contains size of the file. Use i_size_read() instead.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Hi,

BTW. To what tree it is applied?

Mine now, you should get an email soon...