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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 23 Aug 2016 13:03:15 +0200
From:   Bjørn Mork <bjorn@...k.no>
To:     "Michael S. Tsirkin" <mst@...hat.com>
Cc:     linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org,
        Jonathan Corbet <corbet@....net>,
        virtualization@...ts.linux-foundation.org,
        Julia Lawall <julia.lawall@...6.fr>,
        Dan Carpenter <dan.carpenter@...cle.com>
Subject: Re: [PATCH] CodingStyle: add some more error handling guidelines

"Michael S. Tsirkin" <mst@...hat.com> writes:

>                 foo = kmalloc(SIZE, GFP_KERNEL);
>                 if (!foo)
>                         goto err_foo;
>
>                 foo->bar = kmalloc(SIZE, GFP_KERNEL);
>                 if (!foo->bar)
>                         goto err_bar;
>                 ...
>
>                 kfree(foo->bar);
>         err_bar:
>
>                 kfree(foo);
>         err_foo:
>
>                 return ret;


I believe the CodingStyle already contain far too much personal style to
be useful as real style guide.  FWIW, I prefer a single error label, at
the "cost" of additional tests in the error path:


                 foo = kmalloc(SIZE, GFP_KERNEL);
                 if (!foo)
                         goto err;
                 foo->bar = kmalloc(SIZE, GFP_KERNEL);
                 if (!foo->bar)
                         goto err;
                 ...
 		 if (ret)
			goto err;
                 return 0;
      err:
                 if (foo)
                        kfree(foo->bar);
                 kfree(foo);
                 return ret;


The advantage is that I don't have to manage X different labels,
ensuring that they have the order is correct if some part of the
function is refactored etc.  That tends to get too complicated for my
simple brain. And since the error path is rarely tested, complicated
equals buggy.

My sample will of course trigger all those nice "optimizing the error
path" patches, but I ignore those anyway so that's not a big deal.


Bjørn

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ