Re: ntfs: remove redundant assignments

From: Pekka J Enberg (penberg_at_cs.helsinki.fi)
Date: 05/26/05

  • Next message: Shaohua Li: "Swsusp trival fix"
    To: Anton Altaparmakov <aia21@cam.ac.uk>
    Date:	Thu, 26 May 2005 09:21:46 +0300
    
    

    Hi Anton,

    At some point in time, I wrote:
    > Index: 2.6-mm/fs/ntfs/super.c
    > > ===================================================================
    > > --- 2.6-mm.orig/fs/ntfs/super.c 2005-05-25 20:51:57.000000000 +0300
    > > +++ 2.6-mm/fs/ntfs/super.c 2005-05-25 20:54:02.000000000 +0300
    > > @@ -2283,7 +2283,7 @@
    > > sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
    > > #endif /* ! NTFS_RW */
    > > /* Allocate a new ntfs_volume and place it in sb->s_fs_info. */
    > > - sb->s_fs_info = kmalloc(sizeof(ntfs_volume), GFP_NOFS);
    > > + sb->s_fs_info = kcalloc(1, sizeof(ntfs_volume), GFP_NOFS);
    > > vol = NTFS_SB(sb);
    > > if (!vol) {
    > > if (!silent)
    > > @@ -2292,28 +2292,9 @@
    > > return -ENOMEM;
    > > }
    > > /* Initialize ntfs_volume structure. */
    > > - memset(vol, 0, sizeof(ntfs_volume));
    > > vol->sb = sb;
    >
    > The above is fine, thanks.
    >
    > > - vol->upcase = NULL;
    > > - vol->attrdef = NULL;
    > > - vol->mft_ino = NULL;
    > > - vol->mftbmp_ino = NULL;
    > > init_rwsem(&vol->mftbmp_lock);
    > > -#ifdef NTFS_RW
    > > - vol->mftmirr_ino = NULL;
    > > - vol->logfile_ino = NULL;
    > > -#endif /* NTFS_RW */
    > > - vol->lcnbmp_ino = NULL;
    > > init_rwsem(&vol->lcnbmp_lock);
    > > - vol->vol_ino = NULL;
    > > - vol->root_ino = NULL;
    > > - vol->secure_ino = NULL;
    > > - vol->extend_ino = NULL;
    > > -#ifdef NTFS_RW
    > > - vol->quota_ino = NULL;
    > > - vol->quota_q_ino = NULL;
    > > -#endif /* NTFS_RW */
    > > - vol->nls_map = NULL;

    On Wed, 2005-05-25 at 22:10 +0100, Anton Altaparmakov wrote:
    > This is not. memset(0) is not the same as = NULL IMO. I don't care if
    > the compiler thinks it is the same. NULL does not have to be 0 so I
    > prefer to initialize pointers explicitly to NULL. Even more so since this
    > code is not performance critical at all so I prefer clarity here.

    I kind of figured out you were doing it on purpose. The fact is, NULL is
    zero on _all_ Linux architectures. If it weren't, we'd have a lot of broken
    code. Let me play the devils advocate here: why do you memset() (now
    kcalloc()) in the first place?

    At some point in time, I wrote:
    > > Index: 2.6-mm/fs/ntfs/index.c
    > > ===================================================================
    > > --- 2.6-mm.orig/fs/ntfs/index.c 2005-05-25 20:51:57.000000000 +0300
    > > +++ 2.6-mm/fs/ntfs/index.c 2005-05-25 21:07:38.000000000 +0300
    > > @@ -40,16 +40,8 @@
    > >
    > > ictx = kmem_cache_alloc(ntfs_index_ctx_cache, SLAB_NOFS);
    > > if (ictx) {
    > > + memset(ictx, 0, sizeof(*ictx));
    > > ictx->idx_ni = idx_ni;
    > > - ictx->entry = NULL;
    > > - ictx->data = NULL;
    > > - ictx->data_len = 0;
    > > - ictx->is_in_root = 0;
    > > - ictx->ir = NULL;
    > > - ictx->actx = NULL;
    > > - ictx->base_ni = NULL;
    > > - ictx->ia = NULL;
    > > - ictx->page = NULL;

    On Wed, 2005-05-25 at 22:10 +0100, Anton Altaparmakov wrote:
    > Again, as above, I prefer to have the explicit = NULL instead of a memset.

    There's a simple reason why I don't like explicit assignments: it's way too
    easy to forget to initialize something.

                            Pekka
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Shaohua Li: "Swsusp trival fix"

    Relevant Pages

    • Re: Suggested Alternative Unicode Implementation (for Rudy+ miscothers)
      ... usually don't when automagic casting happens). ... There will be the implicit cast warnings. ... default) enable that will kick in even in the case of explicit casting ... decide how "noisy" they want the compiler to be and what they'll ...
      (borland.public.delphi.non-technical)
    • Re: Standards interpretation: interface and intent?
      ... >> Usually though if something is passed, that makes it explicit. ... >> application programmer didn't provide it, ... It's explicit to the compiler. ... Liberty is a well armed sheep contesting the vote. ...
      (comp.lang.fortran)
    • Re: Teaching new tricks to an old dog (C++ -->Ada)
      ... Wes Groleau writes: ... I'm a compiler writer. ... To optimize-away a check, whether explicit or implicit, ... > Answer not a fool according to his folly, ...
      (comp.lang.ada)
    • Re: [patch] generic-hardirqs.patch, 2.6.9-rc1-bk14
      ... > make explicit what you can do easily instead of relying on the ... > compiler. ... It allows to get rid of your horrible generic_ hacks, ... and the architecture with conditionals. ...
      (Linux-Kernel)
    • Re: Thou shalt have no other gods before the ANSI C standard
      ... >> Sorry, hate implicit stuff, prefer explicit, that even the typical ... >This would make a difference with one compiler I came across. ... To be sure, the problem was in the "frozen config file" kludge, not in the ... but your comment reminded me of this security hole anyway. ...
      (sci.crypt)