Re: ntfs: remove redundant assignments

From: Al Viro (viro_at_parcelfarce.linux.theplanet.co.uk)
Date: 05/26/05

  • Next message: Martin J. Bligh: "Re: 2.6.12-rc5-mm1"
    Date:	Thu, 26 May 2005 08:04:38 +0100
    To: Pekka J Enberg <penberg@cs.helsinki.fi>
    
    

    On Thu, May 26, 2005 at 09:21:46AM +0300, Pekka J Enberg wrote:
    > 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?

    Oh, come on...

            ictx = kmalloc(sizeof(ntfs_index_context), GFP_NOFS);
            if (ictx)
                    *ictx = (ntfs_index_context){.idx_ni = idx_ni};
            return ictx;

    and be done with that. Let compiler do its job. And yes, that *will*
    give properly initialized pointers even for weird platforms. Not that
    we had the slightest chance of porting to any of them...

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

    So use the proper constructs. Variant above is guaranteed to do the right
    thing on any C99 compiler, provided that kmalloc() returns NULL or pointer
    to object sufficiently large and properly aligned for ntfs_index_context.
    All missing fields will be initialized the same way they would for initializer
    of a static object.
    -
    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: Martin J. Bligh: "Re: 2.6.12-rc5-mm1"

    Relevant Pages

    • Re: regarding dynamic allocation for pointers
      ... Richard Heathfield wrote: ... which is why one must always explicitly initialize pointers ... in dynamically-allocated memory, typically to NULL. ...
      (comp.lang.c)
    • Re: freevxfs: minor cleanups
      ... memset() doesn't really initialize pointers properly. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Issue with qla2xxx_probe_one
      ... DEBUG2: Failed to initialize ... Ensure proper handling of the scsi free_list handling upon errors ... struct scsi_cmnd *cmd; ...
      (Linux-Kernel)
    • SUMMARY: Graphics console will not initialize
      ... This caused the hardware not to initialize properly thus ... preventing the proper build of the new kernel. ... Graphics console will not initialize ...
      (Tru64-UNIX-Managers)
    • Re: Problem: how to sequence reset of PCI hardware
      ... > space reset program from a driver's probe function except with an ... You either need to execute the video BIOS to initialize the hardware ... or initialize the hardware registers themselves. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)