2014-06-12 21:05:43

by Dmitry Kasatkin

[permalink] [raw]
Subject: [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.

Signed-off-by: Dmitry Kasatkin <[email protected]>
---
drivers/base/firmware_class.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index c30df50e..9aaa97b 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -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);
--
1.9.1


2014-06-13 14:56:26

by Ming Lei

[permalink] [raw]
Subject: Re: [PATCH 1/1] firmware: read firmware size using i_size_read()

On Fri, Jun 13, 2014 at 5:05 AM, Dmitry Kasatkin
<[email protected]> wrote:
> There is no need to read attr because inode structure contains size
> of the file. Use i_size_read() instead.
>
> Signed-off-by: Dmitry Kasatkin <[email protected]>
> ---
> drivers/base/firmware_class.c | 15 +--------------
> 1 file changed, 1 insertion(+), 14 deletions(-)
>
> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
> index c30df50e..9aaa97b 100644
> --- a/drivers/base/firmware_class.c
> +++ b/drivers/base/firmware_class.c
> @@ -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);
> --

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

2014-06-13 15:10:36

by Dmitry Kasatkin

[permalink] [raw]
Subject: [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.

Signed-off-by: Dmitry Kasatkin <[email protected]>
---
drivers/base/firmware_class.c | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index d276e33..e84da14 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -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);
--
1.9.1

2014-06-13 15:10:53

by Dmitry Kasatkin

[permalink] [raw]
Subject: [PATCH v2 0/1] 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(-)

--
1.9.1

2014-06-13 16:03:14

by Ming Lei

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] firmware: read firmware size using i_size_read()

On Fri, Jun 13, 2014 at 11:09 PM, Dmitry Kasatkin
<[email protected]> wrote:
> There is no need to read attr because inode structure contains size
> of the file. Use i_size_read() instead.
>
> Signed-off-by: Dmitry Kasatkin <[email protected]>

Acked-by: Ming Lei <[email protected]>


Thanks,
--
Ming Lei

2014-06-13 16:06:32

by Dmitry Kasatkin

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] firmware: read firmware size using i_size_read()

On 13 June 2014 19:03, Ming Lei <[email protected]> wrote:
> On Fri, Jun 13, 2014 at 11:09 PM, Dmitry Kasatkin
> <[email protected]> wrote:
>> There is no need to read attr because inode structure contains size
>> of the file. Use i_size_read() instead.
>>
>> Signed-off-by: Dmitry Kasatkin <[email protected]>
>
> Acked-by: Ming Lei <[email protected]>
>
>
> Thanks,
> --
> Ming Lei

Thanks.



--
Thanks,
Dmitry

2014-06-25 16:46:46

by Dmitry Kasatkin

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] firmware: read firmware size using i_size_read()

On 13 June 2014 19:06, Dmitry Kasatkin <[email protected]> wrote:
> On 13 June 2014 19:03, Ming Lei <[email protected]> wrote:
>> On Fri, Jun 13, 2014 at 11:09 PM, Dmitry Kasatkin
>> <[email protected]> wrote:
>>> There is no need to read attr because inode structure contains size
>>> of the file. Use i_size_read() instead.
>>>
>>> Signed-off-by: Dmitry Kasatkin <[email protected]>
>>
>> Acked-by: Ming Lei <[email protected]>
>>


Hi,

BTW. To what tree it is applied?

--
Thanks,
Dmitry

2014-07-02 01:33:53

by Ming Lei

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] firmware: read firmware size using i_size_read()

On Thu, Jun 26, 2014 at 12:46 AM, Dmitry Kasatkin
<[email protected]> wrote:
> On 13 June 2014 19:06, Dmitry Kasatkin <[email protected]> wrote:
>> On 13 June 2014 19:03, Ming Lei <[email protected]> wrote:
>>> On Fri, Jun 13, 2014 at 11:09 PM, Dmitry Kasatkin
>>> <[email protected]> wrote:
>>>> There is no need to read attr because inode structure contains size
>>>> of the file. Use i_size_read() instead.
>>>>
>>>> Signed-off-by: Dmitry Kasatkin <[email protected]>
>>>
>>> Acked-by: Ming Lei <[email protected]>
>>>
>
>
> Hi,
>
> BTW. To what tree it is applied?

Greg will take it in driver-core tree.

Thanks,
--
Ming Lei

2014-07-02 05:27:44

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] firmware: read firmware size using i_size_read()

On Wed, Jul 02, 2014 at 09:33:49AM +0800, Ming Lei wrote:
> On Thu, Jun 26, 2014 at 12:46 AM, Dmitry Kasatkin
> <[email protected]> wrote:
> > On 13 June 2014 19:06, Dmitry Kasatkin <[email protected]> wrote:
> >> On 13 June 2014 19:03, Ming Lei <[email protected]> wrote:
> >>> On Fri, Jun 13, 2014 at 11:09 PM, Dmitry Kasatkin
> >>> <[email protected]> wrote:
> >>>> There is no need to read attr because inode structure contains size
> >>>> of the file. Use i_size_read() instead.
> >>>>
> >>>> Signed-off-by: Dmitry Kasatkin <[email protected]>
> >>>
> >>> Acked-by: Ming Lei <[email protected]>
> >>>
> >
> >
> > 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

2014-07-08 22:22:01

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] firmware: read firmware size using i_size_read()

On Wed, Jun 25, 2014 at 07:46:41PM +0300, Dmitry Kasatkin wrote:
> On 13 June 2014 19:06, Dmitry Kasatkin <[email protected]> wrote:
> > On 13 June 2014 19:03, Ming Lei <[email protected]> wrote:
> >> On Fri, Jun 13, 2014 at 11:09 PM, Dmitry Kasatkin
> >> <[email protected]> wrote:
> >>> There is no need to read attr because inode structure contains size
> >>> of the file. Use i_size_read() instead.
> >>>
> >>> Signed-off-by: Dmitry Kasatkin <[email protected]>
> >>
> >> Acked-by: Ming Lei <[email protected]>
> >>
>
>
> Hi,
>
> BTW. To what tree it is applied?

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