[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230613073415.GP4253@hirez.programming.kicks-ass.net>
Date: Tue, 13 Jun 2023 09:34:15 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Greg KH <gregkh@...uxfoundation.org>
Cc: torvalds@...ux-foundation.org, keescook@...omium.org,
pbonzini@...hat.com, masahiroy@...nel.org, nathan@...nel.org,
ndesaulniers@...gle.com, nicolas@...sle.eu,
catalin.marinas@....com, will@...nel.org, vkoul@...nel.org,
trix@...hat.com, ojeda@...nel.org, mingo@...hat.com,
longman@...hat.com, boqun.feng@...il.com, dennis@...nel.org,
tj@...nel.org, cl@...ux.com, acme@...nel.org, mark.rutland@....com,
alexander.shishkin@...ux.intel.com, jolsa@...nel.org,
namhyung@...nel.org, irogers@...gle.com, adrian.hunter@...el.com,
juri.lelli@...hat.com, vincent.guittot@...aro.org,
dietmar.eggemann@....com, rostedt@...dmis.org, bsegall@...gle.com,
mgorman@...e.de, bristot@...hat.com, vschneid@...hat.com,
paulmck@...nel.org, frederic@...nel.org, quic_neeraju@...cinc.com,
joel@...lfernandes.org, josh@...htriplett.org,
mathieu.desnoyers@...icios.com, jiangshanlai@...il.com,
rientjes@...gle.com, vbabka@...e.cz, roman.gushchin@...ux.dev,
42.hyeyoo@...il.com, apw@...onical.com, joe@...ches.com,
dwaipayanray1@...il.com, lukas.bulwahn@...il.com,
john.johansen@...onical.com, paul@...l-moore.com,
jmorris@...ei.org, serge@...lyn.com, linux-kbuild@...r.kernel.org,
linux-kernel@...r.kernel.org, dmaengine@...r.kernel.org,
llvm@...ts.linux.dev, linux-perf-users@...r.kernel.org,
rcu@...r.kernel.org, linux-security-module@...r.kernel.org,
tglx@...utronix.de, ravi.bangoria@....com, error27@...il.com,
luc.vanoostenryck@...il.com
Subject: Re: [PATCH v3 46/57] perf: Simplify pmu_dev_alloc()
On Mon, Jun 12, 2023 at 05:44:59PM +0200, Greg KH wrote:
> Then in the last part of the file, I abuse the DEFINE_FREE() to handle a
> special case of removing a proc file if things go bad (and add a
> DEFINE_FREE() for class_destroy(), which should go into
> include/device/class.h.
>
> I've only test-built it, but is this the proper use of DEFINE_FREE()?
> There wasn't much documentation :)
Yes, this looks right.
> To be fair the end-result of misc_init() is much nicer and cleaner and
> "obviously correct", which is good, even with the crazy proc file mess
> in it. So I like the idea overall, need to figure out when to use
> DEFINE_CLASS() vs. DEFINE_FREE(), that isn't obvious to me.
CLASS is meant for things that have an obvious contructor as well as a
destructor, that always go together. Like for example the lock things,
they always pair a lock and unlock. But also things like:
fdget()+fdput(), these can also always be paired, and if you want the
file to escape you simply take yet another reference to prevent the
fdput() from being the final.
> Also, you can't put a DEFINE_FREE() within a function declaration, which
> I guess makes sense, but the build warning is very odd when you attempt
> it, mentioning an "invalid storage class". Is that supposed to be able
> to work?
No, DEFINE_FREE() and DEFINE_CLASS() end up defining a bunch of inline
functions, which can't be done inside another function.
If only C would have lambda functions ... alas.
> @@ -280,29 +268,24 @@ static char *misc_devnode(const struct device *dev, umode_t *mode)
> return NULL;
> }
>
> +DEFINE_FREE(class_destroy, struct class *, if (_T) class_destroy(_T));
Documentation for class_create() says it will return ERR_PTR(), so then
this should be something like:
DEFINE_FRERE(class_destroy, struct class *, if (!IS_ERR_OR_NULL(_T)) class_destroy(_T))
> +DEFINE_FREE(remove_proc, struct proc_dir_entry *, if (_T) remove_proc_entry("misc", NULL));
> static int __init misc_init(void)
> {
> + struct proc_dir_entry *ret __free(remove_proc) = proc_create_seq("misc", 0, NULL, &misc_seq_ops);
> + struct class *c __free(class_destroy) = class_create("misc");
>
> + if (IS_ERR(c))
> + return PTR_ERR(c);
>
> if (register_chrdev(MISC_MAJOR, "misc", &misc_fops))
> + return -EIO;
>
> + c->devnode = misc_devnode;
> +
> + misc_class = no_free_ptr(c);
> + no_free_ptr(ret);
> +
> + return 0;
> }
And yes, this does look nicer.
Powered by blists - more mailing lists