public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] fs/ufs/super.c: remove unnecessary casting
@ 2014-12-28 15:28 Fabian Frederick
  2014-12-28 15:33 ` Al Viro
  2014-12-28 16:54 ` Joe Perches
  0 siblings, 2 replies; 6+ messages in thread
From: Fabian Frederick @ 2014-12-28 15:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: Fabian Frederick, Evgeniy Dushistov, Andrew Morton

Fix the following coccinelle warning:
fs/ufs/super.c:1418:7-28: WARNING: casting value returned by memory
allocation function to (struct ufs_inode_info *) is useless.

Cc: Evgeniy Dushistov <dushistov@mail.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
 fs/ufs/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index da73801..a15798f 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -1414,8 +1414,8 @@ static struct kmem_cache * ufs_inode_cachep;
 
 static struct inode *ufs_alloc_inode(struct super_block *sb)
 {
-	struct ufs_inode_info *ei;
-	ei = (struct ufs_inode_info *)kmem_cache_alloc(ufs_inode_cachep, GFP_NOFS);
+	struct ufs_inode_info *ei = kmem_cache_alloc(ufs_inode_cachep,
+						     GFP_NOFS);
 	if (!ei)
 		return NULL;
 	ei->vfs_inode.i_version = 1;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] fs/ufs/super.c: remove unnecessary casting
  2014-12-28 15:28 [PATCH 1/1] fs/ufs/super.c: remove unnecessary casting Fabian Frederick
@ 2014-12-28 15:33 ` Al Viro
  2014-12-28 16:45   ` Joe Perches
  2014-12-28 16:54 ` Joe Perches
  1 sibling, 1 reply; 6+ messages in thread
From: Al Viro @ 2014-12-28 15:33 UTC (permalink / raw)
  To: Fabian Frederick; +Cc: linux-kernel, Evgeniy Dushistov, Andrew Morton

On Sun, Dec 28, 2014 at 04:28:29PM +0100, Fabian Frederick wrote:
> Fix the following coccinelle warning:
> fs/ufs/super.c:1418:7-28: WARNING: casting value returned by memory
> allocation function to (struct ufs_inode_info *) is useless.

... except that it makes allocations harder to grep for.  IOW, it's not
obviously an improvement and should be up to maintainer of the code in
question.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] fs/ufs/super.c: remove unnecessary casting
  2014-12-28 15:33 ` Al Viro
@ 2014-12-28 16:45   ` Joe Perches
  2014-12-28 18:21     ` Al Viro
  0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2014-12-28 16:45 UTC (permalink / raw)
  To: Al Viro; +Cc: Fabian Frederick, linux-kernel, Evgeniy Dushistov, Andrew Morton

On Sun, 2014-12-28 at 15:33 +0000, Al Viro wrote:
> On Sun, Dec 28, 2014 at 04:28:29PM +0100, Fabian Frederick wrote:
> > Fix the following coccinelle warning:
> > fs/ufs/super.c:1418:7-28: WARNING: casting value returned by memory
> > allocation function to (struct ufs_inode_info *) is useless.
> 
> ... except that it makes allocations harder to grep for.

How does it do that?

> IOW, it's not
> obviously an improvement and should be up to maintainer of the code in
> question.

That's always true in any case.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] fs/ufs/super.c: remove unnecessary casting
  2014-12-28 15:28 [PATCH 1/1] fs/ufs/super.c: remove unnecessary casting Fabian Frederick
  2014-12-28 15:33 ` Al Viro
@ 2014-12-28 16:54 ` Joe Perches
  1 sibling, 0 replies; 6+ messages in thread
From: Joe Perches @ 2014-12-28 16:54 UTC (permalink / raw)
  To: Fabian Frederick; +Cc: linux-kernel, Evgeniy Dushistov, Andrew Morton

On Sun, 2014-12-28 at 16:28 +0100, Fabian Frederick wrote:
> Fix the following coccinelle warning:
> fs/ufs/super.c:1418:7-28: WARNING: casting value returned by memory
> allocation function to (struct ufs_inode_info *) is useless.
[]
> diff --git a/fs/ufs/super.c b/fs/ufs/super.c
[]
> @@ -1414,8 +1414,8 @@ static struct kmem_cache * ufs_inode_cachep;
>  
>  static struct inode *ufs_alloc_inode(struct super_block *sb)
>  {
> -	struct ufs_inode_info *ei;
> -	ei = (struct ufs_inode_info *)kmem_cache_alloc(ufs_inode_cachep, GFP_NOFS);
> +	struct ufs_inode_info *ei = kmem_cache_alloc(ufs_inode_cachep,
> +						     GFP_NOFS);

If you insist on the blank line after declaration style,
perhaps it's better to separate the declaration from
the alloc so the alloc is on a single line like:

static struct inode *ufs_alloc_inode(struct super_block *sb)
{
	struct ufs_inode_info *ei;

	ei = kmem_cache_alloc(ufs_inode_cachep, GFP_NOFS);
	if (!ei)
		return NULL;

	ei->vfs_inode.i_version = 1;
	etc...



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] fs/ufs/super.c: remove unnecessary casting
  2014-12-28 16:45   ` Joe Perches
@ 2014-12-28 18:21     ` Al Viro
  2014-12-31  8:46       ` Fabian Frederick
  0 siblings, 1 reply; 6+ messages in thread
From: Al Viro @ 2014-12-28 18:21 UTC (permalink / raw)
  To: Joe Perches
  Cc: Fabian Frederick, linux-kernel, Evgeniy Dushistov, Andrew Morton

On Sun, Dec 28, 2014 at 08:45:44AM -0800, Joe Perches wrote:
> On Sun, 2014-12-28 at 15:33 +0000, Al Viro wrote:
> > On Sun, Dec 28, 2014 at 04:28:29PM +0100, Fabian Frederick wrote:
> > > Fix the following coccinelle warning:
> > > fs/ufs/super.c:1418:7-28: WARNING: casting value returned by memory
> > > allocation function to (struct ufs_inode_info *) is useless.
> > 
> > ... except that it makes allocations harder to grep for.
> 
> How does it do that?

search for \<struct[ 	]*$NAME[ 	]*($|[^ 	*]|[*][ 	]*[)])
generally gives a lot of interesting information (variables of that type,
members of anything having that type, sizeof, container_of, explicit casts)
with relatively little noise.

BTW, that's why I really don't like the stuff like
	struct foo *p = kmalloc(sizeof(*p), GFP_KERNEL);
It's bloody hard to spot.

In case of UFS we still catch "sizeof(struct ufs_inode_info)" in
        ufs_inode_cachep = kmem_cache_create("ufs_inode_cache",
                                             sizeof(struct ufs_inode_info),
                                             0, (SLAB_RECLAIM_ACCOUNT|
                                                SLAB_MEM_SPREAD),
                                             init_once);
which gives the obvious secondary search pattern, so it's not _that_ terrible,
but in general it's not something to do without thinking - such a cast could
be placed there exactly to make it stand out on grep.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] fs/ufs/super.c: remove unnecessary casting
  2014-12-28 18:21     ` Al Viro
@ 2014-12-31  8:46       ` Fabian Frederick
  0 siblings, 0 replies; 6+ messages in thread
From: Fabian Frederick @ 2014-12-31  8:46 UTC (permalink / raw)
  To: Joe Perches, Al Viro; +Cc: Andrew Morton, linux-kernel, Evgeniy Dushistov



> On 28 December 2014 at 19:21 Al Viro <viro@ZenIV.linux.org.uk> wrote:
>
>
> On Sun, Dec 28, 2014 at 08:45:44AM -0800, Joe Perches wrote:
> > On Sun, 2014-12-28 at 15:33 +0000, Al Viro wrote:
> > > On Sun, Dec 28, 2014 at 04:28:29PM +0100, Fabian Frederick wrote:
> > > > Fix the following coccinelle warning:
> > > > fs/ufs/super.c:1418:7-28: WARNING: casting value returned by memory
> > > > allocation function to (struct ufs_inode_info *) is useless.
> > >
> > > ... except that it makes allocations harder to grep for.
> >
> > How does it do that?
>
> search for \<struct[  ]*$NAME[        ]*($|[^         *]|[*][         ]*[)])
> generally gives a lot of interesting information (variables of that type,
> members of anything having that type, sizeof, container_of, explicit casts)
> with relatively little noise.
>
> BTW, that's why I really don't like the stuff like
>       struct foo *p = kmalloc(sizeof(*p), GFP_KERNEL);
> It's bloody hard to spot.
>
> In case of UFS we still catch "sizeof(struct ufs_inode_info)" in
>         ufs_inode_cachep = kmem_cache_create("ufs_inode_cache",
>                                              sizeof(struct ufs_inode_info),
>                                              0, (SLAB_RECLAIM_ACCOUNT|
>                                                 SLAB_MEM_SPREAD),
>                                              init_once);
> which gives the obvious secondary search pattern, so it's not _that_ terrible,
> but in general it's not something to do without thinking - such a cast could
> be placed there exactly to make it stand out on grep.

Thanks a lot for taking the time to explain the problem Al.
I'll be more careful next time.

Regards,
Fabian

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-12-31  8:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-28 15:28 [PATCH 1/1] fs/ufs/super.c: remove unnecessary casting Fabian Frederick
2014-12-28 15:33 ` Al Viro
2014-12-28 16:45   ` Joe Perches
2014-12-28 18:21     ` Al Viro
2014-12-31  8:46       ` Fabian Frederick
2014-12-28 16:54 ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox