Thread (103 messages) 103 messages, 15 authors, 2024-01-16

Re: [PATCH v3 46/57] perf: Simplify pmu_dev_alloc()

From: Greg KH <gregkh@linuxfoundation.org>
Date: 2023-06-12 12:59:07
Also in: dmaengine, linux-kbuild, linux-perf-users, lkml, llvm, rcu

On Mon, Jun 12, 2023 at 02:29:05PM +0200, Paolo Bonzini wrote:
On 6/12/23 14:18, Greg KH wrote:
quoted
Yeah, it's a pain, but you are trying to hand-roll code that is not a
"normal" path for a struct device, sorry.

I don't know if you really can encode all of that crazy logic in the
cleanup api, UNLESS you can "switch" the cleanup function at a point in
time (i.e. after device_add() is successful).  Is that possible?
What _could_ make sense is that device_add() completely takes ownership of
the given pointer, and takes care of calling put_device() on failure.
I think we tried that decades ago :)

Problem is that the caller wants to clean stuff up associted with that
struct device-embedded structure _before_ the final put_device() is
called which would usually free the memory of the overall structure.

So device_add() can't call put_device() on the error path within it, you
need the caller to unwind it's local stuff before that happens.
Then you can have

	struct device *dev_struct __free(put_device) =
		kzalloc(sizeof(struct device), GFP_KERNEL);

	struct device *dev __free(device_del) =
		device_add(no_free_ptr(dev_struct));

	/* dev_struct is NULL now */

	pmu->dev = no_free_ptr(dev);
I don't see how that works properly, what am I missing?

thanks,

greg k-h
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help