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: <5d5acba098bda3bbc8aebb5e86b9c53f986f1a72.camel@HansenPartnership.com>
Date: Wed, 19 Mar 2025 16:15:34 -0400
From: James Bottomley <James.Bottomley@...senPartnership.com>
To: Thomas Gleixner <tglx@...utronix.de>, LKML <linux-kernel@...r.kernel.org>
Cc: Marc Zyngier <maz@...nel.org>, Peter Zijlstra <peterz@...radead.org>, 
 Jonathan Cameron <Jonathan.Cameron@...wei.com>, Nishanth Menon <nm@...com>,
 Dhruva Gole <d-gole@...com>, Tero Kristo <kristo@...nel.org>, Santosh
 Shilimkar <ssantosh@...nel.org>, Logan Gunthorpe <logang@...tatee.com>,
 Dave Jiang <dave.jiang@...el.com>, Jon Mason <jdmason@...zu.us>, Allen
 Hubbe <allenbh@...il.com>, ntb@...ts.linux.dev,  Michael Kelley
 <mhklinux@...look.com>, Wei Liu <wei.liu@...nel.org>, Bjorn Helgaas
 <bhelgaas@...gle.com>,  Haiyang Zhang <haiyangz@...rosoft.com>,
 linux-hyperv@...r.kernel.org, linux-pci@...r.kernel.org, Wei Huang
 <wei.huang2@....com>, Manivannan Sadhasivam
 <manivannan.sadhasivam@...aro.org>,  "Martin K. Petersen"
 <martin.petersen@...cle.com>, linux-scsi@...r.kernel.org, Jonathan Cameron
 <Jonathan.Cameron@...ei.com>
Subject: Re: [patch V4 01/14] cleanup: Provide retain_ptr()

On Wed, 2025-03-19 at 11:56 +0100, Thomas Gleixner wrote:
> In cases where an allocation is consumed by another function, the
> allocation needs to be retained on success or freed on failure. The
> code
> pattern is usually:
> 
> 	struct foo *f = kzalloc(sizeof(*f), GFP_KERNEL);
> 	struct bar *b;
> 
> 	,,,
> 	// Initialize f
> 	...
> 	if (ret)
> 		goto free;
>         ...
> 	bar = bar_create(f);
> 	if (!bar) {
> 		ret = -ENOMEM;
> 	   	goto free;
> 	}
> 	...
> 	return 0;
> free:
> 	kfree(f);
> 	return ret;
> 
> This prevents using __free(kfree) on @f because there is no canonical
> way to tell the cleanup code that the allocation should not be freed.
> 
> Abusing no_free_ptr() by force ignoring the return value is not
> really a sensible option either.
> 
> Provide an explicit macro retain_ptr(), which NULLs the cleanup
> pointer. That makes it easy to analyze and reason about.
> 
> Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@...wei.com>
> Cc: Peter Zijlstra <peterz@...radead.org>
> ---
> V4: Cast to void so can't be used as return_ptr() replacement - James

Reviewed-by: James Bottomley <James.Bottomley@...senPartnership.com>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ