[PATCH v3 46/57] perf: Simplify pmu_dev_alloc()
Paolo Bonzini
pbonzini at redhat.com
Mon Jun 12 12:29:05 UTC 2023
On 6/12/23 14:18, Greg KH wrote:
> 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.
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);
Paolo
More information about the Linux-security-module-archive
mailing list