2017-08-19 11:46:32

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/2] fs-ext4: Adjustments for two function implementations

From: Markus Elfring <[email protected]>
Date: Sat, 19 Aug 2017 13:35:43 +0200

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Delete an error message for a failed memory allocation in ext4_multi_mount_protect()
Improve a size determination in two functions

fs/ext4/dir.c | 2 +-
fs/ext4/mmp.c | 7 +++----
2 files changed, 4 insertions(+), 5 deletions(-)

--
2.14.0


2017-08-19 11:47:48

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/2] ext4: Delete an error message for a failed memory allocation in ext4_multi_mount_protect()

From: Markus Elfring <[email protected]>
Date: Sat, 19 Aug 2017 13:04:50 +0200

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
fs/ext4/mmp.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
index eb9835638680..1ce00453f612 100644
--- a/fs/ext4/mmp.c
+++ b/fs/ext4/mmp.c
@@ -371,7 +371,6 @@ int ext4_multi_mount_protect(struct super_block *sb,
- if (!mmpd_data) {
- ext4_warning(sb, "not enough memory for mmpd_data");
+ if (!mmpd_data)
goto failed;
- }
+
mmpd_data->sb = sb;
mmpd_data->bh = bh;

--
2.14.0

2017-08-19 11:49:01

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/2] ext4: Improve a size determination in two functions

From: Markus Elfring <[email protected]>
Date: Sat, 19 Aug 2017 13:14:26 +0200

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
fs/ext4/dir.c | 2 +-
fs/ext4/mmp.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index e8b365000d73..b04e882179c6 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -411,7 +411,7 @@ static struct dir_private_info *ext4_htree_create_dir_info(struct file *filp,
{
struct dir_private_info *p;

- p = kzalloc(sizeof(struct dir_private_info), GFP_KERNEL);
+ p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p)
return NULL;
p->curr_hash = pos2maj_hash(filp, pos);
diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
index 1ce00453f612..3fa5df9f5573 100644
--- a/fs/ext4/mmp.c
+++ b/fs/ext4/mmp.c
@@ -367,5 +367,5 @@ int ext4_multi_mount_protect(struct super_block *sb,
goto failed;
}

- mmpd_data = kmalloc(sizeof(struct mmpd_data), GFP_KERNEL);
+ mmpd_data = kmalloc(sizeof(*mmpd_data), GFP_KERNEL);
if (!mmpd_data)
--
2.14.0

2017-08-19 17:08:32

by Eric Sandeen

[permalink] [raw]
Subject: Re: [PATCH 1/2] ext4: Delete an error message for a failed memory allocation in ext4_multi_mount_protect()

On 8/19/17 6:47 AM, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Sat, 19 Aug 2017 13:04:50 +0200
>
> Omit an extra message for a memory allocation failure in this function.

I might be dense, but what makes this message "extra?"

(I suppose kmalloc squawks too if it fails, but is Coccinelle
now warning about explicit memory allocation failure warnings?)

-Eric

> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> fs/ext4/mmp.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
> index eb9835638680..1ce00453f612 100644
> --- a/fs/ext4/mmp.c
> +++ b/fs/ext4/mmp.c
> @@ -371,7 +371,6 @@ int ext4_multi_mount_protect(struct super_block *sb,
> - if (!mmpd_data) {
> - ext4_warning(sb, "not enough memory for mmpd_data");
> + if (!mmpd_data)
> goto failed;
> - }
> +
> mmpd_data->sb = sb;
> mmpd_data->bh = bh;
>
>

2017-08-19 18:00:44

by SF Markus Elfring

[permalink] [raw]
Subject: Re: ext4: Delete an error message for a failed memory allocation in ext4_multi_mount_protect()

>> Omit an extra message for a memory allocation failure in this function.
>
> I might be dense, but what makes this message "extra?"
>
> (I suppose kmalloc squawks too if it fails,

Do you find the default allocation failure report sufficient?


> but is Coccinelle now warning about explicit memory allocation failure warnings?)

This software tool can help to find source code places for further
development considerations. Would you like to clarify a corresponding
search pattern a bit more?

Regards,
Markus

2017-08-20 01:49:23

by Eric Sandeen

[permalink] [raw]
Subject: Re: [PATCH 2/2] ext4: Improve a size determination in two functions

On 8/19/17 6:48 AM, SF Markus Elfring wrote:
> From: Markus Elfring <[email protected]>
> Date: Sat, 19 Aug 2017 13:14:26 +0200
>
> Replace the specification of data structures by pointer dereferences
> as the parameter for the operator "sizeof" to make the corresponding size
> determination a bit safer according to the Linux coding style convention.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>

Looks good,

Reviewed-by: Eric Sandeen <[email protected]>

> ---
> fs/ext4/dir.c | 2 +-
> fs/ext4/mmp.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
> index e8b365000d73..b04e882179c6 100644
> --- a/fs/ext4/dir.c
> +++ b/fs/ext4/dir.c
> @@ -411,7 +411,7 @@ static struct dir_private_info *ext4_htree_create_dir_info(struct file *filp,
> {
> struct dir_private_info *p;
>
> - p = kzalloc(sizeof(struct dir_private_info), GFP_KERNEL);
> + p = kzalloc(sizeof(*p), GFP_KERNEL);
> if (!p)
> return NULL;
> p->curr_hash = pos2maj_hash(filp, pos);
> diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
> index 1ce00453f612..3fa5df9f5573 100644
> --- a/fs/ext4/mmp.c
> +++ b/fs/ext4/mmp.c
> @@ -367,5 +367,5 @@ int ext4_multi_mount_protect(struct super_block *sb,
> goto failed;
> }
>
> - mmpd_data = kmalloc(sizeof(struct mmpd_data), GFP_KERNEL);
> + mmpd_data = kmalloc(sizeof(*mmpd_data), GFP_KERNEL);
> if (!mmpd_data)
>

2017-08-24 17:44:50

by Theodore Ts'o

[permalink] [raw]
Subject: Re: ext4: Delete an error message for a failed memory allocation in ext4_multi_mount_protect()

On Sat, Aug 19, 2017 at 08:00:31PM +0200, SF Markus Elfring wrote:
> >> Omit an extra message for a memory allocation failure in this function.
> >
> > I might be dense, but what makes this message "extra?"
> >
> > (I suppose kmalloc squawks too if it fails,
>
> Do you find the default allocation failure report sufficient?

>From a helpdesk reporting situation, having a more specific message
when there is a MMP failure causing the mount to fail is definitely
useful.

So, NACK.

- Ted

2017-08-24 17:50:44

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 2/2] ext4: Improve a size determination in two functions

On Sat, Aug 19, 2017 at 08:49:20PM -0500, Eric Sandeen wrote:
> On 8/19/17 6:48 AM, SF Markus Elfring wrote:
> > From: Markus Elfring <[email protected]>
> > Date: Sat, 19 Aug 2017 13:14:26 +0200
> >
> > Replace the specification of data structures by pointer dereferences
> > as the parameter for the operator "sizeof" to make the corresponding size
> > determination a bit safer according to the Linux coding style convention.
> >
> > This issue was detected by using the Coccinelle software.
> >
> > Signed-off-by: Markus Elfring <[email protected]>
>
> Looks good,
>
> Reviewed-by: Eric Sandeen <[email protected]>

Thanks, applied.

- Ted

2017-08-24 19:17:57

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 1/2] ext4: Delete an error message for a failed memory allocation in ext4_multi_mount_protect()

On Sat, Aug 19, 2017 at 12:08:29PM -0500, Eric Sandeen wrote:
> On 8/19/17 6:47 AM, SF Markus Elfring wrote:
> > From: Markus Elfring <[email protected]>
> > Date: Sat, 19 Aug 2017 13:04:50 +0200
> >
> > Omit an extra message for a memory allocation failure in this function.
>
> I might be dense, but what makes this message "extra?"
>
> (I suppose kmalloc squawks too if it fails, but is Coccinelle
> now warning about explicit memory allocation failure warnings?)
>

Yeah... Checkpatch complains that the kmalloc squawks is enough.
"WARNING: Possible unnecessary 'out of memory' message". This
allocation is small so it's guaranteed to succeed in current kernels.

regards,
dan carpenter