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: <adalkn7j2th.fsf@cisco.com>
Date:	Sun, 22 Oct 2006 17:25:30 -0700
From:	Roland Dreier <rdreier@...co.com>
To:	Amit Choudhary <amit2030@...oo.com>
Cc:	Jan Engelhardt <jengelh@...ux01.gwdg.de>,
	Pekka Enberg <penberg@...helsinki.fi>,
	linux-kernel@...r.kernel.org
Subject: Re: Hopefully, kmalloc() will always succeed, but if it doesn't then....

 >         struct mixart_enum_connector_resp *connector;
 >         struct mixart_audio_info_req  *audio_info_req;
 >         struct mixart_audio_info_resp *audio_info;
 > 
 >         connector = kmalloc(sizeof(*connector), GFP_KERNEL);
 >         audio_info_req = kmalloc(sizeof(*audio_info_req), GFP_KERNEL);
 >         audio_info = kmalloc(sizeof(*audio_info), GFP_KERNEL);
 >         if (! connector || ! audio_info_req || ! audio_info) {
 >                 err = -ENOMEM;
 >                 goto __error;
 >         }

This is not a bug.  All of the pointers are initialized, and if
kmalloc() fails, then one of them will be set to NULL.  However,
kfree(NULL) is a perfectly fine thing to do (kfree just returns
immediately in this case).

So this is just a way of saving some tests and optimizing for the
common case when all allocations succeed.  In other words, this is
good code -- although the spacing is slightly bogus: it should be

        if (!connector || !audio_info_req || !audio_info) {

and also using __error as a label is slightly silly -- why not just
make it "error"?

 - R.
-
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