lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20080813091417.GH23417@elte.hu>
Date:	Wed, 13 Aug 2008 11:14:17 +0200
From:	Ingo Molnar <mingo@...e.hu>
To:	Andrew Morton <akpm@...ux-foundation.org>
Cc:	Shaohua Li <shaohua.li@...el.com>,
	lkml <linux-kernel@...r.kernel.org>,
	Arjan van de Ven <arjan@...radead.org>
Subject: Re: [patch]fastboot: remove duplicate unpack_to_rootfs()


* Andrew Morton <akpm@...ux-foundation.org> wrote:

> On Wed, 13 Aug 2008 09:52:36 +0200 Ingo Molnar <mingo@...e.hu> wrote:
> 
> > no-newline-before-return:
> > 
> >          kfree(header_buf);
> >          return message;
> >  }
> 
> I accidentally delete those newlines when nobody is looking.  They 
> don't seem worth the space they consume.

yeah - for me it's case-dependent. My benchmark for it is absolutely 
objective and easy to describe: i add a newline when it looks nicer and 
more maintainable that way ;-)

> (what do we do with a function which has multiple `return's?)

i really didnt want to make a full scale style discussion out of this. 
Lets ignore my suggestion. The valid case when i use a newline is for 
example when the return obscures what happens:

	if (something) {
		do_one();
		repeat_this();
		return;
	}

as visually it's easy to miss the return - especially if the lines above 
it look similar. So i use:

	if (something) {
		do_one();
		repeat_this();

		return;
	}

because way too often do i miss a stray return somewhere and 
misunderstand the code flow of a function if it does not stand out, even 
with syntax highlighting.

Another case is when there's a long linear block of cleanup statements 
followed by a return:

        q->mode = mode;
        strcpy(q->name, name);
        q->next = NULL;
        *p = q;
        return NULL;
}

i usually add a newline:

        q->mode = mode;
        strcpy(q->name, name);
        q->next = NULL;
        *p = q;

        return NULL;
}

as the 'return NULL' is a separate concept from the preceding 
activities.

So in this case it is not really because the return is specialy, this is 
because i like to separate groups of statements per type of activity. So 
i'd do the same if there were two groups of statements, i'd turn this:

        q->mode = mode;
        strcpy(q->name, name);
        q->next = NULL;
        *p = q;
	other_stuff = 2;
	some_other_stuff(other_stuff)

into this:

        q->mode = mode;
        strcpy(q->name, name);
        q->next = NULL;
        *p = q;

	other_stuff = 2;
	some_other_stuff(other_stuff)

to make sure the two groups of statements stand out. (Sometimes a pure 
newline does a better job at inserting the right kind of visual 
structure than a comment line.)

but again ... these are nuances where reasonable people might disagree, 
and i only made them because this topic lives, is developed and tested 
in tip/fastboot at the moment.

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ